Package org.pdfsam.console.business.dto.commands

Examples of org.pdfsam.console.business.dto.commands.DocumentInfoParsedCommand


  private PdfReader pdfReader = null;
  private PdfStamper pdfStamper = null;

  public void execute(AbstractParsedCommand parsedCommand) throws ConsoleException {
    if ((parsedCommand != null) && (parsedCommand instanceof DocumentInfoParsedCommand)) {
      DocumentInfoParsedCommand inputCommand = (DocumentInfoParsedCommand) parsedCommand;
      setPercentageOfWorkDone(0);
      try {
        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());
        }

        HashMap meta = pdfReader.getInfo();
        meta.put("Creator", ConsoleServicesFacade.CREATOR);
        if (inputCommand.getAuthor() != null) {
          meta.put(AUTHOR, inputCommand.getAuthor());
        }
        if (inputCommand.getSubject() != null) {
          meta.put(SUBJECT, inputCommand.getSubject());
        }
        if (inputCommand.getTitle() != null) {
          meta.put(TITLE, inputCommand.getTitle());
        }
        if (inputCommand.getKeywords() != null) {
          meta.put(KEYWORDS, inputCommand.getKeywords());
        }

        setCompressionSettingOnStamper(inputCommand, pdfStamper);

        pdfStamper.setMoreInfo(meta);
        pdfStamper.close();
        pdfReader.close();

        FileUtility.renameTemporaryFile(tmpFile, inputCommand.getOutputFile(), inputCommand.isOverwrite());
        LOG.debug("File " + inputCommand.getOutputFile().getCanonicalPath() + " created.");

      } catch (Exception e) {
        throw new ConsoleException(e);
      } finally {
        setWorkCompleted();
View Full Code Here


*/
public class DocumentInfoCmdValidator extends AbstractCmdValidator {

  protected AbstractParsedCommand validateArguments(CmdLineHandler cmdLineHandler) throws ConsoleException {

    DocumentInfoParsedCommand parsedCommandDTO = new DocumentInfoParsedCommand();

    if (cmdLineHandler != null) {
      // -o
      FileParam oOption = (FileParam) cmdLineHandler.getOption(DocumentInfoParsedCommand.O_ARG);
      if ((oOption.isSet())) {
        File outFile = oOption.getFile();
        // checking extension
        ValidationUtility.assertValidPdfExtension(outFile.getName());
        parsedCommandDTO.setOutputFile(outFile);

      } else {
        throw new ParseException(ParseException.ERR_NO_O);
      }
     
      //-f
          PdfFileParam fOption = (PdfFileParam) cmdLineHandler.getOption(DocumentInfoParsedCommand.F_ARG);          
          if(fOption.isSet()){
            PdfFile inputFile = fOption.getPdfFile();
            ValidationUtility.assertValidPdfExtension(inputFile.getFile().getName());
              parsedCommandDTO.setInputFile(FileUtility.getPdfFile(inputFile));                 
          }else{
            throw new ParseException(ParseException.ERR_NO_F)
          }
         
          //-author
          StringParam authorOption = (StringParam) cmdLineHandler.getOption(DocumentInfoParsedCommand.AUTHOR_ARG);
          if(authorOption.isSet()){
            parsedCommandDTO.setAuthor(authorOption.getValue());        
          }
         
          //-title
          StringParam titleOption = (StringParam) cmdLineHandler.getOption(DocumentInfoParsedCommand.TITLE_ARG);
          if(titleOption.isSet()){
            parsedCommandDTO.setTitle(titleOption.getValue());        
          }
         
          //-subject
          StringParam subjectOption = (StringParam) cmdLineHandler.getOption(DocumentInfoParsedCommand.SUBJECT_ARG);
          if(subjectOption.isSet()){
            parsedCommandDTO.setSubject(subjectOption.getValue());        
          }
         
          //-keywords
          StringParam keywordsOption = (StringParam) cmdLineHandler.getOption(DocumentInfoParsedCommand.KEYWORDS_ARG);
          if(keywordsOption.isSet()){
            parsedCommandDTO.setKeywords(keywordsOption.getValue());        
          }
         
    } else {
      throw new ConsoleException(ConsoleException.CMD_LINE_HANDLER_NULL);
    }
View Full Code Here

TOP

Related Classes of org.pdfsam.console.business.dto.commands.DocumentInfoParsedCommand

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.