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();