Repository navigation
Draw a page of an existing PDF like an image, or under every page - #102
Merged
Merged
Conversation
pdf_page draws a page of another PDF (a path, an IO or its bytes) with the options image takes, and background_pdf puts one under every page, start_new_page naming another or none. The page is a form XObject showing its crop box turned by its /Rotate, written once however many pages draw it; pages of one file share their resources. Under pdf_a, a page whose fonts are not embedded raises. Gamba's own API takes background_pdf as a document option and pdf_page as a box. The object copying of Gamba.combine moves to Gamba::Copier and its page boxes to Gamba::PageBoxes, both shared with the import. The input fuzzer now corrupts PDFs too. Assisted-by: Claude [Claude Code]
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.
Companies keep their letterhead and pre-printed forms as PDFs made by a designer, and drawing on top of one is among the most common requests to a PDF library; Prawn dropped its template support in 1.0.
Gamba.combinecould read those files, but only to put whole pages one after another. Closes #73.pdf_pagedraws a page of another PDF with the optionsimagetakes, andbackground_pdfputs one under every page. Each page becomes a form XObject that shows what a viewer shows of it.pdf_page "terms.pdf", page: 2, width: 200takes a path, an IO or the bytes of a PDF, withat,position,vposition,width,height,scaleandfit.Prawn::Document.new(background_pdf: "letterhead.pdf", background_pdf_page: 1)draws it at its own size from the top left corner;start_new_page(background_pdf: …)names another for one page, orfalsefor none./Rotateare applied; several content streams are joined, wherever they were divided.Gamba.combine, with the same errors. Underpdf_a: true, a page whose fonts are not embedded raisesPdfAViolation, and the input fuzzer now corrupts PDFs too.background_pdfandbackground_pdf_pageas document options, andpdf_pageas a box sized like an image. Object copying moves out ofCombineintoGamba::CopierandGamba::PageBoxes, which both use.Proof
test/pdf_page_test.rbdraws a page at its size, a page turned by/Rotateand a cropped, turned page, and compares each with the page shown alone: same pixels in MuPDF and Poppler, andqpdf --checkpasses. Fifty pages with a background and one more page of the same file write two forms and one font. Other tests cover backgrounds per page, content split between an operator and its operands, errors (page out of range, missing file, not a PDF, password), PDF/A with Helvetica (raises) and with an embedded TrueType font (passes), and the native box. 4,500 corrupted PDFs drawn as pages, on three seeds, each render or raiseMalformedPDF.rake test: 1345 runs, 0 failures; RuboCop is clean;combine_test.rbis unchanged and passes.Generated by Claude Code