Repository navigation
Copy pages with the form fields of their widgets - #89
Merged
Merged
Conversation
FPDF_ImportPagesByIndex copies a page's widgets but not their fields: the page copier skips /Parent, so each copied widget keeps naming the source's field by its number, which names nothing (or something else) once saved, and the destination gets no /AcroForm. EPDFDoc_ImportPages copies the pages the same way, then the fields above the copied widgets: each once, its /Kids limited to what was copied, the widgets' and fields' /Parent pointed at the copies. The copied top-level fields join the destination's /AcroForm /Fields (made when it has none), with the source's /DR resources (a font whose name the destination uses for another font gets a free name, and the copied /DA strings follow), its /DA and /Q where the destination says otherwise, /NeedAppearances, the copied fields' /CO places and SignaturesExist. A copied pop-up's /Parent names its annotation's copy. Names are kept: EPDFDoc_GetImportFieldRoots and EPDFForm_GetFieldPartialName let the caller rename first. CPDF_PageOrganizer gains three public members backing it, tagged epdf-api.
Two review findings in EPDFDoc_ImportPages: - Fonts were compared by subtype, base font and encoding only, so a font with other /Widths (or descriptor metrics, or a /ToUnicode map) was taken for the destination's and the copied fields drew with the wrong widths. A font is now shared only when both definitions match key for key, resolved all the way down; anything with a stream counts as different. Acrobat's identical /Helv stays shared. - The /DA rewrite had its own tokenizer, which read a comment between the font name and Tf as words: "/F1 % note" then "10 Tf" kept /F1 while the resource was renamed. It now reads with CPDF_SimpleParser, which skips comments as a viewer does. Regression tests for both, and one that a font defined the same way stays shared.
bobsingor
force-pushed
the
embedpdf/fix/import-acroform
branch
from
October 28, 2026 12:57
26ca4e4 to
cf7b7d5
Compare
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.
FPDF_ImportPagesByIndex copies a page's widgets but not their fields: the page copier skips /Parent, so each copied widget keeps naming the source's field by its number, which names nothing (or something else) once saved, and the destination gets no /AcroForm.
EPDFDoc_ImportPages copies the pages the same way, then the fields above the copied widgets: each once, its /Kids limited to what was copied, the widgets' and fields' /Parent pointed at the copies. The copied top-level fields join the destination's /AcroForm /Fields (made when it has none), with the source's /DR resources (a font whose name the destination uses for another font gets a free name, and the copied /DA strings follow), its /DA and /Q where the destination says otherwise, /NeedAppearances, the copied fields' /CO places and SignaturesExist. A copied pop-up's /Parent names its annotation's copy. Names are kept: EPDFDoc_GetImportFieldRoots and EPDFForm_GetFieldPartialName let the caller rename first.
CPDF_PageOrganizer gains three public members backing it, tagged epdf-api.