I am using editable pdf files (created by Nitro PDF Software) in my application. These pdf files have a lot of editable fields (like textboxes) and one button (like submit).
Whenever a user opens that pdf file, enters the text, and clicks the submit button they get redirected to an aspx page.
How do I get all the static and dynamic values that are posted to this page, and create another pdf file with the entered data? And how do I save the created pdf file?
From Wikipedia, PDF Interactive elements there are two possibilities for integrating data and PDFs (there are also links to the specifications):
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();
}
}
Try open source library http://pdfsharp.codeplex.com/, sample can be found here http://www.pdfsharp.net/wiki/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With