List of usage examples for com.lowagie.text.pdf PdfArray add
public boolean add(int values[])
int
values to end of the PdfArray
. From source file:net.sf.dynamicreports.examples.genericelement.openflashchart.OpenFlashChartPdfHandler.java
License:Open Source License
@Override public void exportElement(JRPdfExporterContext exporterContext, JRGenericPrintElement element) { try {/*from www.j av a 2s . co m*/ PdfWriter writer = exporterContext.getPdfWriter(); PdfIndirectObject swfRef; boolean newContext = !existingContexts.containsKey(exporterContext); if (newContext) { PdfDictionary extensions = new PdfDictionary(); PdfDictionary adobeExtension = new PdfDictionary(); adobeExtension.put(new PdfName("BaseVersion"), PdfWriter.PDF_VERSION_1_7); adobeExtension.put(new PdfName("ExtensionLevel"), new PdfNumber(3)); extensions.put(new PdfName("ADBE"), adobeExtension); writer.getExtraCatalog().put(new PdfName("Extensions"), extensions); byte[] swfData = getChartSwf(); PdfFileSpecification swfFile = PdfFileSpecification.fileEmbedded(writer, null, "Open Flash Chart", swfData); swfRef = writer.addToBody(swfFile); existingContexts.put(exporterContext, swfRef); } else { swfRef = (PdfIndirectObject) existingContexts.get(exporterContext); } Rectangle rect = new Rectangle(element.getX() + exporterContext.getOffsetX(), exporterContext.getExportedReport().getPageHeight() - element.getY() - exporterContext.getOffsetY(), element.getX() + exporterContext.getOffsetX() + element.getWidth(), exporterContext.getExportedReport().getPageHeight() - element.getY() - exporterContext.getOffsetY() - element.getHeight()); PdfAnnotation ann = new PdfAnnotation(writer, rect); ann.put(PdfName.SUBTYPE, new PdfName("RichMedia")); PdfDictionary settings = new PdfDictionary(); PdfDictionary activation = new PdfDictionary(); activation.put(new PdfName("Condition"), new PdfName("PV")); settings.put(new PdfName("Activation"), activation); ann.put(new PdfName("RichMediaSettings"), settings); PdfDictionary content = new PdfDictionary(); HashMap<String, PdfIndirectReference> assets = new HashMap<String, PdfIndirectReference>(); assets.put("map.swf", swfRef.getIndirectReference()); PdfDictionary assetsDictionary = PdfNameTree.writeTree(assets, writer); content.put(new PdfName("Assets"), assetsDictionary); PdfArray configurations = new PdfArray(); PdfDictionary configuration = new PdfDictionary(); PdfArray instances = new PdfArray(); PdfDictionary instance = new PdfDictionary(); instance.put(new PdfName("Subtype"), new PdfName("Flash")); PdfDictionary params = new PdfDictionary(); String chartData = ((ChartGenerator) element .getParameterValue(ChartGenerator.PARAMETER_CHART_GENERATOR)).generateChart(); String vars = "inline_data=" + chartData; params.put(new PdfName("FlashVars"), new PdfString(vars)); instance.put(new PdfName("Params"), params); instance.put(new PdfName("Asset"), swfRef.getIndirectReference()); PdfIndirectObject instanceRef = writer.addToBody(instance); instances.add(instanceRef.getIndirectReference()); configuration.put(new PdfName("Instances"), instances); PdfIndirectObject configurationRef = writer.addToBody(configuration); configurations.add(configurationRef.getIndirectReference()); content.put(new PdfName("Configurations"), configurations); ann.put(new PdfName("RichMediaContent"), content); writer.addAnnotation(ann); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:net.sf.fspdfs.components.ofc.ChartPdfHandler.java
License:Open Source License
public void exportElement(JRPdfExporterContext exporterContext, JRGenericPrintElement element) { try {/*from ww w . ja va 2 s . c o m*/ PdfWriter writer = exporterContext.getPdfWriter(); PdfIndirectObject swfRef; boolean newContext = !existingContexts.containsKey(exporterContext); if (newContext) { // add the Adobe 1.7 extensions catalog dictionary PdfDictionary extensions = new PdfDictionary(); PdfDictionary adobeExtension = new PdfDictionary(); adobeExtension.put(new PdfName("BaseVersion"), PdfWriter.PDF_VERSION_1_7); adobeExtension.put(new PdfName("ExtensionLevel"), new PdfNumber(3)); extensions.put(new PdfName("ADBE"), adobeExtension); writer.getExtraCatalog().put(new PdfName("Extensions"), extensions); // add the swf file byte[] swfData = readSwf(); PdfFileSpecification swfFile = PdfFileSpecification.fileEmbedded(writer, null, "Open Flash Chart", swfData); swfRef = writer.addToBody(swfFile); existingContexts.put(exporterContext, swfRef); } else { swfRef = (PdfIndirectObject) existingContexts.get(exporterContext); } Rectangle rect = new Rectangle(element.getX() + exporterContext.getOffsetX(), exporterContext.getExportedReport().getPageHeight() - element.getY() - exporterContext.getOffsetY(), element.getX() + exporterContext.getOffsetX() + element.getWidth(), exporterContext.getExportedReport().getPageHeight() - element.getY() - exporterContext.getOffsetY() - element.getHeight()); PdfAnnotation ann = new PdfAnnotation(writer, rect); ann.put(PdfName.SUBTYPE, new PdfName("RichMedia")); PdfDictionary settings = new PdfDictionary(); PdfDictionary activation = new PdfDictionary(); activation.put(new PdfName("Condition"), new PdfName("PV")); settings.put(new PdfName("Activation"), activation); ann.put(new PdfName("RichMediaSettings"), settings); PdfDictionary content = new PdfDictionary(); HashMap assets = new HashMap(); assets.put("map.swf", swfRef.getIndirectReference()); PdfDictionary assetsDictionary = PdfNameTree.writeTree(assets, writer); content.put(new PdfName("Assets"), assetsDictionary); PdfArray configurations = new PdfArray(); PdfDictionary configuration = new PdfDictionary(); PdfArray instances = new PdfArray(); PdfDictionary instance = new PdfDictionary(); instance.put(new PdfName("Subtype"), new PdfName("Flash")); PdfDictionary params = new PdfDictionary(); String chartData = (String) element.getParameterValue(PARAMETER_CHART_DATA); String vars = "inline_data=" + chartData; params.put(new PdfName("FlashVars"), new PdfString(vars)); instance.put(new PdfName("Params"), params); instance.put(new PdfName("Asset"), swfRef.getIndirectReference()); PdfIndirectObject instanceRef = writer.addToBody(instance); instances.add(instanceRef.getIndirectReference()); configuration.put(new PdfName("Instances"), instances); PdfIndirectObject configurationRef = writer.addToBody(configuration); configurations.add(configurationRef.getIndirectReference()); content.put(new PdfName("Configurations"), configurations); ann.put(new PdfName("RichMediaContent"), content); writer.addAnnotation(ann); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:net.sf.jasperreports.components.ofc.ChartPdfHandler.java
License:Open Source License
public void exportElement(JRPdfExporterContext exporterContext, JRGenericPrintElement element) { try {/* ww w. j a va 2s.c o m*/ PdfWriter writer = exporterContext.getPdfWriter(); PdfIndirectObject swfRef; boolean newContext = !existingContexts.containsKey(exporterContext); if (newContext) { // add the Adobe 1.7 extensions catalog dictionary PdfDictionary extensions = new PdfDictionary(); PdfDictionary adobeExtension = new PdfDictionary(); adobeExtension.put(new PdfName("BaseVersion"), PdfWriter.PDF_VERSION_1_7); adobeExtension.put(new PdfName("ExtensionLevel"), new PdfNumber(3)); extensions.put(new PdfName("ADBE"), adobeExtension); writer.getExtraCatalog().put(new PdfName("Extensions"), extensions); // add the swf file byte[] swfData = readSwf(); PdfFileSpecification swfFile = PdfFileSpecification.fileEmbedded(writer, null, "Open Flash Chart", swfData); swfRef = writer.addToBody(swfFile); existingContexts.put(exporterContext, swfRef); } else { swfRef = (PdfIndirectObject) existingContexts.get(exporterContext); } Rectangle rect = new Rectangle(element.getX() + exporterContext.getOffsetX(), exporterContext.getExportedReport().getPageHeight() - element.getY() - exporterContext.getOffsetY(), element.getX() + exporterContext.getOffsetX() + element.getWidth(), exporterContext.getExportedReport().getPageHeight() - element.getY() - exporterContext.getOffsetY() - element.getHeight()); PdfAnnotation ann = new PdfAnnotation(writer, rect); ann.put(PdfName.SUBTYPE, new PdfName("RichMedia")); PdfDictionary settings = new PdfDictionary(); PdfDictionary activation = new PdfDictionary(); activation.put(new PdfName("Condition"), new PdfName("PV")); settings.put(new PdfName("Activation"), activation); ann.put(new PdfName("RichMediaSettings"), settings); PdfDictionary content = new PdfDictionary(); HashMap<String, PdfIndirectReference> assets = new HashMap<String, PdfIndirectReference>(); assets.put("map.swf", swfRef.getIndirectReference()); PdfDictionary assetsDictionary = PdfNameTree.writeTree(assets, writer); content.put(new PdfName("Assets"), assetsDictionary); PdfArray configurations = new PdfArray(); PdfDictionary configuration = new PdfDictionary(); PdfArray instances = new PdfArray(); PdfDictionary instance = new PdfDictionary(); instance.put(new PdfName("Subtype"), new PdfName("Flash")); PdfDictionary params = new PdfDictionary(); String chartData = (String) element.getParameterValue(PARAMETER_CHART_DATA); String vars = "inline_data=" + chartData; params.put(new PdfName("FlashVars"), new PdfString(vars)); instance.put(new PdfName("Params"), params); instance.put(new PdfName("Asset"), swfRef.getIndirectReference()); PdfIndirectObject instanceRef = writer.addToBody(instance); instances.add(instanceRef.getIndirectReference()); configuration.put(new PdfName("Instances"), instances); PdfIndirectObject configurationRef = writer.addToBody(configuration); configurations.add(configurationRef.getIndirectReference()); content.put(new PdfName("Configurations"), configurations); ann.put(new PdfName("RichMediaContent"), content); writer.addAnnotation(ann); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:net.sf.jasperreports.engine.export.JRPdfExporterTagHelper.java
License:Open Source License
protected void createSpanTags(JRPrintElement element, PdfStructureElement parentTag) { int colSpan = 0; int rowSpan = 0; try {// w ww .jav a2s.co m colSpan = Integer.valueOf(element.getPropertiesMap().getProperty(PROPERTY_TAG_COLSPAN)).intValue(); } catch (NumberFormatException e) { try { colSpan = Integer .valueOf(element.getPropertiesMap().getProperty(JRCellContents.PROPERTY_COLUMN_SPAN)) .intValue(); } catch (NumberFormatException ex) { } } try { rowSpan = Integer.valueOf(element.getPropertiesMap().getProperty(PROPERTY_TAG_ROWSPAN)).intValue(); } catch (NumberFormatException e) { try { rowSpan = Integer.valueOf(element.getPropertiesMap().getProperty(JRCellContents.PROPERTY_ROW_SPAN)) .intValue(); } catch (NumberFormatException ex) { } } if (colSpan > 1 || rowSpan > 1) { PdfArray a = new PdfArray(); PdfDictionary dict = new PdfDictionary(); if (colSpan > 1) { dict.put(new PdfName("ColSpan"), new PdfNumber(colSpan)); } if (rowSpan > 1) { dict.put(new PdfName("RowSpan"), new PdfNumber(rowSpan)); } dict.put(PdfName.O, new PdfName("Table")); a.add(dict); parentTag.put(PdfName.A, a); } }
From source file:org.xhtmlrenderer.pdf.ITextOutputDevice.java
License:Open Source License
private void writeNamedDestinations(RenderingContext c) { Map idMap = getSharedContext().getIdMap(); if ((idMap != null) && (!idMap.isEmpty())) { PdfArray dests = new PdfArray(); try {/*from www. j a v a 2 s . co m*/ Iterator it = idMap.entrySet().iterator(); while (it.hasNext()) { Entry entry = (Entry) it.next(); Box targetBox = (Box) entry.getValue(); if (targetBox.getStyle().isIdent(CSSName.FS_NAMED_DESTINATION, IdentValue.CREATE)) { String anchorName = (String) entry.getKey(); dests.add(new PdfString(anchorName, PdfString.TEXT_UNICODE)); PdfDestination dest = createDestination(c, targetBox); if (dest != null) { PdfIndirectReference ref = _writer.addToBody(dest).getIndirectReference(); dests.add(ref); } } } if (!dests.isEmpty()) { PdfDictionary nametree = new PdfDictionary(); nametree.put(PdfName.NAMES, dests); PdfIndirectReference nameTreeRef = _writer.addToBody(nametree).getIndirectReference(); PdfDictionary names = new PdfDictionary(); names.put(PdfName.DESTS, nameTreeRef); PdfIndirectReference destinationsRef = _writer.addToBody(names).getIndirectReference(); _writer.getExtraCatalog().put(PdfName.NAMES, destinationsRef); } } catch (IOException e) { throw new RuntimeException(e); } } }
From source file:questions.markedcontent.ObjectData.java
public static void main(String[] args) { Document document = new Document(PageSize.A5.rotate()); try {//from w ww . j a v a 2 s.c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setTagged(); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfStructureTreeRoot tree = writer.getStructureTreeRoot(); PdfStructureElement se = new PdfStructureElement(tree, new PdfName("Figure")); PdfStructureElement element = new PdfStructureElement(se, new PdfName("Element")); PdfDictionary userproperties = new PdfDictionary(); userproperties.put(PdfName.O, PdfName.USERPROPERTIES); userproperties.put(PdfName.S, new PdfName("Figure")); PdfArray properties = new PdfArray(); PdfDictionary property1 = new PdfDictionary(); property1.put(PdfName.N, new PdfString("Name1")); property1.put(PdfName.V, new PdfString("Value1")); properties.add(property1); PdfDictionary property2 = new PdfDictionary(); property2.put(PdfName.N, new PdfString("Name2")); property2.put(PdfName.V, new PdfString("Value2")); properties.add(property2); PdfDictionary property3 = new PdfDictionary(); property3.put(PdfName.N, new PdfString("Name3")); property3.put(PdfName.V, new PdfString("Value3")); properties.add(property3); userproperties.put(PdfName.P, properties); element.put(PdfName.A, userproperties); PdfLayer lay1 = new PdfLayer("My object", writer); cb.beginMarkedContentSequence(element); cb.beginLayer(lay1); cb.setColorFill(Color.BLUE); cb.rectangle(50, 50, 200, 200); cb.fill(); cb.endLayer(); cb.endMarkedContentSequence(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }