Segev, Eli wrote:

Bruno,

I would like to submit a request to correct the problem in copying
thumbnails from one PDF file to another.  How do I do that?

The problem with this kind of questions, is that an we may be
talking about a completely different problem. You say it doesn't
work, but if we can't reproduce the problem, we can't help you.

The following code snippet is taken from a Servlet I am using.
The doPost gets a String referring to a resource (an existing
PDF file with thumbnails) and String array with page numbers
(if not an HTML page is returned). The String[] is turned into
a comma separated sequence of page numbers.
PdfReader and PdfCopy are used to return a selection of pages
and the Thumbnails panel is opened because thumbnails are
important in this example. This works for me. I hope it works for you.

public void makePdf(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
       try {
           String[] pages = request.getParameterValues("page");
           // take the message from the URL or create default message
           StringBuffer selection = new StringBuffer();
           if (pages.length == 0) {
               response.setContentType("text/html");
makeHtml(response.getOutputStream(), "You must at least choose one!");
               return;
           }
           selection.append(pages[0]);
           for (int i = 1; i < pages.length; i++) {
               selection.append(",");
               selection.append(pages[i]);
           }
           PdfReader reader = new PdfReader(resource);
           reader.selectPages(selection.toString());
           int p = reader.getNumberOfPages();
           Document document = new Document();
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
           PdfCopy copy = new PdfCopy(document, baos);
           document.open();
           for (int i = 0; i < p; ) {
               i++;
               copy.addPage(copy.getImportedPage(reader, i));
           }
           copy.setViewerPreferences(PdfWriter.PageModeUseThumbs);
           copy.setOutlines(SimpleBookmark.getBookmark(reader));
           document.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");
           // setting the content type
           response.setContentType("application/pdf");
           // the contentlength is needed for MSIE!!!
           response.setContentLength(baos.size());
           // write ByteArrayOutputStream to the ServletOutputStream
           ServletOutputStream out = response.getOutputStream();
           baos.writeTo(out);
           out.flush();
       } catch (Exception e) {
System.out.println("Error in " + getClass().getName() + "\n" + e);
           throw(new ServletException(e));
       }
   }


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to