Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate pdf fields with ASP

Status
Not open for further replies.

Cineno

Programmer
Jul 24, 2006
142
US
Hello. I have a pdf file with specific fields that need to populated with a person's data. I'm using ASP connecting to a SQL database.

I was wondering if anyone has any instructions or examples on how I can populate this pdf template with the user's data.

Any help is appreciated. Thanks!
 
Thanks for the help. I've looked at the examples you given and they seem great, but it's not exactly what I'm looking for.

Most of the examples I've seen have the pdf form already open, then an event occurs (user clicks button, etc.) and the asp populates the fields. What I'm looking for is when a user fills out forms in on my asp webpage and clicks submit, the pdf file opens with their data populated. Is there any way to do this?
 
Yes. There are two ways. One 'proper and tricky' and one 'easy and not-so-slick'.

The pdf is a text file that you can read into the asp. Then do a simple replace to 'insert' your elements. Say your pdf has something like:

Name: xxinsertNameHerexxx

Read in the pdf file with the file system read. then use a REPLACE(pdfStream, "xxinsertNameHerexxx", varUserName)

Then output the pdf back to the user.

The 'proper' way involves using Adobe's javascript. Find a file called ADBCDEMO.pdf in Acrobat. It shows you how to insert values from a database into a pdf form. It would be relatively simple to use values from a form rather than a database.
 
Thanks a lot, this sounds like exactly what I need! (the easy not-so-slick choice, haha)

Do you have an example of how to do the file system read? I haven't done that in asp before.
 
I used the AspPDF object to fill in IRS tax forms as you describe. The PDF file contains textbox objects drawn on top of the blanks that you would write in if filling the tax form out by hand. The AspPDF object is used to set the value of these textboxes and then send the "completed" form to the browser.
 
Does anyone know if there's a way with the FileSystemObject that I can open a Word document, replace what I need to replace, and then save it as a .pdf?

If so, is there any example code you could provide.
 
You might be able to do it by starting up an instance of the Word application in memory and then using the PDF printer driver to "print" a PDF file but there is a particular type of problem running Word like that and you're likely to end up with multiple copies of winword.exe running and eating up memory on your server and the only way to stop them running is to bring up the task manager and do "end task
 
PDF:
<%
set fso = server.createobject("Scripting.FileSystemObject")
set ts = fso_OpenTextFile("C:\Inetpub\
myFile = ts.ReadAll
Response.ContentType = "application/pdf"
response.write Replace(myFile,"namePlaceHolder","John Doe")
%>

Word:
<%
set fso = server.createobject("Scripting.FileSystemObject")
set ts = fso_OpenTextFile("C:\Inetpub\
myFile = ts.ReadAll
Response.ContentType = "application/msword"
response.write Replace(myFile,"namePlaceHolder","John Doe")
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top