Repository navigation
Print a PDF from its file, on the paper of the document - #214
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A user reported that a PDF printed from the app has the wrong layout.
printDocumentalways 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
printDocumentsetsprintingItemto itsfileURL, and iOS fits each page to the sheet. All other documents still useviewPrintFormatter(). After a save the document renders again, so the file holds the saved marks.CoreWrapperreads the page size of a text, presentation or drawing document (TextRoot, firstSlide, firstPage). For a PDF,CGPDFDocumentreads the first page, with its/Rotate.PaperChoosergives that size, portrait, toUIPrintPaper.bestPaper(forPageSize:withPapersFrom:), andUIPrintInfo.orientationgets 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.odtportrait,test.odplandscape,test.pdfprintable,test-encrypted.pdfnot printable),PrintAppearanceTestsandOpenDocumentReaderTests: 37 tests pass on the iPhone 16 Pro simulator.UIPrintPageRendererwith an 18 pt margin, to see what the paper changes in WebKit:test.pdf(2 A4 pages)test.odttest.odp(2 slides)A PDF now does not take this path at all.
printingItemand thechoosePapercallback are not tested end to end.