471,339 Members | 1,289 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,339 software developers and data experts.

Fill form fields in a PDF

Hi there,
I have a PDF that has editable form fileds. I want to be able dynamically
fill in those form fields based on values I provide to the PDF. Right now, I
can create an instance of the object, open the PDF document, but can't get a
handle on the JavaScript portion of the document in order to change any of
the form field values.

Here is a snippet of my code so far:
Type AcroApp = Type.GetTypeFromCLSID(new
System.Guid("{85DE1C45-2C66-101B-B02E-04021C009402}"));

Type AcrobatType = Type.GetTypeFromCLSID(new
System.Guid("{72498821-3203-101B-B02E-04021C009402}"));

Type AcroPD = Type.GetTypeFromCLSID(new
System.Guid("{FF76CB60-2EC8-101B-B02E-04021C009402}"));

//create instances of the Acrobat objects needed
Acrobat.CAcroApp oApp = (Acrobat.CAcroApp) Activator.CreateInstance(AcroApp);
Acrobat.CAcroAVDoc avdoc= (Acrobat.CAcroAVDoc)
Activator.CreateInstance(AcrobatType);
Acrobat.CAcroPDDoc adoc = (Acrobat.CAcroPDDoc)
Activator.CreateInstance(AcroPD);

avdoc.Open(Server.MapPath("pdfs/test.pdf"),"test PDF");
adoc = (Acrobat.CAcroPDDoc)avdoc.GetPDDoc();

/* I need to get a hold of the form fields here and fill in their values */

oApp.Show(); //displays the proper PDF
adoc.Close();

Any help would be greately appreciated.

--
Thanks,

John Scott.
Jul 21 '05 #1
2 6438
To be honest, I don't know how to drive PDF.

However, I have a suggestion. When you fill a PDF form and submit it, an
XML stream is sent to the destination of the form. This is how PDF Forms
work (it's very similar to Microsoft Office Infopath, BTW).

So my suggestion is this: if you don't need the customer to see the data in
the form (e.g. you've collected in another way), it may be possible just to
compose the XML stream and submit it to the web server, as though your
program were the acrobat viewer, without ever loading up acrobat.

I hope this helps,

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"John Scott" <jo*******@despammed.com> wrote in message
news:2A**********************************@microsof t.com...
Hi there,
I have a PDF that has editable form fileds. I want to be able dynamically
fill in those form fields based on values I provide to the PDF. Right
now, I
can create an instance of the object, open the PDF document, but can't get
a
handle on the JavaScript portion of the document in order to change any of
the form field values.

Here is a snippet of my code so far:
Type AcroApp = Type.GetTypeFromCLSID(new
System.Guid("{85DE1C45-2C66-101B-B02E-04021C009402}"));

Type AcrobatType = Type.GetTypeFromCLSID(new
System.Guid("{72498821-3203-101B-B02E-04021C009402}"));

Type AcroPD = Type.GetTypeFromCLSID(new
System.Guid("{FF76CB60-2EC8-101B-B02E-04021C009402}"));

//create instances of the Acrobat objects needed
Acrobat.CAcroApp oApp = (Acrobat.CAcroApp)
Activator.CreateInstance(AcroApp);
Acrobat.CAcroAVDoc avdoc= (Acrobat.CAcroAVDoc)
Activator.CreateInstance(AcrobatType);
Acrobat.CAcroPDDoc adoc = (Acrobat.CAcroPDDoc)
Activator.CreateInstance(AcroPD);

avdoc.Open(Server.MapPath("pdfs/test.pdf"),"test PDF");
adoc = (Acrobat.CAcroPDDoc)avdoc.GetPDDoc();

/* I need to get a hold of the form fields here and fill in their values
*/

oApp.Show(); //displays the proper PDF
adoc.Close();

Any help would be greately appreciated.

--
Thanks,

John Scott.

Jul 21 '05 #2
There is a product called ActivePDF that I have used that does this. There
is a toolkit among other things that is relatively cheap. It has a whole
interface to quickly parse PDF template data.

"Nick Malik [Microsoft]" <ni*******@hotmail.nospam.com> wrote in message
news:2u********************@comcast.com...
To be honest, I don't know how to drive PDF.

However, I have a suggestion. When you fill a PDF form and submit it, an
XML stream is sent to the destination of the form. This is how PDF Forms
work (it's very similar to Microsoft Office Infopath, BTW).

So my suggestion is this: if you don't need the customer to see the data
in the form (e.g. you've collected in another way), it may be possible
just to compose the XML stream and submit it to the web server, as though
your program were the acrobat viewer, without ever loading up acrobat.

I hope this helps,

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"John Scott" <jo*******@despammed.com> wrote in message
news:2A**********************************@microsof t.com...
Hi there,
I have a PDF that has editable form fileds. I want to be able
dynamically
fill in those form fields based on values I provide to the PDF. Right
now, I
can create an instance of the object, open the PDF document, but can't
get a
handle on the JavaScript portion of the document in order to change any
of
the form field values.

Here is a snippet of my code so far:
Type AcroApp = Type.GetTypeFromCLSID(new
System.Guid("{85DE1C45-2C66-101B-B02E-04021C009402}"));

Type AcrobatType = Type.GetTypeFromCLSID(new
System.Guid("{72498821-3203-101B-B02E-04021C009402}"));

Type AcroPD = Type.GetTypeFromCLSID(new
System.Guid("{FF76CB60-2EC8-101B-B02E-04021C009402}"));

//create instances of the Acrobat objects needed
Acrobat.CAcroApp oApp = (Acrobat.CAcroApp)
Activator.CreateInstance(AcroApp);
Acrobat.CAcroAVDoc avdoc= (Acrobat.CAcroAVDoc)
Activator.CreateInstance(AcrobatType);
Acrobat.CAcroPDDoc adoc = (Acrobat.CAcroPDDoc)
Activator.CreateInstance(AcroPD);

avdoc.Open(Server.MapPath("pdfs/test.pdf"),"test PDF");
adoc = (Acrobat.CAcroPDDoc)avdoc.GetPDDoc();

/* I need to get a hold of the form fields here and fill in their values
*/

oApp.Show(); //displays the proper PDF
adoc.Close();

Any help would be greately appreciated.

--
Thanks,

John Scott.


Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Barry Margolin | last post: by
reply views Thread by tshad | last post: by
5 posts views Thread by cgian31 | last post: by
2 posts views Thread by Woody Splawn | last post: by
2 posts views Thread by John Scott | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.