Flatten Form Fields

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Merger for .NET (v4)  /  Flatten Form Fields

DynamicPDF Merger for .NET (v4) Forum

 Aug 16 2010 2:24 PM
The last forum message related to flattening form fields I saw was posted some time ago (July 2009).  Is there any plans to add this functionality?  Or at least improve the CreateLabel functionality?  It would appear that CreateLabel requires one to pass in quite a bit of information, including the containing page, the coordinates of the form field, the font specification (and, oh by the way, there is no way to determine programmatically the font of an existing form field)...

In reviewing alternative .NET PDF libraries, there appears to be simple "Flatten" methods; in a couple of cases, a FlattenAllFormFields method, which couldn't be easier to implement!

We have used DynamicPDF since 2006 and really it's been great.  But now we need to the ability to flatten form fields... easily.  If I have to purchase an upgrade (to go from v 4.x to 6.x) anyway, I thought I'd see what other libraries offered, and frankly, they seem much simpler.  So, I thought I'd at least ask and see what the plans are.

Thanks in advance.



 Aug 16 2010 4:18 PM
Posted by a ceTe Software moderator
Hello,

When using the CreateLabel method to do the form flattening you do not need to specify the coordinates of the form field. The CreateLabel method creates a Label object and adds it to the page at the coordinates of that particular form field.  Some sample code for using the CreateLabel is below:

[Visual Basic]
Dim MyPdfDocument as PdfDocument = New PdfDocument( filePath )
Dim MyDocument As MergeDocument = New MergeDocument( MyPdfDocument )

Dim MyPage as Page = MyDocument.Pages( 0 );
MyPdfDocument.Form.Fields( "f1-1" ).CreateLabel( MyPage, "Acme Corp.", ceTe.DynamicPDF.Font.Courier, 12 )
MyPdfDocument.Form.Fields( "c1-2" ).CreateLabel( MyPage, 2.5f, -2.5f, "3", ceTe.DynamicPDF.Font.ZapfDingbats, 12 )
MyPdfDocument.Form.Fields( "f1-4" ).CreateLabel( MyPage, "123 Main Street", ceTe.DynamicPDF.Font.Courier, 12 )
MyPdfDocument.Form.Fields( "f1-5" ).CreateLabel( MyPage, "Anytown, DC  12345", ceTe.DynamicPDF.Font.Courier, 12 )

MyDocument.Draw( "C:\MyDocument.pdf" )

[C#]
PdfDocument pdfDocument = new PdfDocument( filePath);
MergeDocument document = new MergeDocument( pdfDocument );   

Page page = document.Pages[0];
pdfDocument.Form.Fields["f1-1"].CreateLabel( page, "Acme Corp.", ceTe.DynamicPDF.Font.Courier, 12 );
pdfDocument.Form.Fields["c1-2"].CreateLabel( page, 2.5f, -2.5f, "3", ceTe.DynamicPDF.Font.ZapfDingbats, 12 );
pdfDocument.Form.Fields["f1-4"].CreateLabel( page, "123 Main Street", ceTe.DynamicPDF.Font.Courier, 12 );
pdfDocument.Form.Fields["f1-5"].CreateLabel( page, "Anytown, DC  12345", ceTe.DynamicPDF.Font.Courier, 12 );

document.Draw( @"C:\MyDoc.pdf" );

Please refer to the "Form Flattening" topic in the Help documentation, http://www.DynamicPDF.com/Support/NET_Help_Library_10_03/Form%20Flattening.html and refer section labeled "Replace Acro Form Fields with Text".

In v6.0, you can also get the font being used by the form field and use that font in the CreateLabel method instead of specifying your own font. 

Thanks,
ceTe Software Support Team
 Aug 17 2010 3:27 PM
OK, let me try again.  We have an urgent need to modify a large codebase that makes extensive use of form-filling and merging PDFs.  So far so good.  The ONE critical thing we need to do is flatten the form fields. Not just make them readonly or add security to the doc.  We need to flatten those form fields, as one can do it Acrobat through the PDF Optimizer options.

It would appear the only option in DynamicPDF is to loop through a documents pages and then fields on those pages and deal with the .CreateLabel function.  Now, I see that .CreateLabel appears to have a simpler method signature in version 6, requiring 2 params, the containing Page object and text.  OK, that may work, but seems clunky at best, as it seems I'd have to loop all the pages and fields.

In evaluating some "alternative" products (QuickPDF, PDF4Net, PDFTechLib, Aspose Pdf.Kit) there are options for a single method call on the doc/form object, like so:

doc.AcroForm.FlattenFormFields = true;
doc.Save();

(and variations apply depending on the product, but I think you get the idea). Something like this would be trivial to add to our codebase.  Any thoughts on adding something like this to DynamicPDF?  Is their a roadmap for future releases?
 Aug 17 2010 3:39 PM
Posted by a ceTe Software moderator
Hello,

We will add this feature request to our wish list for consideration to be added to the future version of our product.

You can also remove all the form fields in the PDF document by setting MergeOptions object FormField property to false and passing the MergeOptions to the Append method. That will strip all the form fields from the PDF.

In this case you will have to do the placement of the labels on top of the form fields manually and not be able to reference the form fields by their name.

Thanks,
ceTe Software Support Team
 May 21 2012 4:06 PM
Posted by a ceTe Software moderator
Hello,

The feature of flattening the form with a single property has been added to the v7.0 of DynamicPDF Merger for .NET product which was released recently.  The evaluation edition of v7 can be downloaded here.

Thanks,
ceTe Software Support Team
 Sep 08 2015 7:21 PM
Do you have a code sample for this?
 Sep 09 2015 11:54 AM
Posted by a ceTe Software moderator
Hello,

Yes, you can refer to the help topic containing code sample for field level and document level flattening here.

In v8 we added field level flattening in addition to document level flattening which was added in v7.

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 2:10 AM.