Document.add() will take forever to process a paragraph that long. Break
the text into lines, like in the following example:
public static void createPdfFromString (String aSourceString,
OutputStream aOutputStream)
throws Exception
{
try
{
Document myDocument = new
Document(PageSize.A4,5.0f,5.0f,40.0f,40.0f);
PdfWriter myPdfWriter = PdfWriter.getInstance(myDocument,
aOutputStream);
myDocument.open();
String s;
BufferedReader rr = new BufferedReader(new
StringReader(aSourceString));
Font font = new Font(Font.COURIER,10);
while ((s = rr.readLine()) != null) {
if (s.length() == 0) {
s = "\n";
}
Paragraph para = new Paragraph(12,s,font);
myDocument.add(para);
}
myDocument.close();
}
catch (Exception myException)
{
throw myException;
}
}
Paulo
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of Scott Tyriver
> Sent: Friday, April 27, 2007 4:40 PM
> To: [email protected]
> Subject: [iText-questions] thread hang CPU utilization 100%
>
>
> Hello,
>
> We are running into situations where we are receiving large
> uploaded text files 6 meg in size. We are attempting to
> convert to pdf and seeing the thread hang CPU max at 100% and
> the operation never returns. We are using iText version 1.3.4
> jdk version jdk 1.5_07
>
> Here is our code
>
> public static void createPdfFromString (String aSourceString,
> OutputStream
> aOutputStream)
> throws Exception
> {
> try
> {
> Document myDocument = new
> Document(PageSize.A4,5.0f,5.0f,40.0f,40.0f);
> PdfWriter myPdfWriter =
> PdfWriter.getInstance(myDocument, aOutputStream);
> myDocument.open();
> Paragraph myParagraph = new
> Paragraph(12,aSourceString,new Font(Font.COURIER,10));
> myDocument.add(myParagraph);
> myDocument.close();
> }
>
> catch (Exception myException)
> {
> throw myException;
> }
> }
>
> Is there a size limit that we should be guarding against? Or
> another way to optimize this code?
>
> ______________________________________________________________
> __________________________________
> Scott Tyriver * Systems Development * Mortgage Guaranty
> Insurance Corporation
> 250 East Kilbourn Avenue * Milwaukee WI 53202 * *
> 414.347.6803 * 7 414.347.6710 * * [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>
Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter
informação confidencial ou legalmente protegida. A incorrecta transmissão desta
mensagem não significa a perca de confidencialidade. Se esta mensagem for
recebida por engano, por favor envie-a de volta para o remetente e apague-a do
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de
usar, revelar ou distribuir qualquer parte desta mensagem.
Disclaimer:
This message is destined exclusively to the intended receiver. It may contain
confidential or legally protected information. The incorrect transmission of
this message does not mean the loss of its confidentiality. If this message is
received by mistake, please send it back to the sender and delete it from your
system immediately. It is forbidden to any person who is not the intended
receiver to use, distribute or copy any part of this message.
-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/