aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/placeholder/SignaturePlaceholderExtractor.java
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas/placeholder/SignaturePlaceholderExtractor.java')
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/placeholder/SignaturePlaceholderExtractor.java37
1 files changed, 18 insertions, 19 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/placeholder/SignaturePlaceholderExtractor.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/placeholder/SignaturePlaceholderExtractor.java
index 8b8c22e..453b620 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/placeholder/SignaturePlaceholderExtractor.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/placeholder/SignaturePlaceholderExtractor.java
@@ -71,7 +71,7 @@ import com.google.zxing.common.HybridBinarizer;
/**
* Extract all relevant information from a placeholder image.
- *
+ *
* @author exthex
*
*/
@@ -80,10 +80,10 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine {
* The log.
*/
private static Log log = LogFactory.getLog(SignaturePlaceholderExtractor.class);
-
+
private List placeholders = new Vector();
private int currentPage = 0;
-
+
private SignaturePlaceholderExtractor(String placeholderId, int placeholderMatchMode) throws IOException {
super(ResourceLoader.loadProperties("at/gv/egiz/pdfas/placeholder/pdfbox-reader.properties",
true));
@@ -93,7 +93,7 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine {
* Search the document for placeholder images and possibly included
* additional info.<br/>
* Searches only for the first placeholder page after page from top.
- *
+ *
* @param inputStream
* @return all available info from the first found placeholder.
* @throws PDFDocumentException if the document could not be read.
@@ -103,14 +103,13 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine {
throws PDFDocumentException, PlaceholderExtractionException {
SignaturePlaceholderContext.setSignaturePlaceholderData(null);
PDDocument doc = null;
- try
+ try
{
try {
doc = PDDocument.load(inputStream);
} catch (IOException e) {
throw new PDFDocumentException(ErrorCode.DOCUMENT_CANNOT_BE_READ, e);
}
- PDFASUtils.checkDocumentPermissions(doc);
SignaturePlaceholderExtractor extractor;
try
{
@@ -135,7 +134,7 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine {
} catch (IOException e1) {
throw new PDFDocumentException(ErrorCode.DOCUMENT_CANNOT_BE_READ, e1);
}
-
+
}
if (extractor.placeholders.size() > 0){
SignaturePlaceholderData ret = matchPlaceholderDocument(extractor.placeholders, placeholderId, matchMode);
@@ -146,7 +145,7 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine {
if (matchMode == Constants.PLACEHOLDER_MATCH_MODE_STRICT) {
throw new PlaceholderExtractionException(ErrorCode.SIGNATURE_PLACEHOLDER_EXTRACTION_FAILED, "no suitable placeholder found and STRICT matching mode requested.");
}
-
+
return null;
} finally {
if (doc != null)
@@ -158,23 +157,23 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine {
}
}
-
+
private static SignaturePlaceholderData matchPlaceholderDocument(
List placeholders, String placeholderId, int matchMode) throws PlaceholderExtractionException {
-
+
if (matchMode == Constants.PLACEHOLDER_MATCH_MODE_STRICT)
throw new PlaceholderExtractionException(ErrorCode.SIGNATURE_PLACEHOLDER_EXTRACTION_FAILED, "no suitable placeholder found and STRICT matching mode requested.");
-
+
if (placeholders.size() == 0)
return null;
-
+
for (int i = 0; i < placeholders.size(); i++)
{
SignaturePlaceholderData spd = (SignaturePlaceholderData)placeholders.get(i);
if (spd.getId() == null)
return spd;
}
-
+
if (matchMode == Constants.PLACEHOLDER_MATCH_MODE_LENIENT)
return (SignaturePlaceholderData)placeholders.get(0);
@@ -219,7 +218,7 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine {
PDPage page = getCurrentPage();
Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
double rotationInRadians = (page.findRotation() * Math.PI)/180;
-
+
AffineTransform rotation = new AffineTransform();
rotation.setToRotation( rotationInRadians );
AffineTransform rotationInverse = rotation.createInverse();
@@ -227,13 +226,13 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine {
rotationInverseMatrix.setFromAffineTransform( rotationInverse );
Matrix rotationMatrix = new Matrix();
rotationMatrix.setFromAffineTransform( rotation );
-
+
Matrix unrotatedCTM = ctm.multiply( rotationInverseMatrix );
-
+
float x = unrotatedCTM.getXPosition();
float y = unrotatedCTM.getYPosition() + unrotatedCTM.getYScale();
float w = unrotatedCTM.getXScale();
-
+
String posString = "p:" + currentPage + ";x:" + x + ";y:" + y + ";w:" + w;
try
{
@@ -259,7 +258,7 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine {
/**
* Checks an image if it is a placeholder for a signature.
- *
+ *
* @param image
* @return
* @throws IOException
@@ -291,7 +290,7 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine {
formats.add(BarcodeFormat.QR_CODE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
result = new MultiFormatReader().decode(bitmap, hints);
-
+
String text = result.getText();
String profile = null;
String type = null;