l1xnan / obsidian-better-export-pdf

Obsidian PDF export enhancement plugin
MIT License
348 stars 22 forks source link

show pages and true pdf dimensions in the preview #117

Open KraXen72 opened 8 months ago

KraXen72 commented 8 months ago

currently, even if i set the output format to A4, since my custom css increases the note width, the preview does not conform to A4 (it's wider). I would like to see how the content fits to the page format I selected, and where it will be split into pages, so I can adjust the margins or add manual page breaks (even in editor view it's fine). this is somewhat related to #107 but that's more specific.

l1xnan commented 8 months ago

Considering custom pdf margins, @media print margin settings, px to A4 conversion under dpi settings of different systems, etc., it is not easy to handle. I'll try to do a little optimization, but I'm not sure how long.

KraXen72 commented 8 months ago

just take the ratio of an a4 page (available online), then get element width of the preview with element.clientWidth and then calculate the height of 1 page. split prevew into pages, you can add a small note that the page breaks are only appoximate. to get vertical margins (top&bottom), you can use element.getComputedStyle

l1xnan commented 8 months ago

Thank you for your idea.

heeeedjr commented 3 months ago

Hi, I really enjoy your PDF plugin but would also like to see where the page breaks would be in the preview page so that I know exactly what the PDF will look like. Is there any update on this issue?

l1xnan commented 3 months ago

Hi, I really enjoy your PDF plugin but would also like to see where the page breaks would be in the preview page so that I know exactly what the PDF will look like. Is there any update on this issue?

I apologize, but this issue is quite challenging, so there hasn't been any substantial progress yet. Simply judging by the height of elements is not accurate. For example, if there's a large table with repeated headers, the height of the table element changes. The plugin itself doesn't have the capacity to implement a complex pagination algorithm to handle this, and third-party libraries have shown unstable performance. Another approach could be to render a PDF file in real-time and preview this PDF. It seems that Chrome browser implements it this way. However, I’m unsure if the performance will meet the requirements. In the next phase, I might try this approach to test its feasibility, and this work might begin in about two weeks.