Sarah1 (12) [Avatar] Offline
#1
Hi,

I successfully created my PDF Forms, and I save all the forms in the file system.

Now in my JSP I need show this Form with dynamically data from database. Could you pls direct me the correct way to do it?

Thanks in advance.

Sarah
Sarah1 (12) [Avatar] Offline
#2
Re: dynamically display PDF Form
Do I have to create all FDF files for every records in database, then use FDFs to fill the form fields??

If Yes, I need create millions of FDF files. I tried to avoid it.

Thanks.

Sarah
blowagie (284) [Avatar] Offline
#3
Re: dynamically display PDF Form
Please read chapter 17 about serving PDFs to a browser in a web application.
This forum is for people that have the book; it's not the Publisher's intention that complete chapters of the book are copied here.
blowagie (284) [Avatar] Offline
#4
Re: dynamically display PDF Form
As you are asking this question about creating FDF files, I understand that you either didn't read chapter 16, or that you didn't understand it. It should be evident that you don't need to create any FDF files if you want to fill out a form.
Sarah1 (12) [Avatar] Offline
#5
Re: dynamically display PDF Form
I already have Form PDF template in file system. Now I need populated data into the form template, and display the PDF form on the fly.

You are right, and I don't need create any FDF files. I tried the following JSP, and always got blank page. But I successfully created the same PDF form with data in the file system, so it's not the form problem. I read chapter 17 Page 539, it needs set content length, that's why I tried "response.setContentLength(reader.getFileLength());" , but it still doesn't help.

So I have to store this PDF Form (with data) in file system, and then display it on browser??

****************************************************************
try {
PdfReader reader;
PdfStamper stamper;
AcroFields form;

reader = new PdfReader("C:/_JBuilder2005Webs/"+protocol+"_"+frm+"_"+ver+".pdf");

response.setContentType("application/pdf");
response.setContentLength(reader.getFileLength());

stamper = new PdfStamper(reader, response.getOutputStream());
form = stamper.getAcroFields();
form.setField("FormName.SITENO", "11");
form.setField("FormName.PATID", "0000006");
stamper.close();

} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
************************************************************************************

Thanks.

Sarah
blowagie (284) [Avatar] Offline
#6
Re: dynamically display PDF Form
1. It is very bad taste using JSP to create binary files. I can't repeat that enough. Yesterday somebody on the mailing list excused himself by saying he used JSP to have a quick way to test the functionality. THAT IS NONSENSE! When you write a JSP in your IDE, the JSP code is first translated to a Servlet; then the Servlet is compiled. If you write a Servlet to begin with, the Servlet is compiled and deployed on the built-in server of your IDE immediately. That's MUCH FASTER.

2. I don't know why you expect your code to work. You have an original file with X bytes (in PdfReader). Now you are going to create a new file of Y bytes (with PdfStamper). You want the browser to get the new file with Y bytes. Then why do you tell the browser to expect only X bytes?
Sarah1 (12) [Avatar] Offline
#7
Re: dynamically display PDF Form
So my question is:

Since the data is from database, it's dynamic. I don't know the length of the data. This means I can't populate PDF Form with data, and display it on the fly??

Thanks.

Sarah
blowagie (284) [Avatar] Offline
#8
Re: dynamically display PDF Form
From your question on the mailing list, I see that you've already found the answer (as could be found in chapter 17).
segraves (9) [Avatar] Offline
#9
Re: dynamically display PDF Form
Sarah, you have not given us enough information for determination of the best approach to solving your problem, e.g., do you require the "filled" PDF to be served, or would serving an FDF with the target PDF specified in the FDF's /F spec be satisfactory?

You could completely eliminate the need to create/save PDFs on the server side of the transaction if you would serve FDFs and let the client-side browser fetch the correct target PDF for merging with the FDF. But then, your questions would not be appropriate for this forum.

You will get more useful responses to your questions if you tell us a bit more about your requirements.

Bill Segraves
Sarah1 (12) [Avatar] Offline
#10
Re: dynamically display PDF Form
Thanks! After doing some research, I got it.

Sarah