List of usage examples for com.itextpdf.text.pdf PdfName V
PdfName V
To view the source code for com.itextpdf.text.pdf PdfName V.
Click Source Link
From source file:org.orbisgis.core.renderer.PdfRendererWithAttributes.java
License:Open Source License
@Override public void beginFeature(long id, DataSource sds) { int fieldNameIndex; try {//from ww w. j a va 2 s . c om fieldNameIndex = sds.getFieldIndexByName(fieldName); } catch (DriverException ex) { Logger.getLogger(PdfRendererWithAttributes.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger("Field name used for attributes does not exist: by default, we use feature + id"); fieldNameIndex = -1; } try { String attributeName; if (fieldNameIndex > -1) { attributeName = sds.getFieldValue(id, fieldNameIndex).toString(); } else { attributeName = "feature " + (id + 1); } PdfStructureElement e = new PdfStructureElement(top, new PdfName(attributeName)); PdfDictionary userProperties = new PdfDictionary(); userProperties.put(PdfName.O, PdfName.USERPROPERTIES); PdfArray properties = new PdfArray(); for (int i = 0; i < sds.getFieldCount(); i++) { if ((sds.getFieldType(i).getTypeCode() & Type.GEOMETRY) == 0) { PdfDictionary property = new PdfDictionary(); property.put(PdfName.N, new PdfString(sds.getFieldName(i))); Value v = sds.getFieldValue(id, i); property.put(PdfName.V, new PdfString(v.toString())); properties.add(property); } } userProperties.put(PdfName.P, properties); e.put(PdfName.A, userProperties); pTemp = cb.createTemplate(width, height); cb.beginMarkedContentSequence(e); } catch (DriverException ex) { Logger.getLogger(PdfRendererWithAttributes.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.orbisgis.core_export.PdfRendererWithAttributes.java
License:Open Source License
@Override public void beginFeature(long id, ResultSet rs) { try {//w w w . j a v a2s .co m String attributeName; attributeName = rs.getString(fieldName); PdfStructureElement e = new PdfStructureElement(top, new PdfName(attributeName)); PdfDictionary userProperties = new PdfDictionary(); userProperties.put(PdfName.O, PdfName.USERPROPERTIES); PdfArray properties = new PdfArray(); SpatialResultSetMetaData metaData = rs.getMetaData().unwrap(SpatialResultSetMetaData.class); int geometryField = metaData.getFirstGeometryFieldIndex(); PdfDictionary property = new PdfDictionary(); property.put(PdfName.N, new PdfString(metaData.getColumnName(geometryField))); property.put(PdfName.V, new PdfString(rs.getString(geometryField))); properties.add(property); userProperties.put(PdfName.P, properties); e.put(PdfName.A, userProperties); pTemp = cb.createTemplate(width, height); cb.beginMarkedContentSequence(e); } catch (SQLException ex) { Logger.getLogger(PdfRendererWithAttributes.class.getName()).log(Level.SEVERE, null, ex); } }
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 {/* w ww. j a va2 s . co 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 {/* ww w . j ava 2s. 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; }