I'm able to create pdf in the servlet and show it in the browser as well as merge multiple pdfs. My problem is i do not know how to add existing pdf files to newly created pdf.

Matt Benson <[EMAIL PROTECTED]> wrote:
And what problem are you experiencing?

-Matt

--- v b <[EMAIL PROTECTED]>wrote:
> Hi All,
> I'm trying to do the following: 1. create one page
> pdf file with some content 2. import multiple pdf
> files 3. concat everything into one document and
> show this document in the browser. Note everything
> should be done using servlet in the Tomcat
> environment.
>
> I tried to use some of the provided examples.
>
>
> import java.io.*;
> import java.text.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import com.lowagie.text.*;
> import com.lowagie.text.pdf.*;
>
> public class PDFTest extends HttpServlet
> {
> public void doGet(HttpServletRequest
> request,
> HttpServletResponse response) throws
> ServletException, IOException
> {
> OutputStream out = response.getOutputStream();
> ByteArrayOutputStream baos = new
> ByteArrayOutputStream();
>
> String args[] = { "C:\\Chap0101.pdf",
> "C:\\Chap0102.pdf","C:\\Chap0103.pdf",
> "C:\\Chap0201.pdf"};
> try
> {
> Document document = new Document();
> PdfWriter.getInstance(document, baos);
> document.open();
> document.add(new Paragraph("Hello World"));
> document.add(new Paragraph("Hello World"));
> /*------------------------------*/
> int f = 0;
> // String outFile = args[args.length-1];
> // Document document = null;
> PdfCopy writer = null;
> while (f < args.length-1) {
> // we create a reader for a certain
> document
> PdfReader reader = new PdfReader(args[f]);
> // we retrieve the total number of pages
> int n = reader.getNumberOfPages();
> System.out.println("There are " + n + "
> pages in " + args[f]);
> if (f == 0) {
> // step 1: creation of a document-object
> document = new
> Document(reader.getPageSizeWithRotation(1));
> // // step 2: we create a writer that listens
> to the document
> // writer = new PdfCopy(document, new
> FileOutputStream(outFile));
> // step 3: we open the document
> document.open();
> }
> // step 4: we add content
> PdfImportedPage pdfPage;
> for (int i = 0; i < n; ) {
> ++i;
> pdfPage = writer.getImportedPage(reader, i);
> writer.addPage(pdfPage);
> System.out.println("Processed page " + i);
> }
> PRAcroForm form = reader.getAcroForm();
> // if (form != null)
> // writer.copyAcroForm(reader);
> // f++;
> }
> /*------------------------------*/
> document.close();
> response.setContentType("application/pdf");
> response.setContentLength(baos.size());
> response.setBufferSize(baos.size());
> baos.writeTo(out);
> out.flush();
> }
> catch (Exception e)
> {
> System.err.println(e.toString());
> }
> finally
> {
> out.close();
> }
> }
> }
>
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Free online calendar with sync to Outlook(TM).


__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com


Do you Yahoo!?
Free online calendar with sync to Outlook(TM).

Reply via email to