public void execute(SetMetadataParameters parameters) throws TaskException { notifyEvent(getNotifiableTaskMetadata()).progressUndetermined(); PdfSource<?> source = parameters.getSource(); LOG.debug("Opening {} ", source); reader = source.open(sourceOpener); File tmpFile = createTemporaryPdfBuffer(); LOG.debug("Created output temporary buffer {} ", tmpFile); stamperHandler = new PdfStamperHandler(reader, tmpFile, parameters.getVersion()); stamperHandler.setCompressionOnStamper(parameters.isCompress()); LOG.debug("Setting metadata on temporary document."); @SuppressWarnings("unchecked") HashMap<String, String> actualMeta = reader.getInfo(); for (Entry<PdfMetadataKey, String> meta : parameters.entrySet()) { LOG.trace("'{}' -> '{}'", meta.getKey().getKey(), meta.getValue()); actualMeta.put(meta.getKey().getKey(), meta.getValue()); } stamperHandler.setMetadataOnStamper(actualMeta); nullSafeClosePdfReader(reader); nullSafeCloseQuietly(stamperHandler); outputWriter.setOutput(file(tmpFile).name(parameters.getOutputName())); parameters.getOutput().accept(outputWriter); LOG.debug("Metadata set on {}", parameters.getOutput()); }
@Override public void execute(SetMetadataParameters parameters) throws TaskException { executionContext().assertTaskNotCancelled(); notifyEvent(executionContext().notifiableTaskMetadata()).progressUndetermined(); PdfSource<?> source = parameters.getSource(); LOG.debug("Opening {}", source); documentHandler = source.open(documentLoader); documentHandler.setCreatorOnPDDocument(); File tmpFile = createTemporaryBuffer(parameters.getOutput()); outputWriter.taskOutput(tmpFile); LOG.debug("Temporary output set to {}", tmpFile); LOG.debug("Setting metadata on temporary document."); PDDocumentInformation actualMeta = documentHandler.getUnderlyingPDDocument().getDocumentInformation(); for (Entry<PdfMetadataKey, String> meta : parameters.entrySet()) { LOG.trace("'{}' -> '{}'", meta.getKey().getKey(), meta.getValue()); actualMeta.setCustomMetadataValue(meta.getKey().getKey(), meta.getValue()); } documentHandler.setVersionOnPDDocument(parameters.getVersion()); documentHandler.setCompress(parameters.isCompress()); documentHandler.savePDDocument(tmpFile); nullSafeCloseQuietly(documentHandler); parameters.getOutput().accept(outputWriter); LOG.debug("Metadata set on {}", parameters.getOutput()); }
@Override public void execute(SetMetadataParameters parameters) throws TaskException { executionContext().assertTaskNotCancelled(); notifyEvent(executionContext().notifiableTaskMetadata()).progressUndetermined(); PdfSource<?> source = parameters.getSource(); LOG.debug("Opening {}", source); documentHandler = source.open(documentLoader); documentHandler.setCreatorOnPDDocument(); File tmpFile = createTemporaryBuffer(parameters.getOutput()); outputWriter.taskOutput(tmpFile); LOG.debug("Temporary output set to {}", tmpFile); LOG.debug("Setting metadata on temporary document."); PDDocumentInformation actualMeta = documentHandler.getUnderlyingPDDocument().getDocumentInformation(); for (Entry<PdfMetadataKey, String> meta : parameters.entrySet()) { LOG.trace("'{}' -> '{}'", meta.getKey().getKey(), meta.getValue()); actualMeta.setCustomMetadataValue(meta.getKey().getKey(), meta.getValue()); } documentHandler.setVersionOnPDDocument(parameters.getVersion()); documentHandler.setCompress(parameters.isCompress()); documentHandler.savePDDocument(tmpFile); nullSafeCloseQuietly(documentHandler); parameters.getOutput().accept(outputWriter); LOG.debug("Metadata set on {}", parameters.getOutput()); }