PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.net/

Bug when flattening form
http://forum.pdfsharp.net/viewtopic.php?f=3&t=3778
Page 1 of 1

Author:  Imus [ Fri Apr 27, 2018 3:08 pm ]
Post subject:  Bug when flattening form

Hello,

I found a bug flattening a form. When I flatten a document, the fields that contain a "." are not flattened while other fields do.


Here is the original document:
Attachment:
form.jpg
form.jpg [ 65.52 KiB | Viewed 450 times ]


And this is the result:
Attachment:
formfilled.jpg
formfilled.jpg [ 59.19 KiB | Viewed 450 times ]


The url to the original file:
http://www.navarra.es/NR/rdonlyres/1773 ... eneral.pdf


The only thing I do is:
Code:
            // Load form pdf
            var document = PdfReader.Open("form.pdf");

            // Flatten the form
            document.Flatten();


This way the result is the same:
Code:
            // Load form pdf
            var document = PdfReader.Open("../../testFiles/form.pdf");

            // Flatten the form
            PdfAcroForm form = document.AcroForm;
            if (form != null)
            {
                PdfAcroField.PdfAcroFieldCollection fields = form.Fields;
                for (int i = 0; i < fields.Count(); i++)
                {
                    fields[i].ReadOnly = true;
                }
            }


I´m using the latest version of PdfSharp (1.50.4845-RC2a).

Perhaps I'm doing something wrong..

Thanks!

Iñigo

Attachments:
fillForm.zip [41.49 KiB]
Downloaded 28 times

Author:  () => true [ Sun Apr 29, 2018 4:10 pm ]
Post subject:  Re: Bug when flattening form

Hi!
Imus wrote:
Perhaps I'm doing something wrong.
If you think this is a bug then please use the IssueSubmissionTemplate.
viewtopic.php?f=2&t=832

The Flatten method is based on user feedback. It's not my area of expertise. There may be special cases that need special treatment.

Author:  Imus [ Mon Apr 30, 2018 6:46 am ]
Post subject:  Re: Bug when flattening form

Hi!

() => true wrote:
If you think this is a bug then please use the IssueSubmissionTemplate.
Yes, the zip file attached is based on that template.

Thanks!

Author:  (void) [ Sun May 06, 2018 1:16 pm ]
Post subject:  Re: Bug when flattening form

Quote:
When I flatten a document, the fields that contain a "." are not flattened while other fields do.
The current implementation only sets fields on the outermost hierarchy-level to read-only, child-fields are not handled.
Beside that, i do not see what setting fields to read-only has to do with flattening, even when it's done correctly.
This process can be easily reverted by simply removing the read-only flag from the fields.
I have not found an official description about what "flattening" actually means, but this sentence comes close to what i consider as "flattening":
Quote:
Forms flattening is the process of removing this separate form data and adding it as text, images and shapes into the actual PDF data stream.
The PDF will still look the same but the user can no longer interact with the forms.
Source: https://blog.idrsolutions.com/2011/01/w ... lattening/

I am in the process of evaluating the current 1.5 release for our production environment.
We are currently using a custom 1.32 version, where we have made some enhancements especially for Acro-Forms.
I forked PdfSharp on GitHub and shifted over some changes we made for 1.32; that includes "real" Form-Flattening (meaning there are no fields anymore after flattening).
Especially Font-handling for AcroFields may need a big overhaul as i think, the current state handles only the most basic font-related issues.
(e.g. Fields rendered with embedded fonts using some special encoding are not handled correctly at all...)
The current status of this fork is "experimental", as i have not (yet) done extensive testing with it.

But please take a look, and report whether it works for you:
https://github.com/packdat/PDFsharp/tree/AcroForms

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/