Package org.pdfsam.console.utils.perfix

Examples of org.pdfsam.console.utils.perfix.PrefixParser


    if ((parsedCommand != null) && (parsedCommand instanceof EncryptParsedCommand)) {

      EncryptParsedCommand inputCommand = (EncryptParsedCommand) parsedCommand;
      setPercentageOfWorkDone(0);
      int encType = PdfWriter.STANDARD_ENCRYPTION_40;
      PrefixParser prefixParser;
      try {
        PdfFile[] fileList = arraysConcat(inputCommand.getInputFileList(), getPdfFiles(inputCommand.getInputDirectory()));
        // check if empty
        if (fileList == null || !(fileList.length > 0)) {
          throw new EncryptException(EncryptException.CMD_NO_INPUT_FILE);
        }
        for (int i = 0; i < fileList.length; i++) {
          try {
            // set the encryption type
            if (EncryptParsedCommand.E_AES_128.equals(inputCommand.getEncryptionType())) {
              encType = PdfWriter.ENCRYPTION_AES_128;
            } else if (EncryptParsedCommand.E_RC4_128.equals(inputCommand.getEncryptionType())) {
              encType = PdfWriter.STANDARD_ENCRYPTION_128;
            }

            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.setEncryption(encType, inputCommand.getUserPwd(), inputCommand.getOwnerPwd(), inputCommand.getPermissions());
            pdfStamper.close();
            pdfReader.close();
            File outFile = new File(inputCommand.getOutputFile(), prefixParser.generateFileName());
            FileUtility.renameTemporaryFile(tmpFile, outFile, inputCommand.isOverwrite());
            LOG.debug("Encrypted file " + outFile.getCanonicalPath() + " created.");
            setPercentageOfWorkDone(((i + 1) * WorkDoneDataModel.MAX_PERGENTAGE) / fileList.length);
          } catch (Exception e) {
            LOG.error("Error encrypting file " + fileList[i].getFile().getName(), e);
View Full Code Here


  public void execute(AbstractParsedCommand parsedCommand) throws ConsoleException {
    if((parsedCommand != null) && (parsedCommand instanceof SetViewerParsedCommand)){
     
      SetViewerParsedCommand inputCommand = (SetViewerParsedCommand) parsedCommand;

      PrefixParser prefixParser;
      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){
View Full Code Here

  public void execute(AbstractParsedCommand parsedCommand) throws ConsoleException {
   
    if((parsedCommand != null) && (parsedCommand instanceof SlideShowParsedCommand)){ 
     
      SlideShowParsedCommand inputCommand = (SlideShowParsedCommand) parsedCommand;
      PrefixParser prefixParser;
      setPercentageOfWorkDone(0);     
      Transitions transitions = new Transitions();
      transitions.setDefaultTransition(inputCommand.getDefaultTransition());
      transitions.setTransitions(inputCommand.getTransitions());     
      transitions = parseXmlInput(inputCommand.getInputXmlFile(), transitions);
      try{
        prefixParser = new PrefixParser(inputCommand.getOutputFilesPrefix(), inputCommand.getInputFile().getFile().getName());       
        File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
       
        pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile().getAbsolutePath()),inputCommand.getInputFile().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());
        }
       
        //creator
        HashMap meta = pdfReader.getInfo();
        meta.put("Creator", ConsoleServicesFacade.CREATOR);
       
        //compression
        setCompressionSettingOnStamper(inputCommand, pdfStamper);
        pdfStamper.setMoreInfo(meta);
       
        //fullscreen
        if(inputCommand.isFullScreen()){
          pdfStamper.setViewerPreferences(PdfWriter.PageModeFullScreen);
        }
       
        //sets transitions
        if(transitions.getDefaultTransition()==null){
          setTransitionsWithoutDefault(transitions);       
        }else{
          int totalPages = pdfReader.getNumberOfPages();
          setTransitionsWithDefault(transitions, totalPages);
        }
       
        pdfStamper.close();
        pdfReader.close();
       
        File outFile = new File(inputCommand.getOutputFile() ,prefixParser.generateFileName());
          FileUtility.renameTemporaryFile(tmpFile, outFile, inputCommand.isOverwrite());
          LOG.debug("File "+outFile.getCanonicalPath()+" created.");
          LOG.info("Slide show options set.");
      }catch(Exception e){       
        throw new SlideShowException(e);
View Full Code Here

   
    if((parsedCommand != null) && (parsedCommand instanceof DecryptParsedCommand)){
     
      DecryptParsedCommand inputCommand = (DecryptParsedCommand) parsedCommand;
      setPercentageOfWorkDone(0);
      PrefixParser prefixParser;
      try{
        PdfFile[] fileList = inputCommand.getInputFileList();
        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.close();
            pdfReader.close();
            File outFile = new File(inputCommand.getOutputFile() ,prefixParser.generateFileName());
              FileUtility.renameTemporaryFile(tmpFile, outFile, inputCommand.isOverwrite());
                    LOG.debug("Decrypted file "+outFile.getCanonicalPath()+" created.");             
              setPercentageOfWorkDone(((i+1)*WorkDoneDataModel.MAX_PERGENTAGE)/fileList.length)
            }
            catch(Exception e){
View Full Code Here

        if ((parsedCommand != null) && (parsedCommand instanceof RotateParsedCommand)) {

            RotateParsedCommand inputCommand = (RotateParsedCommand) parsedCommand;
            setPercentageOfWorkDone(0);
            PrefixParser prefixParser;

            try {
                PdfFile[] fileList = inputCommand.getInputFileList();
                for (int i = 0; i < fileList.length; i++) {
                    try {

                        prefixParser = new PrefixParser(inputCommand.getOutputFilesPrefix(), fileList[i].getFile()
                                .getName());
                        File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
                        LOG.debug("Opening " + fileList[i].getFile().getAbsolutePath());
                        pdfReader = new PdfReader(new FileInputStream(fileList[i].getFile().getAbsolutePath()),
                                fileList[i].getPasswordBytes());
                        pdfReader.removeUnusedObjects();
                        pdfReader.consolidateNamedDestinations();

                        int pdfNumberOfPages = pdfReader.getNumberOfPages();
                        PageRotation rotation = inputCommand.getRotation();
                        // rotate all
                        if (rotation.getType() == PageRotation.ALL_PAGES) {
                            int pageRotation = rotation.getDegrees();
                            LOG.debug("Applying rotation of " + pageRotation + " for all pages");
                            for (int j = 1; j <= pdfNumberOfPages; j++) {
                                PdfDictionary dictionary = pdfReader.getPageN(j);
                                int rotationDegrees = (pageRotation + pdfReader.getPageRotation(j)) % 360;
                                dictionary.put(PdfName.ROTATE, new PdfNumber(rotationDegrees));
                            }
                        } else if (rotation.getType() == PageRotation.ODD_PAGES) {
                            // odd pages rotation
                            int pageRotation = rotation.getDegrees();
                            LOG.debug("Applying rotation of " + pageRotation + " for odd pages");
                            for (int j = 1; j <= pdfNumberOfPages; j = j + 2) {
                                PdfDictionary dictionary = pdfReader.getPageN(j);
                                int rotationDegrees = (pageRotation + pdfReader.getPageRotation(j)) % 360;
                                dictionary.put(PdfName.ROTATE, new PdfNumber(rotationDegrees));
                            }
                        } else if (rotation.getType() == PageRotation.EVEN_PAGES) {
                            // even pages rotation
                            int pageRotation = rotation.getDegrees();
                            LOG.debug("Applying rotation of " + pageRotation + " for even pages");
                            for (int j = 2; j <= pdfNumberOfPages; j = j + 2) {
                                PdfDictionary dictionary = pdfReader.getPageN(j);
                                int rotationDegrees = (pageRotation + pdfReader.getPageRotation(j)) % 360;
                                dictionary.put(PdfName.ROTATE, new PdfNumber(rotationDegrees));
                            }
                        } else {
                            LOG.warn("Unable to find the rotation type. " + rotation);
                        }

                        // 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.close();
                        pdfReader.close();
                        File outFile = new File(inputCommand.getOutputFile(), prefixParser.generateFileName());
                        FileUtility.renameTemporaryFile(tmpFile, outFile, inputCommand.isOverwrite());
                        LOG.debug("Rotated file " + outFile.getCanonicalPath() + " created.");
                        setPercentageOfWorkDone(((i + 1) * WorkDoneDataModel.MAX_PERGENTAGE) / fileList.length);
                    } catch (Exception e) {
                        LOG.error("Error rotating file " + fileList[i].getFile().getName(), e);
View Full Code Here

        if ((parsedCommand != null) && (parsedCommand instanceof SplitParsedCommand)) {
            SplitParsedCommand inputCommand = (SplitParsedCommand) parsedCommand;
            setPercentageOfWorkDone(0);
            try {
                prefixParser = new PrefixParser(inputCommand.getOutputFilesPrefix(), inputCommand.getInputFile()
                        .getFile().getName());
                if (SplitParsedCommand.S_BURST.equals(inputCommand.getSplitType())) {
                    executeBurst(inputCommand);
                } else if (SplitParsedCommand.S_NSPLIT.equals(inputCommand.getSplitType())) {
                    executeNSplit(inputCommand);
View Full Code Here

TOP

Related Classes of org.pdfsam.console.utils.perfix.PrefixParser

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.