Package org.pdfsam.console.business.pdf.bookmarks

Examples of org.pdfsam.console.business.pdf.bookmarks.BookmarksProcessor


                    pdfReader = new PdfReader(new RandomAccessFileOrArray(fileList[i].getFile().getAbsolutePath()),
                            fileList[i].getPasswordBytes());
                    pdfReader.removeUnusedObjects();
                    pdfReader.consolidateNamedDestinations();
                    int pdfNumberOfPages = pdfReader.getNumberOfPages();
                    BookmarksProcessor bookmarkProcessor = new BookmarksProcessor(SimpleBookmark.getBookmark(pdfReader), pdfNumberOfPages);

                    List boundsList = getBounds(pdfNumberOfPages, selectionGroups);
                    ValidationUtility.assertNotIntersectedBoundsList(boundsList);
                    String boundsString = "";

                    for (Iterator iter = boundsList.iterator(); iter.hasNext();) {
                        Bounds bounds = (Bounds) iter.next();
                        boundsString += (boundsString.length() > 0) ? "," + bounds.toString() : bounds.toString();

                        // bookmarks
                        List bookmarks = bookmarkProcessor.processBookmarks(bounds.getStart(), bounds.getEnd(),
                                pageOffset);
                        if (bookmarks != null) {
                            master.addAll(bookmarks);
                        }
                        int relativeOffset = (bounds.getEnd() - bounds.getStart()) + 1;
View Full Code Here


                inputCommand.getInputFile().getPasswordBytes());
        pdfReader.removeUnusedObjects();
        pdfReader.consolidateNamedDestinations();

        int n = pdfReader.getNumberOfPages();
        BookmarksProcessor bookmarkProcessor = new BookmarksProcessor(SimpleBookmark.getBookmark(pdfReader), n);
        int fileNum = 0;
        LOG.info("Found " + n + " pages in input pdf document.");

        Integer[] limits = inputCommand.getSplitPageNumbers();
        // limits list validation end clean
        TreeSet limitsList = validateSplitLimits(limits, n);
        if (limitsList.isEmpty()) {
            throw new SplitException(SplitException.ERR_NO_PAGE_LIMITS);
        }

        // HERE I'M SURE I'VE A LIMIT LIST WITH VALUES, I CAN START BOOKMARKS
        int currentPage;
        Document currentDocument = new Document(pdfReader.getPageSizeWithRotation(1));
        int relativeCurrentPage = 0;
        int endPage = n;
        int startPage = 1;
        PdfImportedPage importedPage;
        File tmpFile = null;
        File outFile = null;

        Iterator itr = limitsList.iterator();
        if (itr.hasNext()) {
            endPage = ((Integer) itr.next()).intValue();
        }
        for (currentPage = 1; currentPage <= n; currentPage++) {
            relativeCurrentPage++;
            // check if i've to read one more page or to open a new doc
            if (relativeCurrentPage == 1) {
                LOG.debug("Creating a new document.");
                fileNum++;
                tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
                String bookmark = null;
                if (bookmarksTable != null && bookmarksTable.size() > 0) {
                    bookmark = (String) bookmarksTable.get(new Integer(currentPage));
                }
                FileNameRequest request = new FileNameRequest(currentPage, fileNum, bookmark);
                outFile = new File(inputCommand.getOutputFile(), prefixParser.generateFileName(request));
                startPage = currentPage;
                currentDocument = new Document(pdfReader.getPageSizeWithRotation(currentPage));

                pdfWriter = new PdfSmartCopy(currentDocument, new FileOutputStream(tmpFile));

                // set creator
                currentDocument.addCreator(ConsoleServicesFacade.CREATOR);

                setCompressionSettingOnWriter(inputCommand, pdfWriter);
                setPdfVersionSettingOnWriter(inputCommand, pdfWriter, Character.valueOf(pdfReader.getPdfVersion()));

                currentDocument.open();
            }

            importedPage = pdfWriter.getImportedPage(pdfReader, currentPage);
            pdfWriter.addPage(importedPage);

            // if it's time to close the document
            if (currentPage == endPage) {
                LOG.info("Temporary document " + tmpFile.getName() + " done, now adding bookmarks...");
                // manage bookmarks
                List bookmarks = bookmarkProcessor.processBookmarks(startPage, endPage);
                if (bookmarks != null) {
                    pdfWriter.setOutlines(bookmarks);
                }
                relativeCurrentPage = 0;
                currentDocument.close();
View Full Code Here

        pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile().getAbsolutePath()),
                inputCommand.getInputFile().getPasswordBytes());
        pdfReader.removeUnusedObjects();
        pdfReader.consolidateNamedDestinations();
        int n = pdfReader.getNumberOfPages();
        BookmarksProcessor bookmarkProcessor = new BookmarksProcessor(SimpleBookmark.getBookmark(pdfReader), n);
        int fileNum = 0;
        LOG.info("Found " + n + " pages in input pdf document.");
        int currentPage;
        Document currentDocument = new Document(pdfReader.getPageSizeWithRotation(1));
        PdfImportedPage importedPage;
        File tmpFile = null;
        File outFile = null;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int startPage = 0;
        int relativeCurrentPage = 0;
        for (currentPage = 1; currentPage <= n; currentPage++) {
            relativeCurrentPage++;
            // time to open a new document?
            if (relativeCurrentPage == 1) {
                LOG.debug("Creating a new document.");
                startPage = currentPage;
                fileNum++;
                tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
                FileNameRequest request = new FileNameRequest(currentPage, fileNum, null);
                outFile = new File(inputCommand.getOutputFile(), prefixParser.generateFileName(request));
                currentDocument = new Document(pdfReader.getPageSizeWithRotation(currentPage));
                baos = new ByteArrayOutputStream();
                pdfWriter = new PdfSmartCopy(currentDocument, baos);
                // set creator
                currentDocument.addCreator(ConsoleServicesFacade.CREATOR);

                setCompressionSettingOnWriter(inputCommand, pdfWriter);
                setPdfVersionSettingOnWriter(inputCommand, pdfWriter, Character.valueOf(pdfReader.getPdfVersion()));

                currentDocument.open();
            }

            importedPage = pdfWriter.getImportedPage(pdfReader, currentPage);
            pdfWriter.addPage(importedPage);
            // if it's time to close the document
            if ((currentPage == n)
                    || ((relativeCurrentPage > 1) && ((baos.size() / relativeCurrentPage) * (1 + relativeCurrentPage) > inputCommand
                            .getSplitSize().longValue()))) {
                LOG.debug("Current stream size: " + baos.size() + " bytes.");
                // manage bookmarks
                List bookmarks = bookmarkProcessor.processBookmarks(startPage, currentPage);
                if (bookmarks != null) {
                    pdfWriter.setOutlines(bookmarks);
                }
                relativeCurrentPage = 0;
                currentDocument.close();
View Full Code Here

TOP

Related Classes of org.pdfsam.console.business.pdf.bookmarks.BookmarksProcessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.