I've written
a jsp page that produces a PDF using iText
and it work great until 2 people try and
run the report at the same time.
I get a variety
of errors including
DocumentException
: Document is closed.
ConcurrentModficationException
NullPointerException
as well as
pdf's that are corrupt.
I haven't declared
a single thing on the page as being static.
All the exceptions are generated when trying
to call a Document method so I'm wondering
if maybe the document object isn't thread
safe?
This is my
document creation code.
document = new Document(PageSize.A4.rotate());
baseFont = BaseFont.createFont("Helvetica",
BaseFont.WINANSI, false);
font
= new Font(baseFont, defaultFontSize);
totalFont
= new Font(baseFont, 9);
totalFont.setStyle(Font.BOLD);
heading1Font
= new Font(baseFont, 20, Font.BOLDITALIC,
new Color(0, 0, 0));
heading2Font
= new Font(baseFont, 17, Font.BOLDITALIC,
new Color(0, 0, 0));
heading3Font
= new Font(baseFont, 14, Font.BOLDITALIC,
new Color(0, 0, 0));
defaultLayoutCell
= new Cell();
defaultLayoutCell.setBorder(Rectangle.NO_BORDER);
ByteArrayOutputStream baos = new
ByteArrayOutputStream();
writer
= PdfWriter.getInstance(document, baos);
//writer.setEncryption(false,
"", "", PdfWriter.AllowCopy | PdfWriter.AllowPrinting);
PageEventHandler pageEventHandler
= new PageEventHandler();
writer.setPageEvent(pageEventHandler);
writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
// step 3: we open the document
document.open();
Regards
Peter Wilkinson
System Developer
Mantel Solutions
Pty Ltd
PO Box 98,
35 Hamilton Road
Moorooka QLD
4105
P: +61 7 3848
0001
F: +61 7 3392
9923
The information
contained in this electronic message (e-mail)
and any files transmitted with it, is intended
for the named recipients only. It may
contain privileged and or confidential information
and if you are not the intended recipient
you must not copy distribute or take any
action in reliance on it. If you have received
this electronic message (e-mail) and any
files transmitted with it in error please
delete immediately and advise Mantel Solutions
on 07 3848 0001.