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

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

Introduction

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

Prototype

public void setPdfVersion(PdfName version) 

Source Link

Usage

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

License:Open Source License

/**
 * Creates PDF address labels for the specified school classes.
 *//* w w w.j av  a2  s  . c  o m*/
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 ww . ja va2  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;
}