PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create)) ĪcroFields pdfFormFields = pdfStamper.AcroFields įoreach (var fieldName in Formfiledmap.Keys) String newFile = pdfReader = new PdfReader(pdfTemplate) String pdfTemplate = Server.MapPath("/AOF.pdf") Public void FillForm(Dictionary Formfiledmap) Var stamper = new PdfStamper(reader, output) įoreach (var fieldName in formFieldMap.Keys)įormFields.SetField(fieldName, formFieldMap) Public byte FillForm(string pdfPath, Dictionary formFieldMap) PdfReader pdfReader = new PdfReader(Filepath) įoreach (var entry in )įileds.Add((), string.Empty) sb.Append(de.Key.ToString() + Environment.NewLine) StringBuilder sb = new StringBuilder() PdfReader pdfReader = new PdfReader(pdfTemplate) Public Dictionary ListFieldNames(string Filepath) Var Formcontent = ListFieldNames(Filepath) įormcontent = "T.Test" FillForm(Formcontent) // var pdfContents = FillForm(pdfpath, Formcontent) Var pdfpath = Path.Combine(Filepath, "") Try with this: string Filepath = Server.MapPath("/AOF.pdf") (special thanks to for this necessary information)
If you want the form to keep its interactivity, you need to remove the form.flattenFields() otherwise all form fields will be removed, resulting in a flat PDF.īe aware, that itext7 is licenced under AGPL and isn't free for commercial use or closed source. The value corresponds with the value you want to fill in. The key corresponds with the name of a field in your template.
In this snippet, src is the source of a PDF file and dest is the path to the resulting PDF. Var form = PdfAcroForm.GetAcroForm(pdfDoc, true) PdfDocument pdfDoc = new PdfDocument(reader, writer)
To write a specific form field, use code similar to this: PdfReader reader = new PdfReader(src) Add it to your project by executing following command in your NuGet Package Manager Console: If your form is based on the AcroForm technology: Just use the itext7 to accomplish this task. It would be considerably more efficient to generate your form templates once then fill them in.
Given that this is strictly internal and that you'll be printing the PDFs, the licensing isn't much of an issue. Older versions were available under the MPL. AGPL is just as "viral" as the regular GPL. With AGPL, anyone with access to your OUTPUT must have access to the source of your application. iText is licensed under the AGPL (or commercially). I do this with iText (the Java basis of iTextSharp), though there are quite a few libraries available in various languages. If that's not the case.Ģ) Generate your PDF forms programmatically. Using FDF presumes you have the PDF forms already made, just waiting to be filled out. All you'd need to do would be to generate the appropriate FDF files, which is mostly trivial string building. You could just open/print them in the correct order.Īs I recall, Acrobat Pro's batch commands can import FDF data and print. Of course if you can control the order in which things are printed, you needn't merge the forms at all. then you're not really merging PDF forms any more.
There are a couple approaches, the easiest of them being to "flatten" the fields so they are just page contents (line art & text). The aforementioned iText (and several others) can do this programmatically, other apps have command lines.Īny page that might need to be repeated should be it's own form in this environment. There are a number of mail-merge-esque products floating around that can take in an FDF and PDF and produce a filled PDF form. "/F" is the path to the form to be filled. "/V" indicates a field value, "/T" is a field's title. Here's a sample (with extra whitespace to make it more readable): %FDF-1.2 Opening the FDF fills the PDF (via a file association with acrobat/reader). FDF files are fairly trivial to generate, and contain a pile of field/value pairs (and can hold list options, and other fancier stuff you won't need) and a file association. And that's a terrible spec document, it only covers a small (infrequently used, complicated) part of the FDF format.