Skip to content

Print a PDF from its file, on the paper of the document - #214

Merged
andiwand merged 1 commit into
mainfrom
fix/print-paper
Oct 10, 2026
Merged

andiwand merged 1 commit into
mainfrom
fix/print-paper

Conversation

@andiwand

@andiwand andiwand commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

A user reported that a PDF printed from the app has the wrong layout. printDocument always printed the web view, on the default paper of the printer in portrait. A PDF printed as the HTML that the core renders. WebKit also breaks an A4 page over two Letter sheets, because it ignores the CSS page size and only fits the paper width.

This is the iOS side of opendocument-app/OpenDocument.droid#710 and #711.

Change

  • A PDF prints from its file. If the PDF has no password and no unsaved marks, printDocument sets printingItem to its fileURL, and iOS fits each page to the sheet. All other documents still use viewPrintFormatter(). After a save the document renders again, so the file holds the saved marks.
  • The paper of the document. CoreWrapper reads the page size of a text, presentation or drawing document (TextRoot, first Slide, first Page). For a PDF, CGPDFDocument reads the first page, with its /Rotate. PaperChooser gives that size, portrait, to UIPrintPaper.bestPaper(forPageSize:withPapersFrom:), and UIPrintInfo.orientation gets the orientation of the page. If no paper fits, iOS uses the nearest one that the printer has.
  • PrintPaper.swift (new) holds the unit conversion (pt, in, cm, mm, pc, px) and the chooser.

Verification

  • PrintPaperTests (5 tests: units, test.odt portrait, test.odp landscape, test.pdf printable, test-encrypted.pdf not printable), PrintAppearanceTests and OpenDocumentReaderTests: 37 tests pass on the iPhone 16 Pro simulator.
  • A temporary test (not committed) printed the served page through UIPrintPageRenderer with an 18 pt margin, to see what the paper changes in WebKit:
Fixture Letter portrait Letter landscape A4 portrait
test.pdf (2 A4 pages) 3 sheets 4 sheets 2 sheets
test.odt 2 sheets 2 sheets 1 sheet
test.odp (2 slides) 2 sheets 2 sheets 2 sheets

A PDF now does not take this path at all.

  • I could not open the print dialog: this machine has no Printer Simulator. So printingItem and the choosePaper callback are not tested end to end.

Printing always used the web view, on the default paper of the printer
in portrait. A PDF printed as the HTML that the core renders, and
WebKit breaks an A4 page over two Letter sheets because it only fits
the paper width.

A PDF without a password and without unsaved marks now prints from its
file through printingItem. All other documents still print the web
view. CoreWrapper reads the page size of a text, presentation or
drawing document, and CGPDFDocument reads the first page of a PDF. A
PaperChooser asks UIPrintPaper.bestPaper for that size, and the print
info gets the orientation of the page.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KNpfqA2jL1iVM1Wirf7njH
@andiwand
andiwand merged commit 2a1befb into main Oct 10, 2026
4 checks passed
@andiwand
andiwand deleted the fix/print-paper branch October 10, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant