Пример #1
0
 @Override
 public void before(EncryptParameters parameters) {
   totalSteps = parameters.getSourceList().size();
   sourceOpener = PdfSourceOpeners.newPartialReadOpener();
   outputWriter = OutputWriters.newMultipleOutputWriter(parameters.isOverwrite());
   for (PdfAccessPermission permission : parameters.getPermissions()) {
     permissions |= getAccessPermission(permission);
   }
 }
Пример #2
0
  @Override
  public void execute(EncryptParameters parameters) throws TaskException {
    int currentStep = 0;
    for (PdfSource<?> source : parameters.getSourceList()) {
      currentStep++;
      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());
      stamperHandler.setCreatorOnStamper(reader);
      stamperHandler.setEncryptionOnStamper(
          getEncryptionAlgorithm(parameters.getEncryptionAlgorithm()),
          parameters.getUserPassword(),
          parameters.getOwnerPassword(),
          permissions);

      nullSafeClosePdfReader(reader);
      nullSafeCloseQuietly(stamperHandler);

      String outName =
          nameGenerator(parameters.getOutputPrefix())
              .generate(nameRequest().originalName(source.getName()).fileNumber(currentStep));
      outputWriter.addOutput(file(tmpFile).name(outName));

      notifyEvent(getNotifiableTaskMetadata()).stepsCompleted(currentStep).outOf(totalSteps);
    }

    parameters.getOutput().accept(outputWriter);
    LOG.debug("Input documents encrypted and written to {}", parameters.getOutput());
    LOG.debug("Permissions {}", PdfEncryptor.getPermissionsVerbose(permissions));
  }