Page breaks for PDF (again)

I stumbled upon this question while checking out the forum’s most viewed posts.

Use case or problem

When I export to PDF natively via the Obsidian menu. I would like to have the pages breaking at the correct point of the content. Not during a paragraph or item.

Proposed solution

Insert a char for page breaks that the export to pdf feature adheres to.

I came up with a solution that might be useful, but unfortunately the topic was closed. So I open this new one.

The idea is to use the --- markdown syntax (used to insert a horizontal rule), for this purpose.

You can add to .obsidian/snippets the following snippet in a file called for example hrule-is-page-break.css:

@media print {
  hr {
    visibility: hidden;
    page-break-before: always;
  }
}

If you activate this snippet in Obsdian Settings → Appearance, then the --- is transformed into a page break when converting to pdf (it remains visible as a horizontal rule in Obsidian preview).

If you have other notes with horizontal rules and you want to print those “normally”, deactivate the snippet before exporting to pdf.

2 Likes

You can add

<div style="break-after: page;"></div>

for page breaks anywhere.

There are also css options for breaking before/after any h1, h2, etc., heading.

This is a great addition to our export options. Thanks!

1 Like

Great two solutions although you don’t know beforehand how your content is going to be divided across different pages. I would instantly go and transfer my markdown documents to LaTeX or ODT[1] if printing/document export is considered. In some light use cases you can also import markdown to Google Docs[2]. For most users Google Docs could be ideal solution to do relatively fast printing on the fly.


  1. https://github.com/mokeyish/obsidian-enhancing-export ↩︎

  2. https://www.howtogeek.com/google-docs-markdown-import-export/ ↩︎