Examples of ConcatException


Examples of org.pdfsam.console.exceptions.console.ConcatException

                    fileList = getPdfFiles(inputCommand.getInputDirectory());
                }
            }
            // no input file found
            if (fileList == null || !(fileList.length > 0)) {
                throw new ConcatException(ConcatException.CMD_NO_INPUT_FILE);
            }

            // init
            int pageOffset = 0;
            ArrayList master = new ArrayList();
            Document pdfDocument = null;
            int totalProcessedPages = 0;

            try {
                String[] pageSelections = inputCommand.getPageSelections();
                File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
                int length = ArrayUtils.getLength(pageSelections);

                for (int i = 0; i < fileList.length; i++) {

                    String currentPageSelection = ValidationUtility.ALL_STRING;
                    int currentDocumentPages = 0;
                    if (!ArrayUtils.isEmpty(pageSelections) && i <= length) {
                        currentPageSelection = pageSelections[i].toLowerCase();
                    }

                    String[] selectionGroups = StringUtils.split(currentPageSelection, ",");

                    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;
                        currentDocumentPages += relativeOffset;
                        pageOffset += relativeOffset;
                    }

                    // add pages
                    LOG.info(fileList[i].getFile().getAbsolutePath() + ": " + currentDocumentPages
                            + " pages to be added.");
                    if (pdfWriter == null) {
                        if (inputCommand.isCopyFields()) {
                            // step 1: we create a writer
                            pdfWriter = new PdfCopyFieldsConcatenator(new FileOutputStream(tmpFile), inputCommand
                                    .isCompress());
                            LOG.debug("PdfCopyFieldsConcatenator created.");
                            // output document version
                            if (inputCommand.getOutputPdfVersion() != null) {
                                pdfWriter.setPdfVersion(inputCommand.getOutputPdfVersion().charValue());
                            }
                            HashMap meta = pdfReader.getInfo();
                            meta.put("Creator", ConsoleServicesFacade.CREATOR);
                        } else {
                            // step 1: creation of a document-object
                            pdfDocument = new Document(pdfReader.getPageSizeWithRotation(1));
                            // step 2: we create a writer that listens to the document
                            pdfWriter = new PdfSimpleConcatenator(pdfDocument, new FileOutputStream(tmpFile),
                                    inputCommand.isCompress());
                            LOG.debug("PdfSimpleConcatenator created.");
                            // output document version
                            if (inputCommand.getOutputPdfVersion() != null) {
                                pdfWriter.setPdfVersion(inputCommand.getOutputPdfVersion().charValue());
                            }
                            // step 3: we open the document
                            pdfDocument.addCreator(ConsoleServicesFacade.CREATOR);
                            pdfDocument.open();
                        }
                    }
                    // step 4: we add content
                    pdfReader.selectPages(boundsString);
                    pdfWriter.addDocument(pdfReader);
                    // fix 03/07
                    // pdfReader = null;
                    pdfReader.close();
                    pdfWriter.freeReader(pdfReader);
                    totalProcessedPages += currentDocumentPages;
                    LOG.info(currentDocumentPages + " pages processed correctly.");
                    setPercentageOfWorkDone(((i + 1) * WorkDoneDataModel.MAX_PERGENTAGE) / fileList.length);
                }
                if (master.size() > 0) {
                    pdfWriter.setOutlines(master);
                }
                LOG.info("Total processed pages: " + totalProcessedPages + ".");
                if (pdfDocument != null) {
                    pdfDocument.close();
                }
                // rotations
                if (inputCommand.getRotations() != null && inputCommand.getRotations().length > 0) {
                    LOG.info("Applying pages rotation.");
                    File rotatedTmpFile = applyRotations(tmpFile, inputCommand);
                    FileUtility.deleteFile(tmpFile);
                    FileUtility.renameTemporaryFile(rotatedTmpFile, inputCommand.getOutputFile(), inputCommand
                            .isOverwrite());
                } else {
                    FileUtility.renameTemporaryFile(tmpFile, inputCommand.getOutputFile(), inputCommand.isOverwrite());
                }
                LOG.debug("File " + inputCommand.getOutputFile().getCanonicalPath() + " created.");
            } catch (ConsoleException consoleException) {
                throw consoleException;
            } catch (Exception e) {
                throw new ConcatException(e);
            } finally {
                setWorkCompleted();
            }
        } else {
            throw new ConsoleException(ConsoleException.ERR_BAD_COMMAND);
View Full Code Here

Examples of org.pdfsam.console.exceptions.console.ConcatException

                    } else {
                        retVal.setEnd(pdfNumberOfPages);
                    }
                }
            } catch (NumberFormatException nfe) {
                throw new ConcatException(ConcatException.ERR_SYNTAX, new String[] { "" + currentPageSelection }, nfe);
            }
        }
        return retVal;
    }
View Full Code Here

Examples of org.pdfsam.console.exceptions.console.ConcatException

                    }
                }
            }
            bufferReader.close();
        } catch (IOException e) {
            throw new ConcatException(ConcatException.ERR_READING_CSV_OR_XML, new String[] { inputFile
                    .getAbsolutePath() }, e);
        }
        return (PdfFile[]) retVal.toArray(new PdfFile[0]);
    }
View Full Code Here

Examples of org.pdfsam.console.exceptions.console.ConcatException

                } else {
                    LOG.warn("Node type not supported: " + nodeName);
                }
            }
        } catch (Exception e) {
            throw new ConcatException(ConcatException.ERR_READING_CSV_OR_XML, new String[] { inputFile
                    .getAbsolutePath() }, e);
        }
        return (PdfFile[]) fileList.toArray(new PdfFile[0]);
    }
View Full Code Here

Examples of org.pdfsam.console.exceptions.console.ConcatException

        // get filename
        Node fileNode = pdfNode.selectSingleNode("@value");
        if (fileNode != null) {
            fileName = fileNode.getText().trim();
        } else {
            throw new ConcatException(ConcatException.ERR_READING_CSV_OR_XML, new String[] { "Empty file name." });
        }
        // get pwd value
        Node pwdNode = pdfNode.selectSingleNode("@password");
        if (pwdNode != null) {
            pwd = pwdNode.getText();
View Full Code Here

Examples of org.pdfsam.console.exceptions.console.ConcatException

            if ("xml".equals(getExtension(listFile))) {
                retVal = parseXmlFile(listFile);
            } else if ("csv".equals(getExtension(listFile))) {
                retVal = parseCsvFile(listFile);
            } else {
                throw new ConcatException(ConcatException.ERR_READING_CSV_OR_XML,
                        new String[] { "Unsupported extension." });
            }
        } else {
            throw new ConcatException(ConcatException.ERR_READING_CSV_OR_XML,
                    new String[] { "Input file doesn't exists." });
        }
        return retVal;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.