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

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

Introduction

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

Prototype

char VERSION_1_2

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

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//  www.  j  a  va 2 s.c  o  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.adempiere.pdf.Document.java

License:Open Source License

private static void writePDF(Pageable pageable, OutputStream output) {
    try {// w  w  w.  j  a  v a  2 s .  c o m
        final PageFormat pf = pageable.getPageFormat(0);

        final com.lowagie.text.Document document = new com.lowagie.text.Document(
                new Rectangle((int) pf.getWidth(), (int) pf.getHeight()));
        final PdfWriter writer = PdfWriter.getInstance(document, output);
        writer.setPdfVersion(PdfWriter.VERSION_1_2);
        document.open();
        final DefaultFontMapper mapper = new DefaultFontMapper();

        //Elaine 2009/02/17 - load additional font from directory set in PDF_FONT_DIR of System Configurator 
        String pdfFontDir = MSysConfig.getValue(PDF_FONT_DIR, "");
        if (pdfFontDir != null && pdfFontDir.trim().length() > 0) {
            pdfFontDir = pdfFontDir.trim();
            File dir = new File(pdfFontDir);
            if (dir.exists() && dir.isDirectory())
                mapper.insertDirectory(pdfFontDir);
        }
        //

        final float w = (float) pf.getWidth();
        final float h = (float) pf.getHeight();
        final PdfContentByte cb = writer.getDirectContent();
        for (int page = 0; page < pageable.getNumberOfPages(); page++) {
            if (page != 0) {
                document.newPage();
            }

            final PdfTemplate tp = cb.createTemplate(w, h);
            final Graphics2D g2 = tp.createGraphics(w, h, mapper);
            tp.setWidth(w);
            tp.setHeight(h);
            pageable.getPrintable(page).print(g2, pf, page);
            g2.dispose();
            cb.addTemplate(tp, 0, 0);
        }
        document.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.adempiere.util.Document.java

private static void writePDF(Pageable pageable, OutputStream output) {
    try {//w ww  .  j a v  a  2  s .co m
        final PageFormat pf = pageable.getPageFormat(0);

        Rectangle pageSize = new Rectangle((int) pf.getWidth(), (int) pf.getHeight());
        final com.lowagie.text.Document document = new com.lowagie.text.Document(pageSize);
        final PdfWriter writer = PdfWriter.getInstance(document, output);
        writer.setPdfVersion(PdfWriter.VERSION_1_2);
        document.open();
        final DefaultFontMapper mapper = new DefaultFontMapper();

        String pdfFontDir = /* MSysConfig.getValue( */PDF_FONT_DIR/* , "") */;
        if (pdfFontDir != null && pdfFontDir.trim().length() > 0) {
            pdfFontDir = pdfFontDir.trim();
            File dir = new File(pdfFontDir);
            if (dir.exists() && dir.isDirectory())
                mapper.insertDirectory(pdfFontDir);
        }
        final float w = (float) pf.getWidth();
        final float h = (float) pf.getHeight();
        final PdfContentByte cb = writer.getDirectContent();
        for (int page = 0; page < pageable.getNumberOfPages(); page++) {
            if (page != 0) {
                document.newPage();
            }

            final PdfTemplate tp = cb.createTemplate(w, h);
            final Graphics2D g2 = tp.createGraphics(w, h, mapper);
            tp.setWidth(w);
            tp.setHeight(h);
            pageable.getPrintable(page).print(g2, pf, page);
            g2.dispose();
            cb.addTemplate(tp, 0, 0);
        }
        document.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

License:Open Source License

/**
 * @param version//  w w  w  .ja v a  2s .c o  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:se.idega.idegaweb.commune.school.business.StudentAddressLabelsWriter.java

License:Open Source License

/**
 * Creates PDF address labels for the specified school classes.
 *//*  www.jav  a  2 s . c om*/
protected MemoryFileBuffer getPDFBuffer(IWApplicationContext iwac, Collection receivers) throws Exception {
    this.business = getSchoolCommuneBusiness(iwac);
    this.userBusiness = getCommuneUserBusiness(iwac);

    IWResourceBundle iwrb = iwac.getIWMainApplication().getBundle(CommuneBlock.IW_BUNDLE_IDENTIFIER)
            .getResourceBundle(iwac.getApplicationSettings().getApplicationLocale());

    MemoryFileBuffer buffer = new MemoryFileBuffer();
    MemoryOutputStream mos = new MemoryOutputStream(buffer);

    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    PdfWriter writer = PdfWriter.getInstance(document, mos);

    document.addTitle("Student address labels");
    document.addAuthor("Idega Reports");
    document.addSubject("Student address labels");
    document.open();

    this.font = new Font(Font.HELVETICA, 9, Font.BOLD);

    int studentCount = 0;

    Iterator iter = receivers.iterator();
    while (iter.hasNext()) {
        if (studentCount > 0 && studentCount % NR_OF_ADDRESSES_PER_PAGE == 0) {
            document.newPage();
        }

        addAddress(writer, iwrb, (MailReceiver) iter.next(), studentCount++);
    }

    if (studentCount == 0) {
        throw new Exception("No students.");
    }

    document.close();

    writer.setPdfVersion(PdfWriter.VERSION_1_2);
    buffer.setMimeType(MIME_PDF);
    return buffer;
}

From source file:se.idega.idegaweb.commune.school.report.business.ReportPDFWriter.java

License:Open Source License

private MemoryFileBuffer getPDFBuffer() throws DocumentException {
    MemoryFileBuffer buffer = new MemoryFileBuffer();
    MemoryOutputStream mos = new MemoryOutputStream(buffer);

    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    PdfWriter writer = PdfWriter.getInstance(document, mos);

    String titleKey = this._reportModel.getReportTitleLocalizationKey();
    String title = localize(titleKey, titleKey);
    this._normalFont = new Font(Font.HELVETICA, 7, Font.NORMAL);
    this._boldFont = new Font(Font.HELVETICA, 7, Font.BOLD);

    document.addTitle(title);/*from   w  w  w  .j a va 2  s  .c o  m*/
    document.addAuthor("Agura IT Reports");
    document.addSubject(title);
    document.open();

    String dateString = new Date(System.currentTimeMillis()).toString();

    document.add(new Phrase(title + " " + dateString + "\n\n", this._boldFont));
    document.add(new Phrase("\n", this._boldFont));

    int cols = this._reportModel.getColumnSize() + 1;
    Table table = new Table(cols);
    this._widths = new int[cols];
    for (int i = 0; i < cols; i++) {
        this._widths[i] = 1;
    }

    table.setSpacing(1.5f);

    buildColumnHeaders(table);
    buildRowHeaders(table);
    buildReportCells(table);

    int totalWidth = 0;
    for (int i = 0; i < cols; i++) {
        this._widths[i] += 1;
        totalWidth += this._widths[i];
    }
    int width = (100 * totalWidth) / 95;
    if (width > 100) {
        width = 100;
    }
    table.setWidth(width);
    table.setWidths(this._widths);
    document.add(table);
    document.close();
    writer.setPdfVersion(PdfWriter.VERSION_1_2);

    return buffer;
}