0

I have a script that runs after the pdf-file has been loaded and that populates some form fields in the pdf. I assume it is some kind of javascript running behind the scene. In the javascript code some values are stored that I need to retrieve. I use iTextSharp to work with the pdf-file. Is it possible to read the javascript code or the values so I can work with them in my c# code somehow?

1 Answer 1

1

Modified from this SO answer:

var pdfReader = new PdfReader(infilename);
using (MemoryStream memoryStream = new MemoryStream())
{
    PdfStamper stamper = new PdfStamper(pdfReader, memoryStream);
    for (int i = 0; i <= pdfReader.XrefSize; i++)
    {
        PdfDictionary pd = pdfReader.GetPdfObject(i) as PdfDictionary;
        if (pd != null)
        {
            PdfObject poAA = pd.Get(PdfName.AA); //Gets automatic execution objects
            PdfObject poJS = pd.Get(PdfName.JS); // Gets javascript objects
            PdfObject poJavaScript = pd.Get(PdfName.JAVASCRIPT); // Gets other javascript objects
            //use poJS.GetBytes(), poJS.ToString() etc to inspect details...
        }
    }
    stamper.Close();
    pdfReader.Close();
    File.WriteAllBytes(rawfile, memoryStream.ToArray());
}

Here's a reference page for the PdfObject class.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! This works although I found no values. I think it might be in a fdf file. But I have no idea where in the pdf file the path to the fdf file is stored and how to access it? The answer is correct so I will mark it as an answer but it seems it's not the answer I need :)
@Janspeed can you post the pdf for inspection?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.