?
Solved

Retaining interactivity on pdf after programmaticaly passing data to it

Posted on 2008-11-04
4
Medium Priority
?
326 Views
Last Modified: 2012-06-27
I'm passing data programmaticaly to a US I-9 form, but the pdf loses its interactive features when the user tries to edit the filled in form afterwards. I've tried iTextsharp, and PDFKit.NET but both return the same end results. Does any one know of a way that i can fix this, or of another library that i can use that'll retain the interactivity?

(I've tried the actual adobe sdk as well, but licensing restrictions doesn't allow me to access the COM object on the server via asp.)
i-9.pdf
0
Comment
Question by:Caroline_Swart
  • 3
4 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22875613
Can you please provide more information. It sounds like you have a PDF document that has interactive features (e.g. form fields). How are you "passing data" to that file?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22875693
Ah... I opened the attached PDF file and now it's clear why you are having prolbems: The file is not a regular PDF file, it's a XFA form created with Designer. I assume you are using the standard form functions in iText. Use the XFAForm methods to modify your form.
0
 

Author Comment

by:Caroline_Swart
ID: 22876003
I'm fairly new to using iTextSharp, or any pdf libraries. How would i go about using XFA. Ive just searched on the net quickly, and it seems that in order to use XFA i have to create an XML file, and then merge the two so to speak? Is this correct? I've attached the method i wrote that I'm currently using if it'll help?

FillFormI9(formFields); // method that gets called on button click
 
 
private void FillFormI9(Dictionary<string, string> pdfInfo)
    {
        string pdfTemplate = Server.MapPath(@"~/i-9.pdf"); 
        
        string newFile = Server.MapPath(@"~/i-9.pdf_new");
 
        PdfReader pdfReader = new PdfReader(pdfTemplate);
 
        PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
 
        AcroFields pdfFormFields = pdfStamper.AcroFields;
 
        string pdfKey = "";
        string outValue = "";       
 
        foreach (DictionaryEntry de in pdfReader.AcroFields.Fields)
        {
            try
            {
                pdfKey = de.Key.ToString();
 
                if (pdfInfo.ContainsKey(pdfKey))
                {
                    DictionaryEntryCounter++;
 
                    try
                    {
                        if (pdfInfo.TryGetValue(pdfKey, out outValue))
                        {
                            pdfFormFields.SetField(pdfKey, outValue);
                        }
                    }
                    catch (Exception ex)
                    {                       
                    }
                }               
            }
            catch (Exception ex)
            {               
            }
        }
 
        pdfStamper.FormFlattening = false;
        pdfStamper.Close();      
    }
 
  protected Dictionary<string, string> formFields
  {
        get
        {
	   Dictionary<string, string> _formFields = new Dictionary<string, string>();
           _formFieldsAndValues.Add("form1[0].#subform[2].firstname[0]", "James");   // i pass the data from my select statement into a similair dictionary
  	  
 
	  return _formFieldsAndValues;
        }
  }	

Open in new window

0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 1500 total points
ID: 22876172
I don't have any experience with iText and XFA either, but from what I understand, you can use the setField/getField methods with an XFA form (according to this page: http://www.nabble.com/On-filling-reading-reader-enabled-static-XFA-Forms-td17758315.html#a17831162). The page also comes with same sample code, which may or may not work...

All I know for sure is that you have to treat XFA forms differently - they are not true PDF files.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Getting information about Fonts being used in a PDF file A colleague of mine recently faced an issue related to the PDF file format. The PDFs were containing mission critical client information, they were successfully mailed but there was a sm…
This article explains how to perform batch conversion of PDF, TIFF, and other image file formats into PDF, PDF Searchable, and TIFF files via a command line interface, using Nuance's latest document imaging software — Power PDF Advanced.
Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question