List of usage examples for com.itextpdf.text.pdf PdfName P
PdfName P
To view the source code for com.itextpdf.text.pdf PdfName P.
Click Source Link
From source file:de.gbv.marginalia.Annotation.java
License:Open Source License
/** * Serialize the annotation in XML format. * The annotation is emitted as stream of SAX events to a ContentHandler. * The XML is XFDF with additional Marginalia elements in its own namespace. */// ww w. ja va 2 s. c om public void serializeXML(ContentHandler handler) throws SAXException { SimpleXMLCreator xml = new SimpleXMLCreator(handler, namespaces); Set<PdfName> allkeys = this.dict.getKeys(); allkeys.remove(PdfName.TYPE); allkeys.remove(PdfName.SUBTYPE); allkeys.remove(PdfName.PARENT); allkeys.remove(PdfName.CONTENTS); allkeys.remove(PdfName.POPUP); Map<String, String> attrs = new HashMap<String, String>(); for (String aName : this.FIELDS.keySet()) { Field f = this.FIELDS.get(aName); String value = f.getFrom(this.dict); if (value != null) { // TODO: encoding & exception attrs.put(aName, value); // allkeys.remove( f.name ); } } PdfDictionary pg = getAsDictionary(this.dict, PdfName.P); allkeys.remove(PdfName.P); //CropBox=[0, 0, 595, 842] //Rotate //MediaBox=[0, 0, 595, 842] // TODO: find out where page number is stored if (attrs.get("page") == null) attrs.put("page", "" + this.pageNum); String element = subtypes.get(this.subtype); if (element == null) { // TODO element = this.subtype.toString(); } xml.startElement(element, attrs); if (element.equals("ink")) { PdfArray inklist = this.dict.getAsArray(new PdfName("InkList")); if (inklist != null) { xml.startElement("inklist"); for (int i = 0; i < inklist.size(); i++) { PdfArray pathArray = inklist.getAsArray(i); String s = ""; for (int j = 0; j < pathArray.size(); j += 2) { if (j > 0) s += ";"; s += "" + pathArray.getAsNumber(j).floatValue() + ","; s += "" + pathArray.getAsNumber(j + 1).floatValue(); } xml.contentElement("gesture", s); } xml.endElement(); } } if (attrs.get("rect") != null) { Map<String, String> a = new HashMap<String, String>(); RectField rf = (RectField) this.FIELDS.get("rect"); PdfRectangle r = null; if (rf != null) r = (PdfRectangle) rf.getObjectFrom(this.dict); if (r != null) { a.put("left", "" + r.left()); a.put("bottom", "" + r.bottom()); a.put("right", "" + r.right()); a.put("top", "" + r.top()); xml.emptyElement("m", "rect", a); } } if (this.content != null && !this.content.equals("")) { // TODO: encode content if not UTF-8 ? xml.contentElement("content", content.toString()); } // TODO: contents-richtext // TODO: popup /* if ( this.popup != null ) { out.println("<!--popup>"); for ( PdfName n : this.popup.getKeys() ) { out.println( n + "=" + this.popup.getDirectObject(n) ); } out.println("</popup-->"); } */ // remaining dictionary elements /* for ( PdfName name : allkeys ) { Map<String,String> a = new HashMap<String,String>(); a.put("name",name.toString()); a.put("value",this.dict.getDirectObject(name).toString()); xml.emptyElement( "m","unknown", a ); } */ xml.endElement(); }
From source file:org.orbisgis.core.renderer.PdfRendererWithAttributes.java
License:Open Source License
@Override public void beginFeature(long id, DataSource sds) { int fieldNameIndex; try {/* w ww . j a va 2 s . c o m*/ 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 {//from ww w. j av a 2s . 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:pdfpruefbericht.PdfPruefbericht.java
License:Open Source License
public static void main(String[] args) throws IOException, DocumentException, SAXException, ParserConfigurationException, URISyntaxException { String RESULT = args[1];// www . j a va2 s .c o m String RESOURCE = args[0]; ContentParser cp; float compression; try { compression = Float.parseFloat(args[2]); } catch (NumberFormatException e) { System.out.println("Kompresion konnte nicht geparsed werden ... : " + e.getMessage()); compression = 0.5f; } try { Document document = new Document(PageSize.A4); document.setMargins(36, 72, 36, 144); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setTagged(); document.open(); PdfStructureTreeRoot root = writer.getStructureTreeRoot(); root.mapRole(new PdfName("Report"), PdfName.ROOT); root.mapRole(new PdfName("Norm"), PdfName.SECT); root.mapRole(new PdfName("Test"), PdfName.SEPARATION); root.mapRole(new PdfName("Comment"), PdfName.CO); root.mapRole(new PdfName("img"), PdfName.PI); root.mapRole(new PdfName("log"), PdfName.L); root.mapRole(new PdfName("Setup"), PdfName.SETTINGS); root.mapRole(new PdfName("device"), PdfName.D); root.mapRole(new PdfName("parameter"), PdfName.P); PdfStructureElement top = new PdfStructureElement(root, new PdfName("Report")); SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); List<PdfStructureElement> elements = new ArrayList<>(); cp = new ContentParser(document, writer, elements); parser.parse(new InputSource(new FileInputStream(RESOURCE)), new StructureParser(top, elements)); parser.parse(new InputSource(new FileInputStream(RESOURCE)), cp); PdfBuilder pdf = new PdfBuilder(document, writer, cp.getReport(), compression); pdf.build(); document.close(); } catch (IOException | DocumentException | SAXException | ParserConfigurationException e) { System.out.println(e.getMessage()); } //watermark watermark = new watermark(); }