Search in sources :

Example 1 with PdfLayerMembership

use of com.lowagie.text.pdf.PdfLayerMembership in project itext2 by albfernandez.

the class LayersTest method main.

/**
 * Demonstrates some Layer functionality.
 */
@Test
public void main() throws Exception {
    // step 1: creation of a document-object
    Document document = new Document();
    // step 2:
    PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Layers.pdf"));
    writer.setPdfVersion(PdfWriter.VERSION_1_5);
    // step 3:
    writer.setViewerPreferences(PdfWriter.PageModeUseOC);
    document.open();
    // step 4:
    PdfContentByte cb = writer.getDirectContent();
    Phrase explanation = new Phrase("Layer grouping", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red));
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0);
    PdfLayer l1 = new PdfLayer("Layer 1", writer);
    PdfLayer l2 = new PdfLayer("Layer 2", writer);
    PdfLayer l3 = new PdfLayer("Layer 3", writer);
    PdfLayerMembership m1 = new PdfLayerMembership(writer);
    m1.addMember(l2);
    m1.addMember(l3);
    Phrase p1 = new Phrase("Text in layer 1");
    Phrase p2 = new Phrase("Text in layer 2 or layer 3");
    Phrase p3 = new Phrase("Text in layer 3");
    cb.beginLayer(l1);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
    cb.endLayer();
    cb.beginLayer(m1);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
    cb.endLayer();
    cb.beginLayer(l3);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
    cb.endLayer();
    PdfOCProperties p = writer.getOCProperties();
    PdfArray order = new PdfArray();
    order.add(l1.getRef());
    PdfArray group = new PdfArray();
    group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE));
    group.add(l2.getRef());
    group.add(l3.getRef());
    order.add(group);
    PdfDictionary d = new PdfDictionary();
    d.put(PdfName.ORDER, order);
    p.put(PdfName.D, d);
    // step 5: we close the document
    document.close();
}
Also used : PdfArray(com.lowagie.text.pdf.PdfArray) PdfWriter(com.lowagie.text.pdf.PdfWriter) PdfDictionary(com.lowagie.text.pdf.PdfDictionary) PdfLayer(com.lowagie.text.pdf.PdfLayer) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) Phrase(com.lowagie.text.Phrase) Document(com.lowagie.text.Document) PdfLayerMembership(com.lowagie.text.pdf.PdfLayerMembership) PdfOCProperties(com.lowagie.text.pdf.PdfOCProperties) PdfString(com.lowagie.text.pdf.PdfString) Font(com.lowagie.text.Font) Test(org.junit.Test)

Example 2 with PdfLayerMembership

use of com.lowagie.text.pdf.PdfLayerMembership in project itext2 by albfernandez.

the class OrderedLayersTest method main.

/**
 * Demonstrates how to order optional content groups.
 *
 * @param args
 *            no arguments needed
 */
@Test
public void main() throws Exception {
    // step 1
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("orderedlayers.pdf"));
    writer.setPdfVersion(PdfWriter.VERSION_1_5);
    writer.setViewerPreferences(PdfWriter.PageModeUseOC);
    // step 3
    document.open();
    // step 4
    PdfContentByte cb = writer.getDirectContent();
    Phrase explanation = new Phrase("Ordered layers", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red));
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0);
    PdfLayer l1 = new PdfLayer("Layer 1", writer);
    PdfLayer l2 = new PdfLayer("Layer 2", writer);
    PdfLayer l3 = new PdfLayer("Layer 3", writer);
    PdfLayerMembership m1 = new PdfLayerMembership(writer);
    m1.addMember(l2);
    m1.addMember(l3);
    Phrase p1 = new Phrase("Text in layer 1");
    Phrase p2 = new Phrase("Text in layer 2 or layer 3");
    Phrase p3 = new Phrase("Text in layer 3");
    cb.beginLayer(l1);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
    cb.endLayer();
    cb.beginLayer(m1);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
    cb.endLayer();
    cb.beginLayer(l3);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
    cb.endLayer();
    cb.sanityCheck();
    PdfOCProperties p = writer.getOCProperties();
    PdfArray order = new PdfArray();
    order.add(l1.getRef());
    order.add(l2.getRef());
    order.add(l3.getRef());
    PdfDictionary d = new PdfDictionary();
    d.put(PdfName.ORDER, order);
    p.put(PdfName.D, d);
    // step 5
    document.close();
}
Also used : PdfArray(com.lowagie.text.pdf.PdfArray) PdfWriter(com.lowagie.text.pdf.PdfWriter) PdfDictionary(com.lowagie.text.pdf.PdfDictionary) PdfLayer(com.lowagie.text.pdf.PdfLayer) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) Phrase(com.lowagie.text.Phrase) Document(com.lowagie.text.Document) PdfLayerMembership(com.lowagie.text.pdf.PdfLayerMembership) PdfOCProperties(com.lowagie.text.pdf.PdfOCProperties) Font(com.lowagie.text.Font) Test(org.junit.Test)

Example 3 with PdfLayerMembership

use of com.lowagie.text.pdf.PdfLayerMembership in project OpenPDF by LibrePDF.

the class Layers method main.

/**
 * Demonstrates some Layer functionality.
 *
 * @param args
 *            no arguments needed here
 */
public static void main(String[] args) {
    System.out.println("layers");
    // step 1: creation of a document-object
    Document document = new Document();
    try {
        // step 2:
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Layers.pdf"));
        writer.setPdfVersion(PdfWriter.VERSION_1_5);
        // step 3:
        writer.setViewerPreferences(PdfWriter.PageModeUseOC);
        document.open();
        // step 4:
        PdfContentByte cb = writer.getDirectContent();
        Phrase explanation = new Phrase("Layer grouping", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red));
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0);
        PdfLayer l1 = new PdfLayer("Layer 1", writer);
        PdfLayer l2 = new PdfLayer("Layer 2", writer);
        PdfLayer l3 = new PdfLayer("Layer 3", writer);
        PdfLayerMembership m1 = new PdfLayerMembership(writer);
        m1.addMember(l2);
        m1.addMember(l3);
        Phrase p1 = new Phrase("Text in layer 1");
        Phrase p2 = new Phrase("Text in layer 2 or layer 3");
        Phrase p3 = new Phrase("Text in layer 3");
        cb.beginLayer(l1);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
        cb.endLayer();
        cb.beginLayer(m1);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
        cb.endLayer();
        cb.beginLayer(l3);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
        cb.endLayer();
        PdfOCProperties p = writer.getOCProperties();
        PdfArray order = new PdfArray();
        order.add(l1.getRef());
        PdfArray group = new PdfArray();
        group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE));
        group.add(l2.getRef());
        group.add(l3.getRef());
        order.add(group);
        PdfDictionary d = new PdfDictionary();
        d.put(PdfName.ORDER, order);
        p.put(PdfName.D, d);
    } catch (DocumentException | IOException de) {
        System.err.println(de.getMessage());
    }
    // step 5: we close the document
    document.close();
}
Also used : PdfArray(com.lowagie.text.pdf.PdfArray) PdfWriter(com.lowagie.text.pdf.PdfWriter) PdfDictionary(com.lowagie.text.pdf.PdfDictionary) PdfLayer(com.lowagie.text.pdf.PdfLayer) Phrase(com.lowagie.text.Phrase) IOException(java.io.IOException) Document(com.lowagie.text.Document) PdfOCProperties(com.lowagie.text.pdf.PdfOCProperties) PdfString(com.lowagie.text.pdf.PdfString) Font(com.lowagie.text.Font) FileOutputStream(java.io.FileOutputStream) DocumentException(com.lowagie.text.DocumentException) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) PdfLayerMembership(com.lowagie.text.pdf.PdfLayerMembership)

Example 4 with PdfLayerMembership

use of com.lowagie.text.pdf.PdfLayerMembership in project OpenPDF by LibrePDF.

the class ContentGroups method main.

/**
 * Demonstrates how to group optional content.
 * @param args no arguments needed
 */
public static void main(String[] args) {
    System.out.println("Grouping optional content");
    try {
        // step 1
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("contentgroups.pdf"));
        writer.setPdfVersion(PdfWriter.VERSION_1_5);
        writer.setViewerPreferences(PdfWriter.PageModeUseOC);
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        Phrase explanation = new Phrase("Layer grouping", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red));
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0);
        PdfLayer l1 = new PdfLayer("Layer 1", writer);
        PdfLayer l2 = new PdfLayer("Layer 2", writer);
        PdfLayer l3 = new PdfLayer("Layer 3", writer);
        PdfLayerMembership m1 = new PdfLayerMembership(writer);
        m1.addMember(l2);
        m1.addMember(l3);
        Phrase p1 = new Phrase("Text in layer 1");
        Phrase p2 = new Phrase("Text in layer 2 or layer 3");
        Phrase p3 = new Phrase("Text in layer 3");
        cb.beginLayer(l1);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
        cb.endLayer();
        cb.beginLayer(m1);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
        cb.endLayer();
        cb.beginLayer(l3);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
        cb.endLayer();
        cb.sanityCheck();
        PdfOCProperties p = writer.getOCProperties();
        PdfArray order = new PdfArray();
        order.add(l1.getRef());
        PdfArray group = new PdfArray();
        group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE));
        group.add(l2.getRef());
        group.add(l3.getRef());
        order.add(group);
        PdfDictionary d = new PdfDictionary();
        d.put(PdfName.ORDER, order);
        p.put(PdfName.D, d);
        // step 5
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}
Also used : PdfArray(com.lowagie.text.pdf.PdfArray) PdfWriter(com.lowagie.text.pdf.PdfWriter) PdfDictionary(com.lowagie.text.pdf.PdfDictionary) PdfLayer(com.lowagie.text.pdf.PdfLayer) Phrase(com.lowagie.text.Phrase) Document(com.lowagie.text.Document) PdfOCProperties(com.lowagie.text.pdf.PdfOCProperties) PdfString(com.lowagie.text.pdf.PdfString) Font(com.lowagie.text.Font) FileOutputStream(java.io.FileOutputStream) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) PdfLayerMembership(com.lowagie.text.pdf.PdfLayerMembership)

Example 5 with PdfLayerMembership

use of com.lowagie.text.pdf.PdfLayerMembership in project OpenPDF by LibrePDF.

the class OrderedLayers method main.

/**
 * Demonstrates how to order optional content groups.
 * @param args no arguments needed
 */
public static void main(String[] args) {
    System.out.println("Ordering optional content groups");
    try {
        // step 1
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("orderedlayers.pdf"));
        writer.setPdfVersion(PdfWriter.VERSION_1_5);
        writer.setViewerPreferences(PdfWriter.PageModeUseOC);
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        Phrase explanation = new Phrase("Ordered layers", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red));
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0);
        PdfLayer l1 = new PdfLayer("Layer 1", writer);
        PdfLayer l2 = new PdfLayer("Layer 2", writer);
        PdfLayer l3 = new PdfLayer("Layer 3", writer);
        PdfLayerMembership m1 = new PdfLayerMembership(writer);
        m1.addMember(l2);
        m1.addMember(l3);
        Phrase p1 = new Phrase("Text in layer 1");
        Phrase p2 = new Phrase("Text in layer 2 or layer 3");
        Phrase p3 = new Phrase("Text in layer 3");
        cb.beginLayer(l1);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
        cb.endLayer();
        cb.beginLayer(m1);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
        cb.endLayer();
        cb.beginLayer(l3);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
        cb.endLayer();
        cb.sanityCheck();
        PdfOCProperties p = writer.getOCProperties();
        PdfArray order = new PdfArray();
        order.add(l1.getRef());
        order.add(l2.getRef());
        order.add(l3.getRef());
        PdfDictionary d = new PdfDictionary();
        d.put(PdfName.ORDER, order);
        p.put(PdfName.D, d);
        // step 5
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}
Also used : PdfArray(com.lowagie.text.pdf.PdfArray) PdfWriter(com.lowagie.text.pdf.PdfWriter) PdfDictionary(com.lowagie.text.pdf.PdfDictionary) FileOutputStream(java.io.FileOutputStream) PdfLayer(com.lowagie.text.pdf.PdfLayer) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) Phrase(com.lowagie.text.Phrase) Document(com.lowagie.text.Document) PdfLayerMembership(com.lowagie.text.pdf.PdfLayerMembership) PdfOCProperties(com.lowagie.text.pdf.PdfOCProperties) Font(com.lowagie.text.Font)

Aggregations

Document (com.lowagie.text.Document)8 Font (com.lowagie.text.Font)8 Phrase (com.lowagie.text.Phrase)8 PdfContentByte (com.lowagie.text.pdf.PdfContentByte)8 PdfLayer (com.lowagie.text.pdf.PdfLayer)8 PdfLayerMembership (com.lowagie.text.pdf.PdfLayerMembership)8 PdfWriter (com.lowagie.text.pdf.PdfWriter)8 PdfArray (com.lowagie.text.pdf.PdfArray)6 PdfDictionary (com.lowagie.text.pdf.PdfDictionary)6 PdfOCProperties (com.lowagie.text.pdf.PdfOCProperties)6 PdfString (com.lowagie.text.pdf.PdfString)4 FileOutputStream (java.io.FileOutputStream)4 Test (org.junit.Test)4 Chunk (com.lowagie.text.Chunk)2 Image (com.lowagie.text.Image)2 Rectangle (com.lowagie.text.Rectangle)2 PdfAction (com.lowagie.text.pdf.PdfAction)2 PdfFormField (com.lowagie.text.pdf.PdfFormField)2 PdfTemplate (com.lowagie.text.pdf.PdfTemplate)2 TextField (com.lowagie.text.pdf.TextField)2