Example usage for com.lowagie.text.pdf PdfWriter VERSION_1_5

List of usage examples for com.lowagie.text.pdf PdfWriter VERSION_1_5

Introduction

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

Prototype

char VERSION_1_5

To view the source code for com.lowagie.text.pdf PdfWriter VERSION_1_5.

Click Source Link

Document

possible PDF version (header)

Usage

From source file:lucee.runtime.tag.PDF.java

License:Open Source License

/**
 * @param version the version to set//from w w w  . java 2 s  .  co  m
 * @throws ApplicationException 
 */
public void setVersion(double version) throws ApplicationException {
    if (1.1 == version)
        this.version = '1';
    else if (1.2 == version)
        this.version = PdfWriter.VERSION_1_2;
    else if (1.3 == version)
        this.version = PdfWriter.VERSION_1_3;
    else if (1.4 == version)
        this.version = PdfWriter.VERSION_1_4;
    else if (1.5 == version)
        this.version = PdfWriter.VERSION_1_5;
    else if (1.6 == version)
        this.version = PdfWriter.VERSION_1_6;

    else
        throw new ApplicationException("invalid version definition [" + Caster.toString(version)
                + "], valid version definitions are " + "[1.1, 1.2, 1.3, 1.4, 1.5, 1.6]");
}

From source file:org.lucee.extension.pdf.tag.PDF.java

License:Open Source License

/**
 * @param version/*w  w  w .  j  ava  2  s .  co  m*/
 *            the version to set
 * @throws PageException
 */
public void setVersion(double version) throws PageException {
    if (1.1 == version)
        this.version = '1';
    else if (1.2 == version)
        this.version = PdfWriter.VERSION_1_2;
    else if (1.3 == version)
        this.version = PdfWriter.VERSION_1_3;
    else if (1.4 == version)
        this.version = PdfWriter.VERSION_1_4;
    else if (1.5 == version)
        this.version = PdfWriter.VERSION_1_5;
    else if (1.6 == version)
        this.version = PdfWriter.VERSION_1_6;

    else
        throw engine.getExceptionUtil().createApplicationException(
                "invalid version definition [" + engine.getCastUtil().toString(version)
                        + "], valid version definitions are " + "[1.1, 1.2, 1.3, 1.4, 1.5, 1.6]");
}

From source file:questions.encryption.HelloWorldMetadataNotEncrypted.java

public static void main(String[] args) {
    // step 1// w  w  w  .  ja v  a  2s.  co m
    Document document = new Document();
    try {
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        writer.setEncryption("hello".getBytes(), "world".getBytes(), 0,
                PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA);
        writer.createXmpMetadata();
        writer.setPdfVersion(PdfWriter.VERSION_1_5);
        // step 3
        document.open();
        // step 4
        document.add(new Paragraph("Hello World"));
        writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 650f, 150f, 700f),
                "This is some text", "some text".getBytes(), null, "some.txt"));
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    // step 5
    document.close();
}

From source file:questions.ocg.AddOptionalContentToExistingPdf.java

public static void main(String[] args) throws IOException, DocumentException {
    // creating an empty document
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT01));
    writer.setPdfVersion(PdfWriter.VERSION_1_5);
    document.open();//  www  .jav  a2s .  c o  m
    writer.setPageEmpty(false);
    document.close();

    PdfReader reader = new PdfReader(RESULT01);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT02));
    PdfContentByte cb = stamper.getOverContent(1);
    writer = stamper.getWriter();
    PdfLayer nested = new PdfLayer("Nested Layers", writer);
    PdfLayer nested_1 = new PdfLayer("Nested Layer 1", writer);
    PdfLayer nested_2 = new PdfLayer("Nested Layer 2", writer);
    PdfLayer layer21 = new PdfLayer("Layer 2", writer);
    PdfLayer layer22 = new PdfLayer("Layer 2", writer);
    nested_2.addChild(layer21);
    nested_2.addChild(layer22);
    nested.addChild(nested_1);
    nested.addChild(nested_2);
    cb.beginLayer(nested);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("nested layers"), 50, 775, 0);
    cb.endLayer();
    cb.beginLayer(nested_1);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("nested layer 1"), 100, 800, 0);
    cb.endLayer();
    cb.beginLayer(nested_2);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("nested layer 2"), 100, 750, 0);
    cb.endLayer();
    cb.beginLayer(layer21);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("layer 2.1 in the group"), 150, 775, 0);
    cb.endLayer();
    cb.beginLayer(layer22);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("layer 2.2 in the group"), 150, 725, 0);
    cb.endLayer();
    PdfLayer group = PdfLayer.createTitle("Grouped layers", writer);
    PdfLayer layer1 = new PdfLayer("Group: layer 1", writer);
    PdfLayer layer2 = new PdfLayer("Group: layer 2", writer);
    group.addChild(layer1);
    group.addChild(layer2);
    cb.beginLayer(layer1);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("layer 1 in the group"), 50, 700, 0);
    cb.endLayer();
    cb.beginLayer(layer2);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("layer 2 in the group"), 50, 675, 0);
    cb.endLayer();
    PdfLayer radiogroup = PdfLayer.createTitle("Radio Group", writer);
    PdfLayer radio1 = new PdfLayer("Radiogroup: layer 1", writer);
    radio1.setOn(true);
    PdfLayer radio2 = new PdfLayer("Radiogroup: layer 2", writer);
    radio2.setOn(false);
    PdfLayer radio3 = new PdfLayer("Radiogroup: layer 3", writer);
    radio3.setOn(false);
    radiogroup.addChild(radio1);
    radiogroup.addChild(radio2);
    radiogroup.addChild(radio3);
    ArrayList<PdfLayer> options = new ArrayList<PdfLayer>();
    options.add(radio1);
    options.add(radio2);
    options.add(radio3);
    writer.addOCGRadioGroup(options);
    cb.beginLayer(radio1);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("option 1"), 50, 600, 0);
    cb.endLayer();
    cb.beginLayer(radio2);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("option 2"), 50, 575, 0);
    cb.endLayer();
    cb.beginLayer(radio3);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("option 3"), 50, 550, 0);
    cb.endLayer();
    PdfLayer not_printed = new PdfLayer("not printed", writer);
    not_printed.setOnPanel(false);
    not_printed.setPrint("Print", false);
    cb.beginLayer(not_printed);
    ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase("PRINT THIS PAGE"), 300, 700, 90);
    cb.endLayer();
    PdfLayer zoom = new PdfLayer("Zoom 0.75-1.25", writer);
    zoom.setOnPanel(false);
    zoom.setZoom(0.75f, 1.25f);
    cb.beginLayer(zoom);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT,
            new Phrase("Only visible if the zoomfactor is between 75 and 125%"), 30, 530, 90);
    cb.endLayer();
    stamper.close();

    reader = new PdfReader(RESULT02);
    stamper = new PdfStamper(reader, new FileOutputStream(RESULT03));
    Map ocg = stamper.getPdfLayers();
    for (Iterator i = ocg.keySet().iterator(); i.hasNext();) {
        System.out.println(i.next());
    }
    PdfLayer layer = (PdfLayer) ocg.get("Layer 2");
    layer.setOn(false);
    cb = stamper.getOverContent(1);
    cb.beginLayer(layer);
    cb.moveTo(0, 0);
    cb.lineTo(500, 500);
    cb.stroke();
    cb.endLayer();
    PdfLayer parent = (PdfLayer) ocg.get("Layer 2(2)");
    PdfLayer newLayer = new PdfLayer("Child layer", stamper.getWriter());
    newLayer.setOn(false);
    parent.addChild(newLayer);
    cb.beginLayer(newLayer);
    cb.moveTo(0, 500);
    cb.lineTo(500, 0);
    cb.stroke();
    cb.endLayer();
    stamper.close();
}

From source file:questions.ocg.LockedLayers.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from  w  w w . j  a v  a2 s . c  o m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        writer.setPdfVersion(PdfWriter.VERSION_1_5);
        writer.setViewerPreferences(PdfWriter.PageModeUseOC);
        document.open();
        PdfContentByte cb = writer.getDirectContent();

        PdfLayer nested = new PdfLayer("Nested Layers", writer);
        PdfLayer nested_1 = new PdfLayer("Nested Layer 1", writer);
        PdfLayer nested_2 = new PdfLayer("Nested Layer 2", writer);
        nested.addChild(nested_1);
        nested.addChild(nested_2);
        cb.beginLayer(nested);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("nested layers"), 50, 775, 0);
        cb.endLayer();
        cb.beginLayer(nested_1);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("nested layer 1"), 100, 800, 0);
        cb.endLayer();
        cb.beginLayer(nested_2);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("nested layer 2"), 100, 750, 0);
        cb.endLayer();

        PdfLayer group = PdfLayer.createTitle("Grouped layers", writer);
        PdfLayer layer1 = new PdfLayer("Group: layer 1", writer);
        PdfLayer layer2 = new PdfLayer("Group: layer 2", writer);
        group.addChild(layer1);
        group.addChild(layer2);
        cb.beginLayer(layer1);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("layer 1 in the group"), 50, 700, 0);
        cb.endLayer();
        cb.beginLayer(layer2);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("layer 2 in the group"), 50, 675, 0);
        cb.endLayer();

        PdfLayer radiogroup = PdfLayer.createTitle("Radio Group", writer);
        PdfLayer radio1 = new PdfLayer("Radiogroup: layer 1", writer);
        radio1.setOn(true);
        PdfLayer radio2 = new PdfLayer("Radiogroup: layer 2", writer);
        radio2.setOn(false);
        PdfLayer radio3 = new PdfLayer("Radiogroup: layer 3", writer);
        radio3.setOn(false);
        radiogroup.addChild(radio1);
        radiogroup.addChild(radio2);
        radiogroup.addChild(radio3);
        ArrayList<PdfLayer> options = new ArrayList<PdfLayer>();
        options.add(radio1);
        options.add(radio2);
        options.add(radio3);
        writer.addOCGRadioGroup(options);
        cb.beginLayer(radio1);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("option 1"), 50, 600, 0);
        cb.endLayer();
        cb.beginLayer(radio2);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("option 2"), 50, 575, 0);
        cb.endLayer();
        cb.beginLayer(radio3);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("option 3"), 50, 550, 0);
        cb.endLayer();

        PdfLayer not_printed = new PdfLayer("not printed", writer);
        not_printed.setOnPanel(false);
        not_printed.setPrint("Print", false);
        cb.beginLayer(not_printed);
        ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase("PRINT THIS PAGE"), 300, 700, 90);
        cb.endLayer();

        PdfLayer zoom = new PdfLayer("Zoom 0.75-1.25", writer);
        zoom.setOnPanel(false);
        zoom.setZoom(0.75f, 1.25f);
        cb.beginLayer(zoom);
        ColumnText.showTextAligned(cb, Element.ALIGN_LEFT,
                new Phrase("Only visible if the zoomfactor is between 75 and 125%"), 30, 530, 90);
        cb.endLayer();

        writer.lockLayer(nested_1);
        writer.lockLayer(layer2);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    document.close();
}