Example usage for com.itextpdf.text PageSize getRectangle

List of usage examples for com.itextpdf.text PageSize getRectangle

Introduction

In this page you can find the example usage for com.itextpdf.text PageSize getRectangle.

Prototype

public static Rectangle getRectangle(String name) 

Source Link

Document

This method returns a Rectangle based on a String.

Usage

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

private void createPdf(Map rpt, Map<String, String> i18n, File pdf) throws Exception {
    OutputStream out = new FileOutputStream(pdf);

    ThreadHelper.set("_fonts_", new HashMap<String, BaseFont>());
    ThreadHelper.set("_defaultFont_", BaseFont.createFont());

    String pageSize = MapUtil.getStr(rpt, "pageSize", "A4");
    int defaultFontSize = MapUtil.getInt(rpt, "defaultFontSize", 6);
    ThreadHelper.set("_defaultFontSize_", defaultFontSize);
    ThreadHelper.set("_rpt_", rpt);

    int i = pageSize.indexOf(';');
    String margins = "36 36 36 36";
    if (i > 0) {
        margins = pageSize.substring(i + 1);
        pageSize = pageSize.substring(0, i);
    }/*  w ww. j  av  a2  s. c  o m*/
    boolean rotate = false;
    if (pageSize.startsWith("@")) {
        rotate = true;
        pageSize = pageSize.substring(1);
    }
    Rectangle pSize = PageSize.getRectangle(pageSize);
    if (rotate)
        pSize = pSize.rotate();

    String mars[] = margins.split(" ");
    float ml = 0, mt = 0, mr = 0, mb = 0;
    mr = mt = mb = ml = LightUtil.decodeFloat(mars[0]);
    if (mars.length > 1) {
        mt = mb = LightUtil.decodeFloat(mars[1]);
    }
    if (mars.length > 2) {
        mr = LightUtil.decodeFloat(mars[2]);
    }
    if (mars.length > 3) {
        mb = LightUtil.decodeFloat(mars[3]);
    }
    Document doc = new Document(pSize, ml, mr, mt, mb);
    MapUtil.setIfStr(rpt, "author", doc, "addAuthor");
    MapUtil.setIfStr(rpt, "creator", doc, "addCreator");
    MapUtil.setIfStr(rpt, "title", doc, "addTitle");
    MapUtil.setIfStr(rpt, "keyWords", doc, "addKeywords");
    MapUtil.setIfStr(rpt, "subject", doc, "addSubject");

    PdfWriter writer = PdfWriter.getInstance(doc, out);
    writer.setPageEvent(this);
    writer.setStrictImageSequence(true);
    ThreadHelper.set("_writer_", writer);
    ThreadHelper.set("_doc_", doc);
    doc.open();

    List<Map> items = (List) rpt.get("items");
    for (Map row : items) {
        Element el = getElement(row);
        if (el != null)
            doc.add(el);
    }
    doc.close();
    out.close();
    writer.close();

    ThreadHelper.set("_writer_", null);
    ThreadHelper.set("_doc_", null);

}

From source file:org.ganttproject.impex.htmlpdf.itext.ThemeImpl.java

License:GNU General Public License

void run(IGanttProject project, UIFacade facade, OutputStream out) throws ExportException {
    myProject = project;/*w w  w .j  a va 2s  .  com*/
    myUIFacade = facade;
    Rectangle pageSize = PageSize.getRectangle(myPageSizeOption.getValue());
    if (myLandscapeOption.isChecked()) {
        pageSize = pageSize.rotate();
    }
    myDoc = new Document(pageSize, 20, 20, 70, 40);
    try {
        myWriter = PdfWriter.getInstance(myDoc, out);
        myWriter.setPageEvent(this);
        myDoc.open();
        writeProject();
    } catch (Throwable e) {
        e.printStackTrace();
        throw new ExportException("Export failed", e);
    } finally {
        myDoc.close();
    }
}

From source file:ro.nextreports.engine.exporter.PdfExporter.java

License:Apache License

protected void initExport() throws QueryException {
    Padding margins = bean.getReportLayout().getPagePadding();

    if (!bean.isSubreport()) {
        float footerHeight = computeFooterHeight();

        Rectangle rectangle;//  ww w.  j a  v  a 2s  . c o m
        if (ReportLayout.CUSTOM.equals(bean.getReportLayout().getPageFormat())) {
            PaperSize customSize = bean.getReportLayout().getPaperSize();
            rectangle = new Rectangle(customSize.getWidthPoints(), customSize.getHeightPoints());
        } else {
            rectangle = PageSize.getRectangle(bean.getReportLayout().getPageFormat());
        }

        document = new Document(rectangle, getPoints(margins.getLeft()), getPoints(margins.getRight()),
                getPoints(margins.getTop()), getPoints(margins.getBottom()) + footerHeight);
        if (bean.getReportLayout().getOrientation() == LANDSCAPE) {
            document.setPageSize(rectangle.rotate());
        }
    }
    PdfWriter wr = null;
    try {
        if (!bean.isSubreport()) {
            wr = PdfWriter.getInstance(document, getOut());
            wr.setPageEvent(new PdfPageEvent());
            addMetaData();
            document.open();
        }
        table = buildPdfTable(PRINT_DOCUMENT);

    } catch (DocumentException e) {
        e.printStackTrace();
        throw new QueryException(e);
    }
}

From source file:storybook.export.ExportPDF.java

public void open() {
    SbApp.trace("ExportPDF.open()");
    outDoc = new Document();
    Rectangle rectangle = new Rectangle(PageSize.getRectangle(parent.parent.paramExport.pdfPageSize));
    if (parent.parent.paramExport.pdfLandscape) {
        rectangle = new Rectangle(PageSize.getRectangle(parent.parent.paramExport.pdfPageSize).rotate());
    }//from  w  w w. j av  a 2  s .  c om
    outDoc.setPageSize(rectangle);
    try {
        writer = PdfWriter.getInstance(outDoc, new FileOutputStream(fileName));
    } catch (FileNotFoundException | DocumentException ex) {
        SbApp.error(ExportPDF.class.getName(), ex);
    }
    outDoc.open();

    addMetaData();
    try {
        outDoc.add(new Phrase(parent.bookTitle + " - " + parent.exportData.getKey() + "\n",
                FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD)));
    } catch (DocumentException ex) {
        SbApp.error("ExportPDF.open()", ex);
    }
    if (headers == null)
        return;
    float hsize[] = new float[headers.size()];
    int i = 0;
    for (ExportHeader header : headers) {
        hsize[i] = header.getSize();
        i++;
    }

    table = new PdfPTable(hsize);

    for (ExportHeader header : headers) {
        table.addCell(new Phrase(header.getName(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
    }
}