You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2022/02/12 17:06:44 UTC
svn commit: r1898014 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
Author: tilman
Date: Sat Feb 12 17:06:44 2022
New Revision: 1898014
URL: http://svn.apache.org/viewvc?rev=1898014&view=rev
Log:
PDFBOX-4892: optimize, as suggested by valerybokov
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1898014&r1=1898013&r2=1898014&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Sat Feb 12 17:06:44 2022
@@ -339,14 +339,15 @@ public class PDDocument implements Close
// Create SignatureForm for signature and append it to the document
// Get the first valid page
- int pageCount = getNumberOfPages();
+ PDPageTree pageTree = getPages();
+ int pageCount = pageTree.getCount();
if (pageCount == 0)
{
throw new IllegalStateException("Cannot sign an empty document");
}
int startIndex = Math.min(Math.max(options.getPage(), 0), pageCount - 1);
- PDPage page = getPage(startIndex);
+ PDPage page = pageTree.get(startIndex);
// Get the AcroForm from the Root-Dictionary and append the annotation
PDDocumentCatalog catalog = getDocumentCatalog();
@@ -572,12 +573,12 @@ public class PDDocument implements Close
private void assignSignatureRectangle(PDSignatureField signatureField, COSDictionary annotDict)
{
// Read and set the rectangle for visual signature
- COSArray rectArray = annotDict.getCOSArray(COSName.RECT);
PDRectangle existingRectangle = signatureField.getWidgets().get(0).getRectangle();
//in case of an existing field keep the original rect
if (existingRectangle == null || existingRectangle.getCOSArray().size() != 4)
{
+ COSArray rectArray = annotDict.getCOSArray(COSName.RECT);
PDRectangle rect = new PDRectangle(rectArray);
signatureField.getWidgets().get(0).setRectangle(rect);
}