fix: scale each imported pdf page independently to fit the document format - #1835
alberto-is wants to merge 2 commits into
Conversation
|
This is a design decision I'd like to flag before merging. The min() in page_zoom_fit gives the page a "contain" behavior: each page is scaled to fit entirely within the document page format while preserving its aspect ratio. The trade-off is that when a page's aspect ratio doesn't match the format, there can be empty space on one side. For example, a portrait page imported into a landscape-oriented format may leave blank space to the right. An alternative would be to scale by width only (page_width / intrinsic_width), which would always fill the full width. The height would then match the page's natural size, and since the document is already expanded to fit the content via set_height, nothing would be clipped. I kept the min() approach because it ensures the page is never distorted or cropped. However, if it's preferred to always fill the full width, it's a one-line change and I'm happy to update it. Any preference on which behavior we should go with? |
This way you guarantee that a pdf page is always inside a rnote page on export. Wouldn't you cut your page (portrait page into a landscape pdf document) into two with the second option? Your video shows the second option if I'm not mistaken |
|
I wonder if it is even desirable to always fit the document pages uniformly into the Rnote document width. If a PDF has multiple size pages (e.g. A4 and A3), should that not be reflected in the Rnote document as well? Another idea for a solution would be to take the maximum width of all PDF pages and scale them to this value accordingly. |
|
I can update the PR to use a single zoom level for all pages, based on the maximum intrinsic width, so that the widest PDF page fits Btw, with this approach, narrower pages will leave empty space on the right if left-aligned (as is the current behavior). Do you prefer to keep them left-aligned, or center them? |
|
Good question, I'll leave it up to you. |
Also enable the "Page Spacing" option when "Adjust Document" is active.
629f525 to
c4d787d
Compare
|
So, I went with the max-width approach; it’s much better than my initial idea. I updated the PR to use a single zoom level based on the widest page and dropped the per-page fit from the initial version. Since I personally prefer keeping all the pages together because I don’t use the export that much, I also enabled “Page Spacing” with “Adjust Document”, so “One per Document Page” can avoid splitting pages on export for those who use it. I also centered the narrower pages, but I can left-align them instead if you prefer. Btw (x3), I applied the zoom changes to both modes (Adjust Document on/off) because it didn’t make much sense to me to keep the zoom level based on the first page. |



Fixes #1834
When importing a PDF containing pages with different formats, such as a mix of portrait and landscape pages, the pages could become misaligned when Adjust document was enabled.
This happened because all pages were scaled using the dimensions of the first page. Pages with a different format therefore did not fit correctly in the document layout.
Changes
Testing
cargo fmt --all -- --checkcargo clippy --workspace --all-targets -- -D warningscargo test --workspaceThe following video shows the result before and after the fix when importing a PDF with mixed page formats:
format.import.pdf.mp4