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

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

Introduction

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

Prototype

PdfName DUPLEX

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

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  www.  j a  v a 2  s  .  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.sejda.impl.itext5.ViewerPreferencesTask.java

License:Open Source License

/**
 * //from  w  w w .  ja  v  a 2s  . com
 * @param parameters
 * @return a map of preferences with corresponding value to be set on the documents
 */
private Map<PdfName, PdfObject> getConfiguredViewerPreferencesMap(ViewerPreferencesParameters parameters) {
    Map<PdfName, PdfObject> confPreferences = new HashMap<PdfName, PdfObject>();
    if (parameters.getDirection() != null) {
        confPreferences.put(PdfName.DIRECTION, ViewerPreferencesUtils.getDirection(parameters.getDirection()));
    }
    if (parameters.getDuplex() != null) {
        confPreferences.put(PdfName.DUPLEX, ViewerPreferencesUtils.getDuplex(parameters.getDuplex()));
    }
    if (parameters.getPrintScaling() != null) {
        confPreferences.put(PdfName.PRINTSCALING,
                ViewerPreferencesUtils.getPrintScaling(parameters.getPrintScaling()));
    }
    confPreferences.put(PdfName.NONFULLSCREENPAGEMODE,
            ViewerPreferencesUtils.getNFSMode(parameters.getNfsMode()));

    Set<PdfBooleanPreference> activePref = parameters.getEnabledPreferences();
    for (PdfBooleanPreference boolPref : PdfBooleanPreference.values()) {
        if (activePref.contains(boolPref)) {
            confPreferences.put(ViewerPreferencesUtils.getBooleanPreference(boolPref), PdfBoolean.PDFTRUE);
        } else {
            confPreferences.put(ViewerPreferencesUtils.getBooleanPreference(boolPref), PdfBoolean.PDFFALSE);
        }
    }
    return confPreferences;
}