List of usage examples for com.itextpdf.text.pdf PdfDictionary contains
public boolean contains(final PdfName key)
true
if this PdfDictionary
contains a mapping for the specified key. From source file:io.konik.carriage.itext.ITextInvoiceExtractor.java
License:Open Source License
private static PdfArray getValidAf(PdfDictionary catalog) { if (catalog.contains(AF)) { PdfArray af = catalog.getAsArray(AF); if (!af.isEmpty() && af.getDirectObject(0).isDictionary()) { return af; }/*ww w . j a v a2s. c om*/ } throw new InvoiceExtractionError("Pdf catalog does not contain Valid AF Entry"); }
From source file:io.konik.carriage.itext.ITextInvoiceExtractor.java
License:Open Source License
private static PdfDictionary getValidEf(PdfDictionary fileSpec) { if (fileSpec.contains(EF)) { return fileSpec.getAsDict(EF); }//from w w w.java 2 s. c o m throw new InvoiceExtractionError("Pdf catalog does not contain Valid EF Entry"); }
From source file:io.konik.carriage.itext.ITextInvoiceExtractor.java
License:Open Source License
private static byte[] getFStream(PdfDictionary ef) { if (ef.contains(F)) { PdfStream xmlStream = ef.getAsStream(F); try {//from ww w. ja v a 2s. co m return getStreamBytes((PRStream) xmlStream); } catch (IOException e) { throw new InvoiceExtractionError("Could not extrac xml content form pdf.", e); } } throw new InvoiceExtractionError("Pdf catalog does not contain Valid F Entry"); }
From source file:mkl.testarea.itext5.pdfcleanup.StrictPdfCleanUpProcessor.java
License:Open Source License
/** * Extracts locations from the redact annotations contained in the document and applied to the given page. *//*from w w w . jav a2 s . c o m*/ private List<PdfCleanUpLocation> extractLocationsFromRedactAnnots(int page, PdfDictionary pageDict) { List<PdfCleanUpLocation> locations = new ArrayList<PdfCleanUpLocation>(); if (pageDict.contains(PdfName.ANNOTS)) { PdfArray annotsArray = pageDict.getAsArray(PdfName.ANNOTS); for (int i = 0; i < annotsArray.size(); ++i) { PdfIndirectReference annotIndirRef = annotsArray.getAsIndirectObject(i); PdfDictionary annotDict = annotsArray.getAsDict(i); PdfName annotSubtype = annotDict.getAsName(PdfName.SUBTYPE); if (annotSubtype.equals(PdfName.REDACT)) { saveRedactAnnotIndirRef(page, annotIndirRef.toString()); locations.addAll(extractLocationsFromRedactAnnot(page, i, annotDict)); } } } return locations; }
From source file:org.roda.common.certification.PDFSignatureUtils.java
private static StringBuilder getExtractionInformation(AcroFields fields, ArrayList<?> names, Path outputContents, String filename) throws IOException { StringBuilder sb = new StringBuilder(); for (int i = 0; i < names.size(); i++) { String name = (String) names.get(i); Item item = fields.getFieldItem(name); PdfDictionary widget = item.getWidget(0); PdfDictionary infoDictionary = widget.getAsDict(PdfName.V); sb.append("<signature>\n"); try {/*from w w w.j av a 2 s . c o m*/ PdfPKCS7 pk = fields.verifySignature(name); sb = addElementToExtractionResult(sb, "name", name); sb = addElementToExtractionResult(sb, "sign-name", pk.getSignName()); sb = addElementToExtractionResult(sb, "version", Integer.toString(pk.getVersion())); sb = addElementToExtractionResult(sb, "reason", pk.getReason()); sb = addElementToExtractionResult(sb, "location", pk.getLocation()); SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); if (pk.getTimeStampDate() != null) { String timestamp = formatter.format(pk.getTimeStampDate().getTime()); sb = addElementToExtractionResult(sb, "timestamp-time", timestamp); } if (pk.getSignDate() != null) { String sign = formatter.format(pk.getSignDate().getTime()); sb = addElementToExtractionResult(sb, "sign-time", sign); } sb = addElementToExtractionResult(sb, "digest-algorithm", pk.getDigestAlgorithm()); sb = addElementToExtractionResult(sb, "hash-algorithm", pk.getHashAlgorithm()); sb = addElementToExtractionResult(sb, "covers-whole-document", Boolean.toString(fields.signatureCoversWholeDocument(name))); sb = addElementToExtractionResult(sb, "ft", widget.get(PdfName.FT).toString()); if (infoDictionary.contains(PdfName.CONTACTINFO)) sb = addElementToExtractionResult(sb, "contact-info", infoDictionary.getAsString(PdfName.CONTACTINFO).toString()); if (infoDictionary.contains(PdfName.FILTER)) sb = addElementToExtractionResult(sb, "filter", infoDictionary.get(PdfName.FILTER).toString()); if (infoDictionary.contains(PdfName.SUBFILTER)) sb = addElementToExtractionResult(sb, "subfilter", infoDictionary.get(PdfName.SUBFILTER).toString()); if (infoDictionary.contains(PdfName.LOCK)) sb = addElementToExtractionResult(sb, "lock", "true"); if (infoDictionary.contains(PdfName.CONTENTS)) { PdfString elementName = infoDictionary.getAsString(PdfName.CONTENTS); Files.write(outputContents, elementName.toUnicodeString().getBytes()); sb = addElementToExtractionResult(sb, "contents", filename + ".pkcs7"); } } catch (NoSuchFieldError e) { LOGGER.warn("DS information extraction did not execute properly"); } sb.append("</signature>"); } return sb; }
From source file:org.roda.core.plugins.plugins.characterization.PDFSignatureUtils.java
private static StringBuilder getExtractionInformation(AcroFields fields, ArrayList<?> names, Path outputContents, String filename) throws IOException { StringBuilder sb = new StringBuilder(); for (int i = 0; i < names.size(); i++) { String name = (String) names.get(i); Item item = fields.getFieldItem(name); PdfDictionary widget = item.getWidget(0); PdfDictionary infoDictionary = widget.getAsDict(PdfName.V); sb.append("<signature>\n"); try {// w ww .j a v a 2 s . c o m PdfPKCS7 pk = fields.verifySignature(name); sb = addElementToExtractionResult(sb, "name", name); sb = addElementToExtractionResult(sb, "sign-name", pk.getSignName()); sb = addElementToExtractionResult(sb, "version", Integer.toString(pk.getVersion())); sb = addElementToExtractionResult(sb, "reason", pk.getReason()); sb = addElementToExtractionResult(sb, "location", pk.getLocation()); SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); if (pk.getTimeStampDate() != null) { String timestamp = formatter.format(pk.getTimeStampDate().getTime()); sb = addElementToExtractionResult(sb, "timestamp-time", timestamp); } if (pk.getSignDate() != null) { String sign = formatter.format(pk.getSignDate().getTime()); sb = addElementToExtractionResult(sb, "sign-time", sign); } sb = addElementToExtractionResult(sb, "digest-algorithm", pk.getDigestAlgorithm()); sb = addElementToExtractionResult(sb, "hash-algorithm", pk.getHashAlgorithm()); sb = addElementToExtractionResult(sb, "covers-whole-document", Boolean.toString(fields.signatureCoversWholeDocument(name))); sb = addElementToExtractionResult(sb, "ft", widget.get(PdfName.FT).toString()); if (infoDictionary.contains(PdfName.CONTACTINFO)) sb = addElementToExtractionResult(sb, "contact-info", infoDictionary.getAsString(PdfName.CONTACTINFO).toString()); if (infoDictionary.contains(PdfName.FILTER)) sb = addElementToExtractionResult(sb, "filter", infoDictionary.get(PdfName.FILTER).toString()); if (infoDictionary.contains(PdfName.SUBFILTER)) sb = addElementToExtractionResult(sb, "subfilter", infoDictionary.get(PdfName.SUBFILTER).toString()); if (infoDictionary.contains(PdfName.LOCK)) sb = addElementToExtractionResult(sb, "lock", "true"); if (infoDictionary.contains(PdfName.CONTENTS)) { PdfString elementName = infoDictionary.getAsString(PdfName.CONTENTS); Files.write(outputContents, elementName.toUnicodeString().getBytes()); sb = addElementToExtractionResult(sb, "contents", filename + ".pkcs7"); } } catch (NoSuchFieldError e) { LOGGER.warn("DS information extraction did not execute properly"); } sb.append("</signature>"); } return sb; }