Make working with AcroForms more user-friendly and allow creating PDFs with minmal size #236
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.
This PR is an attempt to make working with AcroForms easier and user-friendly.
Notable changes:
The 14 standard-fonts defined in the Pdf-Specification are now embedded in the library.
There is a test-case (
RenderGlyphsOfStandardFonts
) that was used to inspect the fonts by rendering all glyphs into a Pdf (one for each font) here.These fonts are freely distributable as they are licensed under the OFL License.
To use them, utilize the new StandardFontResolver, e.g.
The StandardFontResolver also has methods that allow registering own fonts:
A new method
PdfDocument.ImportAcroForm
was added to import AcroFields from existing documents.This method also allows filtering of fields during the import.
An new method
PdfDocument.GetOrCreateAcroForm
was added which allows creating new AcroForms.New methods were added that allow creating new AcroForms from scratch.
Example:
See full example in method
CanCreateNewForm
hereThere is now a distinction between a field (which is only metadata regarding the Pdf-Specification) and it's appearance (which is the visual part of a field).
The appearances of AcroFields are defined by PdfWidgetAnnotations.
A field may have multiple annotations (e.g. a contract-number that is repeated on every page of a contract-document; each visual is a
PdfWidgetAnnotation
associated with the samePdfAcroField
).The annotations of fields can be retrieved by
PdfAcroField.Annotations
Each field type has it's own renderer which is used to create the visual appearances for the fields.
These renderers may be overridden by the user to customize the rendering.
See PdfAcroFieldRenderer as a starting point.
An instance of this class is available in
PdfAcroForm.FieldRenderer
PdfAcroForm
has a new methodGetAllFields
for easily retrieving the complete field-hierarchy as a flattened collection.AcroForms can be flattened by the new method
PdfDocument.FlattenAcroForm
(the old method
PdfDocument.Flatten
, wich was just setting the "ReadOnly"-flag for AcroFields, was removed)Note that annotations not related to AcroFields are unaffected by this (as the name implies).
I'm pretty sure there's room for further improvement; some feedback would be useful for that and is highly appreciated !