Example usage for com.lowagie.text DocWriter getISOBytes

List of usage examples for com.lowagie.text DocWriter getISOBytes

Introduction

In this page you can find the example usage for com.lowagie.text DocWriter getISOBytes.

Prototype


public static final byte[] getISOBytes(String text) 

Source Link

Document

Converts a String into a Byte array according to the ISO-8859-1 codepage.

Usage

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfDocumentWriter.java

License:Open Source License

public void open() throws DocumentException {
    this.document = new Document();
    // pageSize, marginLeft, marginRight, marginTop, marginBottom));

    writer = PdfWriter.getInstance(document, out);
    writer.setLinearPageMode();/*from   ww w . java2 s. c  o m*/

    version = getVersion();
    writer.setPdfVersion(version);
    writer.setViewerPreferences(getViewerPreferences());

    final String encrypt = config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Encryption");

    if (encrypt != null) {
        if (encrypt.equals(PdfPageableModule.SECURITY_ENCRYPTION_128BIT) == true
                || encrypt.equals(PdfPageableModule.SECURITY_ENCRYPTION_40BIT) == true) {
            final String userpassword = config.getConfigProperty(
                    "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.UserPassword");
            final String ownerpassword = config.getConfigProperty(
                    "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.OwnerPassword");
            // Log.debug ("UserPassword: " + userpassword + " - OwnerPassword: " + ownerpassword);
            final byte[] userpasswordbytes = DocWriter.getISOBytes(userpassword);
            byte[] ownerpasswordbytes = DocWriter.getISOBytes(ownerpassword);
            if (ownerpasswordbytes == null) {
                ownerpasswordbytes = PdfDocumentWriter.PDF_PASSWORD_PAD;
            }
            final int encryptionType;
            if (encrypt.equals(PdfPageableModule.SECURITY_ENCRYPTION_128BIT)) {
                encryptionType = PdfWriter.STANDARD_ENCRYPTION_128;
            } else {
                encryptionType = PdfWriter.STANDARD_ENCRYPTION_40;
            }
            writer.setEncryption(userpasswordbytes, ownerpasswordbytes, getPermissions(), encryptionType);
        }
    }

    /**
     * MetaData can be set when the writer is registered to the document.
     */
    final String title = config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Title",
            config.getConfigProperty("org.pentaho.reporting.engine.classic.core.metadata.Title"));
    final String subject = config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Description",
            config.getConfigProperty("org.pentaho.reporting.engine.classic.core.metadata.Description"));
    final String author = config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Author",
            config.getConfigProperty("org.pentaho.reporting.engine.classic.core.metadata.Author"));
    final String keyWords = config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Keywords",
            config.getConfigProperty("org.pentaho.reporting.engine.classic.core.metadata.Keywords"));

    if (title != null) {
        document.addTitle(title);
    }
    if (author != null) {
        document.addAuthor(author);
    }
    if (keyWords != null) {
        document.addKeywords(keyWords);
    }
    if (keyWords != null) {
        document.addSubject(subject);
    }

    document.addCreator(PdfDocumentWriter.CREATOR);
    document.addCreationDate();

    // getDocument().open();
    awaitOpenDocument = true;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.itext.PatchRtfCell.java

License:Open Source License

/**
 * Write the cell definition part of this PatchRtfCell
 *//*from   w w  w  . ja  v a  2s . co  m*/
public void writeDefinition(final OutputStream result) throws IOException {
    if (this.mergeType == MERGE_VERT_PARENT) {
        result.write(DocWriter.getISOBytes("\\clvmgf"));
    } else if (this.mergeType == MERGE_VERT_CHILD) {
        result.write(DocWriter.getISOBytes("\\clvmrg"));
    }
    switch (verticalAlignment) {
    case Element.ALIGN_BOTTOM:
        result.write(DocWriter.getISOBytes("\\clvertalb"));
        break;
    case Element.ALIGN_CENTER:
    case Element.ALIGN_MIDDLE:
        result.write(DocWriter.getISOBytes("\\clvertalc"));
        break;
    case Element.ALIGN_TOP:
        result.write(DocWriter.getISOBytes("\\clvertalt"));
        break;
    }
    this.borders.writeContent(result);

    if (this.backgroundColor != null) {
        result.write(DocWriter.getISOBytes("\\clcbpat"));
        result.write(intToByteArray(this.backgroundColor.getColorNumber()));
    }
    this.document.outputDebugLinebreak(result);

    result.write(DocWriter.getISOBytes("\\clftsWidth3"));
    this.document.outputDebugLinebreak(result);

    result.write(DocWriter.getISOBytes("\\clwWidth"));
    result.write(intToByteArray(this.cellWidth));
    this.document.outputDebugLinebreak(result);

    if (this.cellPadding > 0) {
        result.write(DocWriter.getISOBytes("\\clpadl"));
        result.write(intToByteArray(this.cellPadding / 2));
        result.write(DocWriter.getISOBytes("\\clpadt"));
        result.write(intToByteArray(this.cellPadding / 2));
        result.write(DocWriter.getISOBytes("\\clpadr"));
        result.write(intToByteArray(this.cellPadding / 2));
        result.write(DocWriter.getISOBytes("\\clpadb"));
        result.write(intToByteArray(this.cellPadding / 2));
        result.write(DocWriter.getISOBytes("\\clpadfl3"));
        result.write(DocWriter.getISOBytes("\\clpadft3"));
        result.write(DocWriter.getISOBytes("\\clpadfr3"));
        result.write(DocWriter.getISOBytes("\\clpadfb3"));
    }
    result.write(DocWriter.getISOBytes("\\cellx"));
    result.write(intToByteArray(this.cellRight));
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.itext.PatchRtfCell.java

License:Open Source License

/**
 * Write the content of this PatchRtfCell
 *//* www  . jav a2  s . c  o m*/
public void writeContent(final OutputStream result) throws IOException {
    if (this.content.size() == 0) {
        result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
        if (this.parentRow.getParentTable().getTableFitToPage()) {
            result.write(RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT);
        }
        result.write(RtfParagraph.IN_TABLE);
    } else {
        for (int i = 0; i < this.content.size(); i++) {
            RtfBasicElement rtfElement = this.content.get(i);
            if (rtfElement instanceof RtfParagraph) {
                ((RtfParagraph) rtfElement)
                        .setKeepTogetherWithNext(this.parentRow.getParentTable().getTableFitToPage());
            }
            rtfElement.writeContent(result);
            if (rtfElement instanceof RtfParagraph && i < (this.content.size() - 1)) {
                result.write(RtfParagraph.PARAGRAPH);
            }
        }
    }
    result.write(DocWriter.getISOBytes("\\cell"));
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.itext.PatchRtfCell.java

License:Open Source License

/**
 * Transforms an integer into its String representation and then returns the bytes of that string.
 *
 * @param i/*from w  w  w .  j a va 2  s.c  o m*/
 *          The integer to convert
 * @return A byte array representing the integer
 */
private byte[] intToByteArray(int i) {
    return DocWriter.getISOBytes(Integer.toString(i));
}