Example usage for com.lowagie.text.pdf PdfArray PdfArray

List of usage examples for com.lowagie.text.pdf PdfArray PdfArray

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfArray PdfArray.

Prototype

public PdfArray() 

Source Link

Document

Constructs an empty PdfArray-object.

Usage

From source file:eu.europa.ec.markt.dss.signature.pdf.itext.ITextPdfArray.java

License:Open Source License

ITextPdfArray() {
    this(new 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  w  ww .  ja v a 2 s . c om
        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   w  w  w .  j a  va 2  s.  co  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 {//from   www  . ja  v  a2 s  . com
        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 createStartTags(JRPrintElement element) {
    if (element.hasProperties()) {
        String prop = element.getPropertiesMap().getProperty(PROPERTY_TAG_TABLE);
        if (prop != null && (TAG_START.equals(prop) || TAG_FULL.equals(prop))) {
            createTableStartTag();//from w w  w . ja  v a 2 s.  com
        }

        prop = element.getPropertiesMap().getProperty(PROPERTY_TAG_TR);
        if (prop != null && (TAG_START.equals(prop) || TAG_FULL.equals(prop))) {
            createTrStartTag();
        }

        prop = element.getPropertiesMap().getProperty(PROPERTY_TAG_TH);
        if (prop != null && (TAG_START.equals(prop) || TAG_FULL.equals(prop))) {
            createThStartTag(element);
        }

        prop = element.getPropertiesMap().getProperty(PROPERTY_TAG_TD);
        if (prop != null && (TAG_START.equals(prop) || TAG_FULL.equals(prop))) {
            createTdStartTag(element);
        }

        prop = element.getPropertiesMap().getProperty(JRCellContents.PROPERTY_TYPE);
        if (prop != null && (JRCellContents.TYPE_CROSSTAB_HEADER.equals(prop)
                || JRCellContents.TYPE_COLUMN_HEADER.equals(prop)
                || JRCellContents.TYPE_ROW_HEADER.equals(prop))) {
            createThStartTag(element);
        }
        if (prop != null && (JRCellContents.TYPE_DATA.equals(prop))) {
            createTdStartTag(element);
        }

        prop = element.getPropertiesMap().getProperty(PROPERTY_TAG_H1);
        if (prop != null && (TAG_START.equals(prop) || TAG_FULL.equals(prop))) {
            PdfStructureElement headingTag = new PdfStructureElement(tagStack.peek(), new PdfName("H1"));
            pdfContentByte.beginMarkedContentSequence(headingTag);
            headingTag.put(PdfName.K, new PdfArray());
            tagStack.push(headingTag);
            isTagEmpty = true;
        }

        prop = element.getPropertiesMap().getProperty(PROPERTY_TAG_H2);
        if (prop != null && (TAG_START.equals(prop) || TAG_FULL.equals(prop))) {
            PdfStructureElement headingTag = new PdfStructureElement(tagStack.peek(), new PdfName("H2"));
            pdfContentByte.beginMarkedContentSequence(headingTag);
            headingTag.put(PdfName.K, new PdfArray());
            tagStack.push(headingTag);
            isTagEmpty = true;
        }

        prop = element.getPropertiesMap().getProperty(PROPERTY_TAG_H3);
        if (prop != null && (TAG_START.equals(prop) || TAG_FULL.equals(prop))) {
            PdfStructureElement headingTag = new PdfStructureElement(tagStack.peek(), new PdfName("H3"));
            pdfContentByte.beginMarkedContentSequence(headingTag);
            headingTag.put(PdfName.K, new PdfArray());
            tagStack.push(headingTag);
            isTagEmpty = true;
        }
    }
}

From source file:net.sf.jasperreports.engine.export.JRPdfExporterTagHelper.java

License:Open Source License

protected void createTableStartTag() {
    PdfStructureElement tableTag = new PdfStructureElement(allTag, new PdfName("Table"));
    pdfContentByte.beginMarkedContentSequence(tableTag);
    tableTag.put(PdfName.K, new PdfArray());
    tagStack.push(tableTag);//from   w  w w. ja v a2 s.  c om
}

From source file:net.sf.jasperreports.engine.export.JRPdfExporterTagHelper.java

License:Open Source License

protected void createTrStartTag() {
    PdfStructureElement tableRowTag = new PdfStructureElement(tagStack.peek(), new PdfName("TR"));
    pdfContentByte.beginMarkedContentSequence(tableRowTag);
    tableRowTag.put(PdfName.K, new PdfArray());
    tagStack.push(tableRowTag);//from w w  w .  java  2s  .  c  om
}

From source file:net.sf.jasperreports.engine.export.JRPdfExporterTagHelper.java

License:Open Source License

protected void createThStartTag(JRPrintElement element) {
    PdfStructureElement tableHeaderTag = new PdfStructureElement(tagStack.peek(), new PdfName("TH"));
    pdfContentByte.beginMarkedContentSequence(tableHeaderTag);
    tableHeaderTag.put(PdfName.K, new PdfArray());
    tagStack.push(tableHeaderTag);//from  ww  w. j a  va  2  s .  c o  m
    isTagEmpty = true;

    createSpanTags(element, tableHeaderTag);
}

From source file:net.sf.jasperreports.engine.export.JRPdfExporterTagHelper.java

License:Open Source License

protected void createTdStartTag(JRPrintElement element) {
    PdfStructureElement tableCellTag = new PdfStructureElement(tagStack.peek(), new PdfName("TD"));
    pdfContentByte.beginMarkedContentSequence(tableCellTag);
    tableCellTag.put(PdfName.K, new PdfArray());
    tagStack.push(tableCellTag);/*from ww  w  .  j  a v a  2 s .  c om*/
    isTagEmpty = true;

    createSpanTags(element, tableCellTag);
}

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 {/*from   w  w w  .  j av a  2s  . c o  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);
    }
}