pdf/src/main/java/se/idsec/signservice/integration/document/pdf/signpage/DefaultPdfSignaturePagePreparator.java
private Pair<PDDocument, Integer> addSignaturePage(final PDDocument document, final PdfSignaturePage signPage, Integer insertPageAt)
      throws SignServiceIntegrationException {

    final PDDocument signPageDocument = PDDocumentUtils.load(signPage.getContents());
    try {
      int noPages = document.getNumberOfPages();
      int newPagePos = (insertPageAt == null || insertPageAt == 0) ? noPages + 1 : insertPageAt;

      PDDocument updatedDocument = PDDocumentUtils.insertDocument(document, signPageDocument, newPagePos);

      if (signPage.getImagePlacementConfiguration().getPage() == null || signPage.getImagePlacementConfiguration().getPage() == 1) {
        return new Pair<>(updatedDocument, newPagePos);
      }
      else if (signPage.getImagePlacementConfiguration().getPage() == 0) {
        return new Pair<>(updatedDocument, newPagePos + signPageDocument.getNumberOfPages() - 1);
      }
      else {
        return new Pair<>(updatedDocument, newPagePos + signPage.getImagePlacementConfiguration().getPage() - 1);
      }
    }
    finally {
      PDDocumentUtils.close(signPageDocument);
    }
  }
/**
   * Adds a signature page document according to the {@code insertPageAt} parameter.
   * 
   * @param document
   *          the document to update
   * @param signPage
   *          the sign page to add
   * @param insertPageAt
   *          the (one-based) directive where the sign page should be inserted
   * @return a Pair of the updated document and the (one-based) page number where the sign page is located in the
   *         updated document
   * @throws SignServiceIntegrationException
   *           for processing errors
   */
Adds a signature page document according to the  insertPageAt parameter.


Adds a signature page document according to the insertPageAt parameter .
private Pair<PDDocument, Integer> addSignaturePage(final PDDocument document, final PdfSignaturePage signPage, Integer insertPageAt)
      throws SignServiceIntegrationException {
    final PDDocument signPageDocument = PDDocumentUtils.load(signPage.getContents());
    try {
      int noPages = document.getNumberOfPages();
      int newPagePos = (insertPageAt == null || insertPageAt == 0) ? noPages + 1 : insertPageAt;
      PDDocument updatedDocument = PDDocumentUtils.insertDocument(document, signPageDocument, newPagePos);
      if (signPage.getImagePlacementConfiguration().getPage() == null || signPage.getImagePlacementConfiguration().getPage() == 1) {
        return new Pair<>(updatedDocument, newPagePos);
      }
      else if (signPage.getImagePlacementConfiguration().getPage() == 0) {
        return new Pair<>(updatedDocument, newPagePos + signPageDocument.getNumberOfPages() - 1);
      }
      else {
        return new Pair<>(updatedDocument, newPagePos + signPage.getImagePlacementConfiguration().getPage() - 1);
      }
    }
    finally {
      PDDocumentUtils.close(signPageDocument);
    }
  }
private Pair < PDDocument , Integer > addSignaturePage ( final PDDocument document , final PdfSignaturePage signPage , Integer insertPageAt ) throws SignServiceIntegrationException { final PDDocument signPageDocument = PDDocumentUtils . load ( signPage . getContents ( ) ) ; try { int noPages = document . getNumberOfPages ( ) ; int newPagePos = ( insertPageAt == null || insertPageAt == 0 ) ? noPages + 1 : insertPageAt ; PDDocument updatedDocument = PDDocumentUtils . insertDocument ( document , signPageDocument , newPagePos ) ; if ( signPage . getImagePlacementConfiguration ( ) . getPage ( ) == null || signPage . getImagePlacementConfiguration ( ) . getPage ( ) == 1 ) { return new Pair < > ( updatedDocument , newPagePos ) ; } else if ( signPage . getImagePlacementConfiguration ( ) . getPage ( ) == 0 ) { return new Pair < > ( updatedDocument , newPagePos + signPageDocument . getNumberOfPages ( ) - 1 ) ; } else { return new Pair < > ( updatedDocument , newPagePos + signPage . getImagePlacementConfiguration ( ) . getPage ( ) - 1 ) ; } } finally { PDDocumentUtils . close ( signPageDocument ) ; } }
Adds a signature page document according to the {@code insertPageAt} parameter.
Adds a signature page document according to the { @code insertPageAt } parameter .