Create PDF from form data and save it Create PDF from form data and save it asp.net asp.net

Create PDF from form data and save it


From Wikipedia, PDF Interactive elements there are two possibilities for integrating data and PDFs (there are also links to the specifications):

  • AcroForms (also known as Acrobat forms), introduced in the PDF 1.2 format specification and included in all later PDF specifications.
  • Adobe XML Forms Architecture (XFA) forms, introduced in the PDF 1.5 format specification. The XFA specification is not included in the PDF specification, it is only referenced as an optional feature. Adobe XFA Forms are not compatible with AcroForms.

For compatibility issues I would go for AcroForms. In that case I would use XFDF, because it is XML and therefore easier to parse. I never used Nitro, but when you build a PDF form you usually provide a "Save" button and choose at action for this button "Send/Post form to server" with the data format XML which is just XFDF.

This works only when the PDF is viewed in the browser. So the typical use case is: have an empty PDF template on the server, before returning the PDF to the user mix your data into the PDF, the user enters data in the form (PDF is opened in the browser via a plugin or natively in Chrome), then the user presses the save buttons which posts a xml on the server. The next time the user asks for his PDF, you took the recent data and mix it again with the template.

So only two questions are open:

See the complete process here: http://itextpdf.com/book/chapter.php?id=9 . This example updates the PDF with the form dynamically at run time. Since iText is used there is no difference between Java and C#.

Be aware that previous versions of iText (Java up to 2.1.7 and C# up to 4.1.6) were distributed under the Mozilla Public License or the LGPL, while current versions are distributed under the Affero General Public License. Thats explains why the older versions are still used.


User following code for Generate PDF in asp.net:

There's a full code sample below to get you started.// Code

using System;using System.IO;using System.Diagnostics;using iTextSharp.text;using iTextSharp.text.pdf;public class iTextDemo { public static void Main()  {  Console.WriteLine("iText Demo");  // step 1: creation of a document-object  Document myDocument = new Document(PageSize.A4.Rotate());  try   {   // step 2:   // Now create a writer that listens to this doucment and writes the document to desired Stream.   PdfWriter.GetInstance(myDocument, new FileStream("Salman.pdf", FileMode.Create));   // step 3:  Open the document now using   myDocument.Open();   // step 4: Now add some contents to the document   myDocument.Add(new Paragraph("First Pdf File made by Salman using iText"));  }  catch(DocumentException de)   {   Console.Error.WriteLine(de.Message);  }  catch(IOException ioe)   {   Console.Error.WriteLine(ioe.Message);  }  // step 5: Remember to close the documnet  myDocument.Close(); }}