Make working with AcroForms more user-friendly and allow creating PDFs with minmal size#236
Make working with AcroForms more user-friendly and allow creating PDFs with minmal size#236packdat wants to merge 6 commits intoempira:masterfrom
Conversation
|
Some test-cases require documents to work with. They should be extracted into PDFsharp's asset-folder, e.g. |
|
Unfortunately, i was not able to create a separate PR for the latest changes, sorry for that. There are use-cases where you don't care about PDF/A conformance or the like, you just want to create documents quickly and with minimal size. The latest commit added support for this scenario. |
|
@PDFsharp-Team This is a very exciting upgrade to Acroforms. Will this make it to the next Preview version? |
It is a very interesting proof of concept, but requires some debugging and some refactoring. It probably will not make it into the next Preview version. |
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.ImportAcroFormwas added to import AcroFields from existing documents.This method also allows filtering of fields during the import.
An new method
PdfDocument.GetOrCreateAcroFormwas added which allows creating new AcroForms.New methods were added that allow creating new AcroForms from scratch.
Example:
See full example in method
CanCreateNewFormhereThere 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
PdfWidgetAnnotationassociated with the samePdfAcroField).The annotations of fields can be retrieved by
PdfAcroField.AnnotationsEach 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.FieldRendererPdfAcroFormhas a new methodGetAllFieldsfor 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 !