Hi,
The Adobe Acrobat Standard (7.0 and over) support functionality "Open Table in 
Spreadsheet", that let you select test in the PDF, click right button over the 
selected text and open selected content in Excel.
We are using iText version 1.3.6 to merge multiple PDF documents in one. Before 
merge "Open Table in Spreadsheet" functionality exist, after merge this 
functionality does not exist.
Could you give me some suggestions what could be done to fix it? Does the 
latest version 1.3.6 support this functionality?

Here is a code we use:

public void mergePdf(OutputStream out, DocumentRequestValue request)
                throws PdfGenerationException {
                List documents = request.getDocuments();
                DocumentValue docVal = null;

                PdfReader reader = null;
                Document document = null;
                PdfWriter writer = null;

                try {
                        // if empty document set don't do anything
                        if (documents.size() < 1)
                                throw new PdfGenerationException(
                                        "empty document set for request: "
                                                + request.getRequestId());

                        // log document access
                        DocumentRequestDAO requestDAO = new DocumentRequestDAO
();
                        request.setAccessSite("AI");
                        try {
                                requestDAO.logRequest(request);
                        } catch (DAOException daoe) {
                                logger.error(daoe);
                                throw new PdfGenerationException(daoe);
                        }

                        docVal = (DocumentValue) documents.get(0);
                        
                        // create a pdf reader that reads actual file
                        reader = new PdfReader(getPdf(docVal));

                        // create a pdf document that will be used to retrieve 
pdf details
                        document = new Document(reader.getPageSizeWithRotation
(1));

                        // create a pdf writer to write file
                        writer = PdfWriter.getInstance(document, out);

                        // add some meta info
                        document.addAuthor("Prudential Finantial");
                        document.addCreator("Prudential Finantial");
                        document.addSubject(
                                "iText Library - Copyright (C) 1999-2004 by 
Bruno Lowagie and Paulo Soares. All Rights Reserved. ");
                        document.addTitle("Download Pdf");

// open the document once
                        document.open();                        

// don't know what this does
                        // somekind of page writer
                        PdfContentByte cb = writer.getDirectContent();

                        int docIndex = 0;

                        // loop on documents
                        while (true) {
                                // this is copied from itext examples, it is 
weird
                                // don't know if it is all needed

                                // get number of pages in current doc
                                int pages = reader.getNumberOfPages();

                                // loop on each page in document
                                int i = 0;
                                PdfImportedPage page;
                                while (i < pages) {
                                        i++;
                                        document.setPageSize
(reader.getPageSizeWithRotation(i));
                                        document.newPage();

                                        // get page from reader
                                        page = writer.getImportedPage(reader, 
i);
                                        int rotation = reader.getPageRotation
(i);

                                        // think this for pages that aren't 
landscape
                                        // adds actual page to output
                                        if (rotation == 90 || rotation == 270) {
                                                cb.addTemplate(
                                                        page,
                                                        0,
                                                        -1f,
                                                        1f,
                                                        0,
                                                        0,
                                                
        reader.getPageSizeWithRotation(i).height());
                                        } else {
                                                cb.addTemplate(page, 1f, 0, 0, 
1f, 0, 0);
                                        }
                                }

                                // update index, if just processed last doc 
then stop
                                ++docIndex;
                                if (docIndex == documents.size())
                                        break;

                                // get next document for next pass through loop
                                //
                                // creating a new reader automatically updates 
document
                                docVal = (DocumentValue) documents.get
(docIndex);
                                reader = new PdfReader(getPdf(docVal));
                        }
                        // closing document automatically closes reader/writer
                        //document.close();
                } catch (IOException ex) {
                        logger.error("IOException from iText", ex);
                        throw new PdfGenerationException(ex, "IOException from 
iText");
                } catch (DocumentException ex) {
                        logger.error("DocumentException from iText", ex);
                        throw new PdfGenerationException(
                                ex,
                                "DocumentException from iText");
                } finally {
                        // closing document automatically closes reader/writer
                        if (document != null) {
                                document.close();
                        }
                }
        }


Thanks

Ivaylo




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to