Hello,
I'm pretty new to this mailing list. So far I couldn't find a similar
question in the last postings, so if I happen to ask something that has
been discussed before, please route me to that thread.
I want to write a Java-Servlet using itext, which will open a certain
PDF-document with prepared form-fields (for adress, date, some other
textual content, empty by default) when called by the client. The
servlet should take some data from our database and fill the form-fields
of the PDF-document before giving it to the response of the request.
In my current approach I tried to use PDFReader and PDFStamper to open
the PDF-document and to fill the relevant fields with setField(). Then I
would send he Output of PdfStamper into the response-stream. However,
the Client only gets the empty document, no filled fields. What am I
doing wrong?
Here is the java method that I use to open the document, fill its fields
and deliver the filled-out document to the user:
--- snip ---
public void fillAndDeliver(HttpServletResponse response, String pdfdoc,
String address, String content) {
PdfReader reader = new PdfReader(pdfdoc);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Fill the Fields
PdfStamper stamp = new PdfStamper(reader, baos);
AcroFields form = stamp.getAcroFields();
form.setField("address", address);
form.setField("content", content);
stamp.close();
// setting some response headers
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate,
post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
response.setContentType("application/pdf");
response.setContentLength(baos.size());
// write ByteArrayOutputStream to the ServletOutputStream
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
return;
}
--- snip! ---
Thank you in advance,
Oliver Schönwald
--
Oliver Schönwald, Diplom-Informatiker
FernUniversität Hagen
Zentrum für IT und Medien (ZMI) - Competence Center Anwendungsentwicklung
Universitätsstr.21/AVZ - 58084 Hagen - Deutschland
fon: +49 2331 987 1721 - email: [EMAIL PROTECTED]
begin:vcard
fn:Oliver Schoenwald
n:Schoenwald;Oliver
org;quoted-printable:FernUniversitaet Hagen;ZMI - Zentrum f=C3=BCr Medien und IT
adr:;;Universitaetsstrasse 21;Hagen;NRW;58300;Deutschland
email;internet:[EMAIL PROTECTED]
tel;work:02331 987 1721
x-mozilla-html:FALSE
url:http://www.fernuni-hagen.de
version:2.1
end:vcard
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/