Example usage for com.lowagie.text PageSize A4

List of usage examples for com.lowagie.text PageSize A4

Introduction

In this page you can find the example usage for com.lowagie.text PageSize A4.

Prototype

Rectangle A4

To view the source code for com.lowagie.text PageSize A4.

Click Source Link

Document

This is the a4 format

Usage

From source file:org.kuali.kfs.module.purap.pdf.PurapPdf.java

License:Open Source License

/**
 * Creates an instance of a new Document and set its margins according to
 * the given input parameters./*  ww w.j a  v  a2  s.  co m*/
 *
 * @param f1  Left margin.
 * @param f2  Right margin.
 * @param f3  Top margin.
 * @param f4  Bottom margin.
 * @return    The created Document object.
 */
public Document getDocument(float f1, float f2, float f3, float f4) {
    LOG.debug("getDocument() started");
    Document document = new Document(PageSize.A4);
    // Margins: 36pt = 0.5 inch, 72pt = 1 inch. Left, right, top, bottom.
    document.setMargins(f1, f2, f3, f4);
    return document;
}

From source file:org.kuali.kfs.module.purap.pdf.PurchaseOrderQuoteRequestsPdf.java

License:Open Source License

/**
 * Creates an instance of a new Document and set its margins.
 * // ww w  . j  av  a  2  s.  c  o  m
 * @return    The created Document object.
 */
private Document getDocument() throws DocumentException {
    LOG.debug("getDocument() started");
    Document document = new Document(PageSize.A4);
    // Margins: 36pt = 0.5 inch, 72pt = 1 inch. Left, right, top, bottom.
    document.setMargins(9, 9, 25, 36);
    return document;
}

From source file:org.kuali.kfs.pdp.batch.service.impl.DailyReportServiceImpl.java

License:Educational Community License

protected Document openPdfWriter(String destinationDirectory, String fileprefix, Date runDate, String title) {
    try {//from  w w  w  .  j a  v  a 2 s . c o m
        Document document = new Document(PageSize.A4.rotate());

        PageHelper helper = new PageHelper();
        helper.runDate = runDate;
        helper.headerFont = headerFont;
        helper.title = title;

        String filename = destinationDirectory + "/" + fileprefix + "_";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
        filename = filename + sdf.format(runDate);
        filename = filename + ".pdf";
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        writer.setPageEvent(helper);

        document.open();

        return document;
    } catch (Exception e) {
        LOG.error("openPdfWriter() Exception caught trying to create new PDF document", e);
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new RuntimeException(e);
        }
    }
}

From source file:org.kuali.ole.describe.controller.EditorController.java

License:Open Source License

public Document getDocument(float f1, float f2, float f3, float f4) {
    Document document = new Document(PageSize.A4);
    document.setMargins(f1, f2, f3, f4);
    return document;
}

From source file:org.locationtech.udig.printing.ui.pdf.ExportPDFWizard.java

License:Open Source License

/**
 * converts a page size "name" (such as "A3" or "A4" into a 
 * rectangle object that iText will understand.
 *///  w ww .j av a2s.  c o  m
private Rectangle getITextPageSize(String pageSizeName) {
    if (pageSizeName.equals("A3")) //$NON-NLS-1$
        return PageSize.A3;
    if (pageSizeName.equals("A4")) //$NON-NLS-1$
        return PageSize.A4;
    throw new IllegalArgumentException(pageSizeName + " is not a supported page size"); //$NON-NLS-1$
}

From source file:org.locationtech.udig.printing.ui.pdf.PrintWizard.java

License:Open Source License

/**
 * converts a page size "name" (such as "A3" or "A4" into a 
 * rectangle object that iText will understand.
 *//*from w  w  w  .  j  a  v  a  2 s. co m*/
private Rectangle getITextPageSize(String pageSizeName) {
    if (pageSizeName.equals("A3")) //$NON-NLS-1$
        return PageSize.A3;
    if (pageSizeName.equals("A4")) //$NON-NLS-1$
        return PageSize.A4;
    if (pageSizeName.equals("Letter"))
        return PageSize.LETTER;
    throw new IllegalArgumentException(pageSizeName + " is not a supported page size"); //$NON-NLS-1$
}

From source file:org.mapfish.print.PdfTestCase.java

License:Open Source License

@Override
protected void setUp() throws Exception {
    super.setUp();
    PJsonObject spec = MapPrinter.parseSpec(FileUtilities.readWholeTextFile(new File("samples/spec.json")));
    spec.getInternalObj().put("units", "meters");

    doc = new Document(PageSize.A4);
    String baseDir = PdfTestCase.class.getClassLoader().getResource(".").getFile();
    outFile = new FileOutputStream(baseDir + getClass().getSimpleName() + "_" + getName() + ".pdf");
    writer = PdfWriter.getInstance(doc, outFile);
    writer.setFullCompression();//from w ww.  j a va  2  s  .  com
    createContext(spec);
    doc.setMargins(MARGIN, MARGIN, MARGIN, MARGIN * 3);
    doc.open();
    doc.newPage();
    final Paragraph title = new Paragraph("Test class=" + getClass().getName() + " method=" + getName());
    title.setSpacingAfter(20);
    doc.add(title);
}

From source file:org.meveo.admin.action.billing.BillingAccountBean.java

License:Open Source License

public void generatePDF(long invoiceId) {
    Invoice invoice = invoiceService.findById(invoiceId);
    byte[] invoicePdf = invoice.getPdf();
    FacesContext context = FacesContext.getCurrentInstance();
    String invoiceFilename = null;
    BillingRun billingRun = invoice.getBillingRun();
    invoiceFilename = invoice.getInvoiceNumber() + ".pdf";
    if (billingRun != null && billingRun.getStatus() != BillingRunStatusEnum.VALIDATED) {
        invoiceFilename = "unvalidated-invoice.pdf";
    }// w  w w  . jav a 2  s .co m

    HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
    response.setContentType("application/pdf"); // fill in
    response.setHeader("Content-disposition", "attachment; filename=" + invoiceFilename);

    try {
        OutputStream os = response.getOutputStream();
        Document document = new Document(PageSize.A4);
        if (billingRun != null && invoice.getBillingRun().getStatus() != BillingRunStatusEnum.VALIDATED) {
            // Add watemark image
            PdfReader reader = new PdfReader(invoicePdf);
            int n = reader.getNumberOfPages();
            PdfStamper stamp = new PdfStamper(reader, os);
            PdfContentByte over = null;
            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
            PdfGState gs = new PdfGState();
            gs.setFillOpacity(0.5f);
            int i = 1;
            while (i <= n) {
                over = stamp.getOverContent(i);
                over.setGState(gs);
                over.beginText();
                System.out.println("top=" + document.top() + ",bottom=" + document.bottom());
                over.setTextMatrix(document.top(), document.bottom());
                over.setFontAndSize(bf, 150);
                over.setColorFill(Color.GRAY);
                over.showTextAligned(Element.ALIGN_CENTER, "TEST", document.getPageSize().getWidth() / 2,
                        document.getPageSize().getHeight() / 2, 45);
                over.endText();
                i++;
            }

            stamp.close();
        } else {
            os.write(invoicePdf); // fill in PDF with bytes
        }

        // contentType
        os.flush();
        os.close();
        context.responseComplete();
    } catch (IOException e) {
        log.error("failed to generate PDF ", e);
    } catch (DocumentException e) {
        log.error("error in generation PDF ", e);
    }
}

From source file:org.netxilia.server.rest.pdf.SheetPdfProvider.java

License:Open Source License

@Override
public void writeTo(SheetFullName sheetName, Class<?> clazz, Type type, Annotation[] ann, MediaType mediaType,
        MultivaluedMap<String, Object> headers, OutputStream out) throws IOException, WebApplicationException {

    if (sheetName == null) {
        return;//from  w ww.  j  a v a  2  s .c  o m
    }

    /**
     * This is the table, added as an Element to the PDF document. It contains all the data, needed to represent the
     * visible table into the PDF
     */
    Table tablePDF;

    /**
     * The default font used in the document.
     */
    Font smallFont = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.NORMAL, new Color(0, 0, 0));
    ISheet summarySheet = null;
    ISheet sheet = null;
    try {
        sheet = workbookProcessor.getWorkbook(sheetName.getWorkbookId()).getSheet(sheetName.getSheetName());
        try {
            // get the corresponding summary sheet
            SheetFullName summarySheetName = SheetFullName.summarySheetName(sheetName,
                    userService.getCurrentUser());
            summarySheet = workbookProcessor.getWorkbook(summarySheetName.getWorkbookId())
                    .getSheet(summarySheetName.getSheetName());

        } catch (Exception e) {
            // no summary sheet - go without one
        }

        // Initialize the Document and register it with PdfWriter listener and the OutputStream
        Document document = new Document(PageSize.A4.rotate(), 60, 60, 40, 40);
        document.addCreationDate();
        HeaderFooter footer = new HeaderFooter(new Phrase("", smallFont), true);
        footer.setBorder(Rectangle.NO_BORDER);
        footer.setAlignment(Element.ALIGN_CENTER);

        PdfWriter.getInstance(document, out);

        // Fill the virtual PDF table with the necessary data
        // Initialize the table with the appropriate number of columns
        tablePDF = initTable(sheet);
        // take tha maximum numbers of columns
        int columnCount = sheet.getDimensions().getNonBlocking().getColumnCount();
        if (summarySheet != null) {
            columnCount = Math.max(columnCount, summarySheet.getDimensions().getNonBlocking().getColumnCount());
        }
        generateHeaders(sheet, tablePDF, smallFont, columnCount);

        tablePDF.endHeaders();
        generateRows(sheet, false, tablePDF, smallFont, columnCount);
        if (summarySheet != null) {
            generateRows(summarySheet, true, tablePDF, smallFont, columnCount);
        }

        document.open();
        document.setFooter(footer);
        document.add(tablePDF);
        document.close();

        out.flush();
        out.close();

    } catch (Exception e) {
        throw new IOException(e);
    }
}

From source file:org.openconcerto.erp.generationDoc.SheetUtils.java

License:Open Source License

public static void convert2PDF(final OpenDocument doc, final File pdfFileToCreate) throws Exception {
    assert (!SwingUtilities.isEventDispatchThread());
    // Open the PDF document
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    try {//from   ww w.j a  v a  2 s .c  om

        FileOutputStream fileOutputStream = new FileOutputStream(pdfFileToCreate);

        // Create the writer
        PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream);
        writer.setPdfVersion(PdfWriter.VERSION_1_6);
        writer.setFullCompression();

        document.open();

        PdfContentByte cb = writer.getDirectContent();

        // Configure the renderer
        ODTRenderer renderer = new ODTRenderer(doc);
        renderer.setIgnoreMargins(false);
        renderer.setPaintMaxResolution(true);

        // Scale the renderer to fit width
        renderer.setResizeFactor(renderer.getPrintWidth() / document.getPageSize().getWidth());

        // Print pages
        for (int i = 0; i < renderer.getPrintedPagesNumber(); i++) {

            Graphics2D g2 = cb.createGraphics(PageSize.A4.getWidth(), PageSize.A4.getHeight());

            // If you want to prevent copy/paste, you can use
            // g2 = tp.createGraphicsShapes(w, h, true, 0.9f);

            // Render
            renderer.setCurrentPage(i);
            renderer.paintComponent(g2);
            g2.dispose();

            // Add our spreadsheet in the middle of the page
            if (i < renderer.getPrintedPagesNumber() - 1)
                document.newPage();

        }
        // Close the PDF document
        document.close();
        // writer.close();
        fileOutputStream.close();

    } catch (Exception originalExn) {
        ExceptionHandler.handle("Impossible de crer le PDF " + pdfFileToCreate.getAbsolutePath(),
                originalExn);
    }

}