Exemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  protected int output(final OutputStream stream) throws IOException {
    final CountingOutputStream cout = new CountingOutputStream(stream);
    final Writer writer = PDFDocument.getWriterFor(cout);
    if (hasObjectNumber()) {
      writer.write(getObjectID());
    }

    writer.write(toString());

    if (hasObjectNumber()) {
      writer.write("\nendobj\n");
    }

    writer.flush();
    return cout.getCount();
  }
Exemplo n.º 2
0
 /**
  * Sets up PDF encryption if PDF encryption is requested by registering a <code>
  * PDFEncryptionParams</code> object with the user agent and if the necessary cryptographic
  * support is available.
  *
  * @param params the PDF encryption params or null to disable encryption
  * @param pdf the PDF document to setup encryption for
  */
 public static void setupPDFEncryption(PDFEncryptionParams params, PDFDocument pdf) {
   if (pdf == null) {
     throw new NullPointerException("PDF document must not be null");
   }
   if (params != null) {
     if (!checkAvailableAlgorithms()) {
       if (isJCEAvailable()) {
         log.warn(
             "PDF encryption has been requested, JCE is "
                 + "available but there's no "
                 + "JCE provider available that provides the "
                 + "necessary algorithms. The PDF won't be "
                 + "encrypted.");
       } else {
         log.warn(
             "PDF encryption has been requested but JCE is "
                 + "unavailable! The PDF won't be encrypted.");
       }
     }
     pdf.setEncryption(params);
   }
 }