diff options
Diffstat (limited to 'src/main/java/at/gv')
-rw-r--r-- | src/main/java/at/gv/egiz/pdfas/impl/vfilter/VerificationFilterImpl.java | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/vfilter/VerificationFilterImpl.java b/src/main/java/at/gv/egiz/pdfas/impl/vfilter/VerificationFilterImpl.java index acf6622..47f217a 100644 --- a/src/main/java/at/gv/egiz/pdfas/impl/vfilter/VerificationFilterImpl.java +++ b/src/main/java/at/gv/egiz/pdfas/impl/vfilter/VerificationFilterImpl.java @@ -504,14 +504,18 @@ public class VerificationFilterImpl implements VerificationFilter return blockPartitions;
}
- protected String extractText(PdfDataSource pdf, int endOfDocument) throws PresentableException
+ protected String extractText(PdfDataSource pdf, int endOfDocument) throws PresentableException {
+ return extractText(pdf, endOfDocument, "utf8");
+ }
+ protected String extractText(PdfDataSource pdf, int endOfDocument, String encoding) throws PresentableException
{
+
log.debug("EXTRACTING TEXT... end index = " + endOfDocument);
DelimitedPdfDataSource dds = new DelimitedPdfDataSource(pdf, endOfDocument);
//DelimitedInputStream dis = new DelimitedInputStream(pdf.createInputStream(), endOfDocument);
- return PdfAS.extractNormalizedTextTextual(dds);
+ return PdfAS.extractNormalizedTextTextual(dds, encoding);
}
@@ -714,6 +718,42 @@ public class VerificationFilterImpl implements VerificationFilter log.debug("Extracting signatures finished.");
log.debug("Number of found signatures: " + extractedSignatures.size());
+ if (extractedSignatures.size() > 0) {
+ List cp1252SignaturesPositions = new ArrayList();
+ //boolean iscp1252Sig = false;
+ for (int i = 0; i < extractedSignatures.size(); i++) {
+ SignatureHolder sh = (SignatureHolder)extractedSignatures.get(i);
+ PdfASID kzid = sh.getSignatureObject().getKZ();
+ if (kzid != null && kzid.isOldCp1252Version()) {
+ log.debug("found cp1252 signature");
+ cp1252SignaturesPositions.add(new Integer(i));
+ //iscp1252Sig = true;
+ //break;
+ }
+ }
+ if (cp1252SignaturesPositions.size() > 0) {
+ log.debug("redo text and signature extraction with cp1252 encoding");
+ extractedText = extractText(pdf, endOfDocument, "cp1252");
+ log.debug("Extracting text finished.");
+
+ log.debug("Extracting signatures:");
+ List cp1252ExtractedSignatures = extractNewSignaturesFromText(extractedText);
+ log.debug("Extracting signatures finished.");
+ log.debug("Number of found signatures: " + extractedSignatures.size());
+
+ if (cp1252ExtractedSignatures.size() != extractedSignatures.size()) {
+ log.error("Invalid cp1252 signatures found. Skipping cp1252 compatibility.");
+ }
+ // merge signature holders
+ for (int i = 0; i < cp1252SignaturesPositions.size(); i++) {
+ int replaceIndex = ((Integer)cp1252SignaturesPositions.get(i)).intValue();
+ extractedSignatures.remove(replaceIndex);
+ extractedSignatures.add(replaceIndex, cp1252ExtractedSignatures.get(replaceIndex));
+ }
+ }
+
+ }
+
if (log.isDebugEnabled())
{
log.debug("extracted signatures:");
@@ -788,7 +828,7 @@ public class VerificationFilterImpl implements VerificationFilter DelimitedPdfDataSource dds = new DelimitedPdfDataSource(pdf, pdf.getLength());
String text = null;
try {
- text = PdfAS.extractNormalizedTextTextual(dds);
+ text = PdfAS.extractNormalizedTextTextual(dds, "utf-8");
} catch (PresentableException e) {
throw new VerificationFilterException(e);
}
|