Examples of SetViewerException


Examples of org.pdfsam.console.exceptions.console.SetViewerException

      setPercentageOfWorkDone(0);
      try{
        PdfFile[] fileList = arraysConcat(inputCommand.getInputFileList(), getPdfFiles(inputCommand.getInputDirectory()));
        //no input file found
        if (fileList== null || !(fileList.length >0)){
          throw new SetViewerException(SetViewerException.CMD_NO_INPUT_FILE);
        }
        for(int i = 0; i<fileList.length; i++){
          try{
            prefixParser = new PrefixParser(inputCommand.getOutputFilesPrefix(), fileList[i].getFile().getName());
            File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
            pdfReader = new PdfReader(new RandomAccessFileOrArray(fileList[i].getFile().getAbsolutePath()),fileList[i].getPasswordBytes());
            pdfReader.removeUnusedObjects();
            pdfReader.consolidateNamedDestinations();
           
            //version
            LOG.debug("Creating a new document.");
            Character pdfVersion = inputCommand.getOutputPdfVersion();
            if(pdfVersion != null){
              pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(tmpFile), inputCommand.getOutputPdfVersion().charValue());
            }else{
              pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(tmpFile), pdfReader.getPdfVersion());
            }
 
            HashMap meta = pdfReader.getInfo();
            meta.put("Creator", ConsoleServicesFacade.CREATOR);
           
            setCompressionSettingOnStamper(inputCommand, pdfStamper);
           
            pdfStamper.setMoreInfo(meta);
            pdfStamper.setViewerPreferences(inputCommand.getDirection() | inputCommand.getLayout() | inputCommand.getMode() | inputCommand.getNfsmode() | getVewerOptions(inputCommand));
            pdfStamper.close();
            pdfReader.close();
           
            File outFile = new File(inputCommand.getOutputFile() ,prefixParser.generateFileName());
              FileUtility.renameTemporaryFile(tmpFile, outFile, inputCommand.isOverwrite());
                    LOG.debug("File "+outFile.getCanonicalPath()+" created.");
            setPercentageOfWorkDone(((i+1)*WorkDoneDataModel.MAX_PERGENTAGE)/fileList.length)
          }
            catch(Exception e){
              LOG.error("Error setting options for file "+fileList[i].getFile().getName(), e);
            }
        }
        LOG.info("Viewer options set. Pdf files created in "+inputCommand.getOutputFile().getAbsolutePath()+".");
      }catch(Exception e){       
        throw new SetViewerException(e);
      }finally{
        setWorkCompleted();
      }   
    }else{
      throw new ConsoleException(ConsoleException.ERR_BAD_COMMAND);
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.