?
Solved

How to generate a read-only PDF document from database data.

Posted on 2005-02-24
8
Medium Priority
?
997 Views
Last Modified: 2008-01-09
I have information in a database that I want to use to dynamically generate a read-only PDF document that  s user can then print out.

I've tried to find information on how to accomplish this in a simple manner but all the postings I've seen refer to submitting entered data from the PDF document itself.

I'm assuming I need to create a PDF template somehow, in the process putting in place holders for the dynamic data. I'm then hoping that I can generate an FDF file from this template. Once I have these 2 items I guess it should be relatively straightforward for me to modify the FDF on the fly with data from the database and then marry that with the PDF template to give the user what they want.

Am I on the right lines and if so which tools do I use to accomplish the above? Or is there a better solution to what I am trying to achieve?

thanks in anticipation


0
Comment
Question by:ucacppw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 13398317
How do you want to deliver these PDF files to your users?

In general, there are two way, you  can accomplish this: The solution you've proposed is one option. In addition to this, you can also generate a PDF file from scratch with a library like e.g. iText (http://www.lowagie.com/iText/ - this is a free Java library) or iSEDQuickPDF (http://www.sedtech.com/isedquickpdf/ - $99 for different programming environments).
In this case, you would use e.g. a ASP page on a web server to get the raw data from the database, and then use iSEDQuickPDF to create your PDF file.

If you want to go the PDF route, you need the full version of Acrobat Professional to create your form that will then get filled in with your database data. A potential problem here is that if you don't know how many data sets you want to display on one page, the JavaScript support required to make this work might be a bit overwhelming. If it's always the same data (eg you don't need to create tables with a variable number of records), then this is a pretty simple way to do this.

Once you have your form, fill it in with dummy data and export the form data as FDF file. Analyze this FDF file, and then create this in your program. You will notice that the format is pretty simple.

Once you have both a FDF file and the PDF template, you can use a tool like pdftk (http://www.accesspdf.com/pdftk/) to merge the PDF and FDF data. You also need to flatten the file so that the form data can no longer be modified. This can also be done with pdftk.

0
 

Author Comment

by:ucacppw
ID: 13398700
Thanks khkremer,

in answer to your question the PDF file will be delivered to the users over the internet. The user will log into our web-site which contains user-specific data in our database. The user will then click an html link to open up a read-only PDF file containing user-specific data.

This may sound like a simple question but what how do I go about creating the PDF template in acrobat professional? If I select "File-Create PDF" the only options I get are to create the PDF from an external file.

I do not have any such external files so it would be probably better for me to create the PDF template directly in acrobat professional. Is that possible and if so how do I do it and put in the placeholders for my dynamic data?
0
 

Author Comment

by:ucacppw
ID: 13402272
After a bit more experimenting I managed to create a PDF form in acrobat 7.0 professional by choosing Advanced-Forms-Create New Form which then takes me to Adobe Designer. I then chose an option for a form for electronic filling of data. I'm assuming that at some later date(once I've got the FDF) I can make this PDF file read-only.

Anyway I have just tried opening the form in acrobat professional. I then chose "File - Form Data - Export Data From Form" but the only options available for export format are *.xml *.xdp *.txt. There was no option for FDF.

How do I obtain the FDF file? Once I have this as khkremer mentioned I can then regenerate the FDF on the fly with the users data in order to create a user-specific read-only PDF file.
0
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 13403011
Adobe Designer will not work with FDF files!

To create a new form, you would usually start with another application and create the static elements in e.g. Word, InDesign, PageMaker, ... You would then convert this document to PDF. Once this is in PDF form, you can then add forms elements.

You add forms elements with the forms tool (Tools>Advanced Editing, there you can then find the differen form elements like Button Tool, Checkbox Tool, Text Field Tool, ...)
After you added your form fields, you would then save your form (just so that you don't destroy it when playing more with the form fields and the FDF data). Enter information into your form and select Advanced>Forms>Export Data from From.

If you want to start with a blank page, bring up the JavaScript debugger and type the following command:

app.newDoc()

Then (with the cursor still at the end of this line) use the "Enter" key on the numeric keypad. The normal Enter key will not work for this.
0
 

Author Comment

by:ucacppw
ID: 13407103
Thanks khkremer,

I've tried everything you said, i.e. create FDF file from PDF and run pdftk. And it works. However the big problem is, if the data in the FDF is too large for the text fields in the PDF, the text fields do not auto-adjust their size, nor does the position of the text from the original word document used to the create the PDF auto-adjust its position. The result is loss of data. This is a problem as I cannot guarantee the size of the data items to go in each text field.

Is this a limitation of this simple approach? If so which is the next simplest approach I might try.

Also I should have mentioned, the final PDF will actually be an invoice and will contain a list of a variable number of items together with their associated costs, with a final cost at the bottom.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 13407543
Yes, this is a limitation of this approach. There is not much you can do about this besides dynamically changing the box size depending on the content. This will however require some serious JavaScript programming.

Given the type of document you want to generate, there are a number of other solutions that you can use. None of them however as simple as the FDF approach.

One option is to generate a XML file with your data, and then use XSL/FO to format this XML data as PDF. You can give this a try for free if you use the Apache FOP software (http://xml.apache.org/fop/). If you like this approach, but need a more robust solution, you can try commercial offerings (e.g. http://www.antennahouse.com/)

Another solution (as I already indicated) is to generate PDF from scratch with the two products I mentioned or e.g. PDFLib (http://www.pdflib.com/) which is a pretty mature and powerful library. This does however involve programming.
0
 

Author Comment

by:ucacppw
ID: 13409769
Thanks again khkremer,

one final question before I allocate your well deserved points.

Our system is a java based application running on a tomcat web server and I am a proficient java programmer. Considering this and my requirements which you have a good idea of now, which of the alternative solutions that you have mentioned would you go for if you were in my position?
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 2000 total points
ID: 13409937
Take a serious look at iText. It's a Java library, and you can find a tutorial on the web site. This should get you started. If you have any questions along the way, I will try to help (I'm not programming in Java, but I'm pretty familiar with the PDF format).
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
Have you ever come up with a need of emailing only few pages of PDF file to one of yourfriend or colleague, instead of whole Adobe file? If yes, then surely you have face problems in doing that! Read this section as I have suggested multiple solutio…
In this second video of the Xpdf series, we discuss and demonstrate the PDFimages utility, which, in a single command, is able to extract all the images from a PDF file and save each one in a separate image file (PBM, PPM, or JPG). Download and inst…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Suggested Courses

762 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