Example usage for com.lowagie.text.pdf PdfStructureElement put

List of usage examples for com.lowagie.text.pdf PdfStructureElement put

Introduction

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

Prototype

public void put(PdfName key, PdfObject object) 

Source Link

Document

Associates the specified PdfObject as value with the specified PdfName as key in this map.

Usage

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

License:Open Source License

protected void startImage(JRPrintImage printImage) {
    if (isTagged) {
        PdfStructureElement imageTag = new PdfStructureElement(allTag, PdfName.IMAGE);
        pdfContentByte.beginMarkedContentSequence(imageTag);
        if (printImage.getHyperlinkTooltip() != null) {
            imageTag.put(PdfName.ALT, new PdfString(printImage.getHyperlinkTooltip()));
        }//from   w w w.  jav  a 2  s. c  o  m
    }
}

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.j  a va  2 s.  c o  m*/
        }

        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  a 2  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);/*  w  w w.  ja v a 2  s . 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);// w  ww .j  a  v  a2  s.  co 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);/* ww  w .j  a va  2  s. com*/
    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 {/*w  w w  .ja  v 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);
    }
}

From source file:questions.markedcontent.ObjectData.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A5.rotate());
    try {//from w w w.  j ava  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();

}