Nico Van den Broeck wrote:
This is the MergePdfByteArray class
(some code I found on the mailing list)
OK, it looks good at first sight.
The first thing you should establish is if the problem is related to the
fact that you are using a web app or to a programming error.
You should write the file you want to see in the browser to a file (from
inside the servlet). If the file looks alright, but the problem in the
browser remains, you need to apply the work around mentionned in the
tutorial.
package application.printtest;
import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class MergePdfByteArrays
{
private ByteArrayOutputStream outStream = new
ByteArrayOutputStream();
private Document document = null;
private PdfCopy writer = null;
public MergePdfByteArrays()
{ super(); }
ByteArrayOutputStream getOutputStream()
{ return this.outStream; }
void setOutputStream(ByteArrayOutputStream outStreamInput)
{ this.outStream = outStreamInput; }
public byte[] getMergedPdfByteArray()
{
if(this.outStream != null )
{ return this.outStream.toByteArray(); }
else
{ return null;}
}
public void add(byte[] pdfByteArray)
{
try
{
PdfReader reader = new PdfReader(pdfByteArray);
int numberOfPages = reader.getNumberOfPages();
if(this.document == null)
{
this.document = new
Document(reader.getPageSizeWithRotation(1));
this.writer = new PdfCopy( this.document,
this.getOutputStream()
);
this.document.open();
}
PdfImportedPage page;
for(int i = 0; i < numberOfPages; )
{
++i;
page = this.writer.getImportedPage(reader,
i);
this.writer.addPage(page);
}
PRAcroForm form = reader.getAcroForm();
if(form != null)
{ this.writer.copyAcroForm(reader); }
}
catch(Exception e)
{ e.printStackTrace(); }
}
public void close()
{
try
{
this.document.close();
this.outStream.close();
}
catch(Exception e)
{ e.printStackTrace(); }
}
}
-----Original Message-----
From: Bruno Lowagie [mailto:[EMAIL PROTECTED]
Sent: donderdag 3 november 2005 16:24
To: Nico Van den Broeck
Cc: [email protected]
Subject: Re: [iText-questions] Merging dynamically generated documents in
servlet environment
Nico Van den Broeck wrote:
MergePdfByteArrays pdfMerger = new MergePdfByteArrays();
What is this MergePdfByteArray class?
It doesn't just append byte array I hope?
writer = new PdfCopy(document, response.getOutputStream());
Writing directly to the OutputStream directly works for many browsers
and in many cases, but it's dangerous. Read the tutorial on web
applications:
http://itextdocs.lowagie.com/tutorial/general/webapp/#HelloWorld
br,
Bruno
(Ik zeg niet dat dit werkelijk het probleem is, ik heb gewoon de code
overlopen en dat waren de dingen die me op het eerste zicht opvielen.)
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions