Example usage for com.itextpdf.text.pdf PdfWriter PDF_VERSION_1_5

List of usage examples for com.itextpdf.text.pdf PdfWriter PDF_VERSION_1_5

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfWriter PDF_VERSION_1_5.

Prototype

PdfName PDF_VERSION_1_5

To view the source code for com.itextpdf.text.pdf PdfWriter PDF_VERSION_1_5.

Click Source Link

Document

possible PDF version (catalog)

Usage

From source file:com.vectorprint.report.itext.style.stylers.DocumentSettings.java

License:Open Source License

@Override
public final <E> E style(E element, Object data) throws VectorPrintException {
    document.setPageSize(new Rectangle(getValue(WIDTH, Float.class), getValue(HEIGHT, Float.class)));
    document.setMargins(getValue(ReportConstants.MARGIN.margin_left.name(), Float.class),
            getValue(ReportConstants.MARGIN.margin_right.name(), Float.class),
            getValue(ReportConstants.MARGIN.margin_top.name(), Float.class),
            getValue(ReportConstants.MARGIN.margin_bottom.name(), Float.class));
    writer.setPdfVersion(PdfWriter.PDF_VERSION_1_5);
    writer.addViewerPreference(PdfName.NONFULLSCREENPAGEMODE, PdfName.USEOC);
    writer.addViewerPreference(PdfName.PRINT, PdfName.DUPLEX);
    document.addProducer();/* w ww.j a  v  a  2s  .  c o  m*/
    document.addCreationDate();
    byte[] password = getValue(PASSWORD, byte[].class);
    byte[] userpassword = getValue(USER_PASSWORD, byte[].class);
    byte[] ownerpassword = getValue(OWNER_PASSWORD, byte[].class);
    if (userpassword == null) {
        userpassword = password;
    }
    if (ownerpassword == null) {
        ownerpassword = password;
    }
    int permissions = ((PermissionsParameter) getParameter(PERMISSIONS, PERMISSION[].class)).getPermission();
    ENCRYPTION encryption = getValue(ENCRYPTION_PARAM, ENCRYPTION.class);
    if (userpassword != null) {
        int enc = encryption != null ? encryption.encryption : PdfWriter.ENCRYPTION_AES_128;
        try {
            writer.setEncryption(userpassword, ownerpassword, permissions, enc);
            ArrayHelper.clear(password);
            ArrayHelper.clear(ownerpassword);
            ArrayHelper.clear(userpassword);
        } catch (DocumentException ex) {
            throw new VectorPrintException(ex);
        }
    } else if (getValue(CERTIFICATE, URL.class) != null) {
        int enc = encryption != null ? encryption.encryption : PdfWriter.ENCRYPTION_AES_128;
        try {
            writer.setEncryption(new Certificate[] { loadCertificate() }, new int[] { permissions }, enc);
        } catch (DocumentException ex) {
            throw new VectorPrintException(ex);
        }
    }

    for (PDFBOX b : PDFBOX.values()) {
        if (getValue(b.name(), float[].class) != null) {
            float[] size = getValue(b.name(), float[].class);
            writer.setBoxSize(b.name(), new Rectangle(size[0], size[1], size[2], size[3]));
        }
    }

    document.addSubject(getValue(SUBJECT, String.class));
    document.addAuthor(getValue(AUTHOR, String.class));
    document.addTitle(getValue(TITLE, String.class));
    document.addCreator(getValue(CREATOR, String.class));
    document.addKeywords(getValue(KEYWORDS, String.class));

    if (getValue(PDFA, Boolean.class)) {
        try {
            pdfA1A(writer);
        } catch (IOException | DocumentException ex) {
            throw new VectorPrintException(ex);
        }
    }
    writer.createXmpMetadata();

    return (E) document;
}

From source file:org.gephi.io.exporter.preview.PDFExporter.java

License:Open Source License

public boolean execute() {
    Progress.start(progress);/*from  w w w .j a v  a  2 s  . c o  m*/

    PreviewController controller = Lookup.getDefault().lookup(PreviewController.class);
    controller.getModel(workspace).getProperties().putValue(PreviewProperty.VISIBILITY_RATIO, 1.0);
    controller.refreshPreview(workspace);
    PreviewProperties props = controller.getModel(workspace).getProperties();

    Rectangle size = new Rectangle(pageSize);
    if (landscape) {
        size = new Rectangle(pageSize.rotate());
    }
    Color col = props.getColorValue(PreviewProperty.BACKGROUND_COLOR);
    size.setBackgroundColor(new BaseColor(col.getRed(), col.getGreen(), col.getBlue()));

    Document document = new Document(size);
    PdfWriter pdfWriter = null;
    try {
        pdfWriter = PdfWriter.getInstance(document, stream);
        pdfWriter.setPdfVersion(PdfWriter.PDF_VERSION_1_5);
        pdfWriter.setFullCompression();

    } catch (DocumentException ex) {
        Exceptions.printStackTrace(ex);
    }
    document.open();
    PdfContentByte cb = pdfWriter.getDirectContent();
    cb.saveState();

    props.putValue(PDFTarget.LANDSCAPE, landscape);
    props.putValue(PDFTarget.PAGESIZE, size);
    props.putValue(PDFTarget.MARGIN_TOP, new Float((float) marginTop));
    props.putValue(PDFTarget.MARGIN_LEFT, new Float((float) marginLeft));
    props.putValue(PDFTarget.MARGIN_BOTTOM, new Float((float) marginBottom));
    props.putValue(PDFTarget.MARGIN_RIGHT, new Float((float) marginRight));
    props.putValue(PDFTarget.PDF_CONTENT_BYTE, cb);
    target = (PDFTarget) controller.getRenderTarget(RenderTarget.PDF_TARGET, workspace);
    if (target instanceof LongTask) {
        ((LongTask) target).setProgressTicket(progress);
    }

    try {
        controller.render(target, workspace);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    cb.restoreState();
    document.close();

    Progress.finish(progress);

    props.putValue(PDFTarget.PDF_CONTENT_BYTE, null);
    props.putValue(PDFTarget.PAGESIZE, null);

    return !cancel;
}

From source file:view.SettingsDialog.java

License:Open Source License

private void loadSettings() {
    DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
    dcbm.addElement(PdfWriter.PDF_VERSION_1_2);
    dcbm.addElement(PdfWriter.PDF_VERSION_1_3);
    dcbm.addElement(PdfWriter.PDF_VERSION_1_4);
    dcbm.addElement(PdfWriter.PDF_VERSION_1_5);
    dcbm.addElement(PdfWriter.PDF_VERSION_1_6);
    dcbm.addElement(PdfWriter.PDF_VERSION_1_7);
    jComboBox1.setModel(dcbm);/*from  w  w  w  .  j  ava2  s . c o m*/

    String language = null;
    String renderQuality = null;
    String pdfVersion = null;
    String prefix = null;
    String signatureWidthString = null;
    String signatureHeightString = null;
    try {
        language = getConfigParameter("language");
        renderQuality = getConfigParameter("renderQuality");
        pdfVersion = getConfigParameter("pdfversion");
        prefix = getConfigParameter("prefix");
        signatureWidthString = getConfigParameter("signatureWidth");
        signatureHeightString = getConfigParameter("signatureHeight");
    } catch (IOException ex) {
        loadSettings();
        return;
    }

    if (pdfVersion == null || prefix == null || signatureWidthString == null || signatureHeightString == null) {
        loadSettings();
        return;
    }

    switch (language) {
    case "en-US":
        Bundle.getBundle().setCurrentLocale(Bundle.Locales.English);
        break;
    case "pt-PT":
        Bundle.getBundle().setCurrentLocale(Bundle.Locales.Portugues);
        break;
    default:
        Bundle.getBundle().setCurrentLocale(Bundle.Locales.English);
    }

    switch (Integer.valueOf(renderQuality)) {
    case 3:
        jComboBox2.setSelectedIndex(0);
        break;
    case 2:
        jComboBox2.setSelectedIndex(1);
        break;
    case 1:
        jComboBox2.setSelectedIndex(2);
        break;
    default:
        jComboBox2.setSelectedIndex(1);
    }

    switch (pdfVersion) {
    case "/1.2":
        jComboBox1.setSelectedIndex(0);
        break;
    case "/1.3":
        jComboBox1.setSelectedIndex(1);
        break;
    case "/1.4":
        jComboBox1.setSelectedIndex(2);
        break;
    case "/1.5":
        jComboBox1.setSelectedIndex(3);
        break;
    case "/1.6":
        jComboBox1.setSelectedIndex(4);
        break;
    case "/1.7":
        jComboBox1.setSelectedIndex(5);
        break;
    default:
        jComboBox1.setSelectedIndex(5);
    }
    int signatureWidth = Integer.parseInt(signatureWidthString);
    int signatureHeight = Integer.parseInt(signatureHeightString);
    tfPrefix.setText(prefix);
    tfHeight.setText(String.valueOf(signatureHeight));
    tfWidth.setText(String.valueOf(signatureWidth));
}