Example usage for com.itextpdf.text.pdf PdfName USEOC

List of usage examples for com.itextpdf.text.pdf PdfName USEOC

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfName USEOC.

Prototype

PdfName USEOC

To view the source code for com.itextpdf.text.pdf PdfName USEOC.

Click Source Link

Document

A name

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