Example usage for com.itextpdf.text PageSize A4

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

Introduction

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

Prototype

Rectangle A4

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

Click Source Link

Document

This is the a4 format

Usage

From source file:com.incosyz.sms.pdfcontroller.ChequePDF.java

public void generateOrderPdf(ArrayList<CheckModel> checkModels, String filepath, String chequeDescription)
        throws FileNotFoundException, DocumentException {
    try {//from   w  ww.j  a  va2 s . co m
        String html = getHTML(checkModels, chequeDescription);

        Document document = new Document(PageSize.A4.rotate());

        File f = new File(filepath);
        FileOutputStream fileOutputStream = new FileOutputStream(f);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOutputStream);

        document.open();

        StringReader fileReader = new StringReader(html);
        XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, fileReader);

        document.close();
        fileOutputStream.close();
    } catch (IOException ex) {
        Logger.getLogger(ChequePDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.incosyz.sms.pdfcontroller.OrderPDF.java

public void sendPdf(ArrayList<GETOrderModel> gETOrderModels, String orderDescription)
        throws DocumentException, MessagingException {
    try {/*ww w . jav  a  2s. c  om*/
        String html = getHTML(gETOrderModels, orderDescription);

        Document document = new Document(PageSize.A4.rotate());

        String path = "./src/com/incosyz/sms/temp/tmporders.pdf";
        File f = new File(path);
        FileOutputStream fileOutputStream = new FileOutputStream(f);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOutputStream);

        document.open();

        StringReader fileReader = new StringReader(html);
        XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, fileReader);

        document.close();
        fileOutputStream.close();

        MailSender mailSender = new MailSender();
        MimeBodyPart body = (MimeBodyPart) mailSender.getBody();
        body.setText(html, "utf-8", "html");
        mailSender.setAttachmentPath(path);
        mailSender.setSubject(orderDescription);
        mailSender.sendMail();
    } catch (IOException ex) {
        Logger.getLogger(OrderPDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.incosyz.sms.pdfcontroller.OrderPDF.java

public void generateOrderPdf(ArrayList<GETOrderModel> gETOrderModels, String filepath, String orderDescription)
        throws FileNotFoundException, DocumentException {
    try {//from  w  ww  . java 2 s.  co m
        String html = getHTML(gETOrderModels, orderDescription);

        Document document = new Document(PageSize.A4.rotate());

        File f = new File(filepath);
        FileOutputStream fileOutputStream = new FileOutputStream(f);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOutputStream);

        document.open();

        StringReader fileReader = new StringReader(html);
        XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, fileReader);

        document.close();
        fileOutputStream.close();
    } catch (IOException ex) {
        Logger.getLogger(OrderPDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.innoq.iQpdfutil.Main.java

License:Open Source License

/**
 * This method adds a page number to all pages (except the first one)
 * from the given input pdf and writes the modified pdf to
 * the output-stream./*from   w w  w .ja va2  s . c  o  m*/
 *
 * <p>
 * The page number is placed in the center at the bottom of the page.
 * </p>
 *
 * <pre>
 *  +-----+
 *  |     |
 *  |     |
 *  |     |
 *  | -2- |
 *  +-----+
 * </pre>
 * */
private static void numberPages(PdfReader reader, OutputStream os) throws IOException, DocumentException {

    PdfStamper stamper = new PdfStamper(reader, os);

    try {
        int n = reader.getNumberOfPages();

        ColumnText text;
        PdfContentByte contents;
        Paragraph paragraph;
        Font headerFont = new Font(Font.FontFamily.COURIER, 12, Font.NORMAL);
        for (int i = 2; i <= n; i++) {
            contents = stamper.getOverContent(i);
            text = new ColumnText(contents);
            text.setSimpleColumn(1, 10, PageSize.A4.getWidth() - 1, 30, 1, Element.ALIGN_CENTER);
            paragraph = new Paragraph(String.format("- %d -", i), headerFont);
            paragraph.setAlignment(Element.ALIGN_CENTER);
            text.addElement(paragraph);
            text.go();
        }
    } finally {
        try {
            stamper.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.iox.rms.mbean.UserBean.java

@SuppressWarnings("deprecation")
private byte[] generateInvoiceForCustomerPurchase(CustomerProduct cp) {
    byte[] data = null;

    if (cp != null) {
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {/*from   w ww .j av a  2 s. com*/
            PdfWriter writer = PdfWriter.getInstance(document, baos);
            writer.setPageEvent(new HeaderFooter());
            writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788));
            if (!document.isOpen()) {
                document.open();
            }
            document.setPageSize(PageSize.A4);
            document.addAuthor("AutoLife");
            document.addCreationDate();
            document.addCreator("AutoLife");
            document.addSubject("Invoice");
            document.addTitle("Purchase Invoice");

            PdfPTable headerTable = new PdfPTable(3);

            ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance()
                    .getExternalContext().getContext();
            String logo = servletContext.getRealPath("") + File.separator + "images" + File.separator
                    + "sattrak-logo.png";
            PdfPCell c = new PdfPCell(Image.getInstance(logo));
            c.setBorder(0);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            headerTable.addCell(c);

            BaseFont helvetica = null;
            try {
                helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
            } catch (Exception e) {
            }
            Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD);
            c = new PdfPCell(new Paragraph("INVOICE", font));
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            c.setBorder(0);
            headerTable.addCell(c);

            font = new Font(helvetica, 10, Font.NORMAL | Font.BOLD);
            c = new PdfPCell(new Paragraph("TRANSACTION REF. NO.: " + cp.getPurchaseTranRef(), font));
            c.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            c.setBorder(0);
            headerTable.addCell(c);

            document.add(headerTable);

            font = new Font(helvetica, 12, Font.NORMAL | Font.BOLD);
            Paragraph p = new Paragraph("DETAILS", font);
            p.setAlignment(Paragraph.ALIGN_CENTER);
            document.add(p);

            PdfPTable pdfTable = new PdfPTable(3);

            font = new Font(helvetica, 8, Font.BOLDITALIC);
            pdfTable.addCell(new Paragraph("INITIATED DATE", font));
            pdfTable.addCell(new Paragraph("PRODUCT", font));
            pdfTable.addCell(new Paragraph("AMOUNT", font));
            font = new Font(helvetica, 8, Font.NORMAL);
            pdfTable.addCell(
                    new Paragraph(cp.getPurchaseTransaction().getTranInitDate().toLocaleString(), font));
            pdfTable.addCell(new Paragraph(cp.getProductBooked().getDetails(), font));
            pdfTable.addCell(new Paragraph("" + cp.getPurchasedAmount(), font));
            document.add(pdfTable);

            document.close();

            data = baos.toByteArray();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    return data;
}

From source file:com.isdemu.controller.BarCode128.java

public static void main(String[] args) throws FileNotFoundException, DocumentException {

    Document document = new Document(new Rectangle(PageSize.A4));
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:/Java4s_BarCode_128.pdf"));

    document.open();//from w w w .  j a v  a 2s . c  o m
    document.add(new Paragraph("Code_128 Format_Java4s.com"));

    Barcode128 code128 = new Barcode128();
    code128.setGenerateChecksum(true);
    code128.setCode("1234554321");

    document.add(code128.createImageWithBarcode(writer.getDirectContent(), null, null));
    document.close();

    System.out.println("Document Generated...!!!!!!");
}

From source file:com.iucosoft.eavertizare.util.Export.java

public static void toPdf(JFrame frame, JTable jTableClients, String firma) {

    Document document = new Document(PageSize.A4.rotate());
    try {/*from   w ww  .ja v a2s .  c  o  m*/
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setDialogTitle("Specify a file to save");

        int userSelection = fileChooser.showSaveDialog(frame);

        if (userSelection == JFileChooser.APPROVE_OPTION) {

            File fileToSave = fileChooser.getSelectedFile();
            System.out.println("Save as file: " + fileToSave.getAbsolutePath());
            PdfWriter.getInstance(document, new FileOutputStream(fileToSave.getAbsolutePath() + ".pdf"));

        }

        document.open();
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        Date date = new Date();

        if (firma.equals("All firms")) {

            addTitle(document, "Raport pentru toate firmele cu toti clienti \n din " + dateFormat.format(date));
        } else {

            addTitle(document, "Raport pentru " + firma + " \n din " + dateFormat.format(date));
        }

        addEmptyLine(document, new Paragraph(), 2);

        PdfPTable table = new PdfPTable(jTableClients.getColumnCount());
        table.setTotalWidth(jTableClients.getColumnCount() + 780);
        table.setLockedWidth(true);
        table.setHorizontalAlignment(Element.ALIGN_LEFT);

        for (int i = 0; i < table.getNumberOfColumns(); i++) {

            if (jTableClients.getColumnName(i).equals("")) {
                table.addCell("Trimis");
            } else {
                table.addCell(jTableClients.getColumnName(i));
            }
        }
        Object value;
        for (int i = 0; i < jTableClients.getRowCount(); i++) {
            for (int j = 0; j < table.getNumberOfColumns(); j++) {
                value = jTableClients.getValueAt(i, j);
                table.addCell(value.toString());
            }
        }
        document.add(table);
        document.close();

    } catch (DocumentException ex) {
        Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.jpsycn.print.util.PDFUtils.java

private static Document setHeader(File file, Context mContext, Font simfang12, Font simfangBlod12, String title,
        String sno) throws DocumentException, IOException {
    Document document = new Document(PageSize.A4, 30, 30, 20, 0);

    PdfWriter.getInstance(document, new FileOutputStream(file));
    document.open();/*from  w  ww .j a  v a2s .  com*/

    // 
    Font simhei18 = FontUtil.getFont(mContext, 18, "simhei.ttf");
    Paragraph b = new Paragraph(title, simhei18);
    b.setAlignment(Element.ALIGN_CENTER);
    document.add(b);
    // ?

    Chunk m1 = new Chunk("?", simfang12);
    Chunk m2 = new Chunk(sno, simfangBlod12);
    Paragraph p2 = new Paragraph();
    p2.add(m1);
    p2.add(m2);
    p2.setAlignment(Element.ALIGN_RIGHT);
    document.add(p2);
    return document;
}

From source file:com.khepry.frackhem.fxml.FracKhemGUIController.java

License:Apache License

private void saveTextAsPDF(String content, File file)
        throws FileNotFoundException, DocumentException, IOException, InterruptedException {
    Document document = new Document(PageSize.A4.rotate());
    PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(file));
    document.open();// w  w  w  .  j  a  v a  2  s .c o m
    document.addAuthor("Author of the Doc");
    document.addCreator("Creator of the Doc");
    document.addSubject("Subject of the Doc");
    document.addCreationDate();
    document.addTitle(file.getName());
    String html = htmlHeader.concat(markdown4jProcessor.process(content.trim()));
    //        XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, new ByteArrayInputStream(html.getBytes("UTF-8")), this.getClass().getResourceAsStream(cssFileFullPath));
    XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document,
            new ByteArrayInputStream(html.getBytes("UTF-8")));
    document.close();
    pdfWriter.close();
    displayFile(file.getAbsolutePath(), sleepMillis);
}

From source file:com.maxl.java.amikodesk.SaveBasket.java

License:Open Source License

public void generatePdf(Author author, String filename, String type) {
    // A4: 8.267in x 11.692in => 595.224units x 841.824units (72units/inch)

    // marginLeft, marginRight, marginTop, marginBottom
    Document document = new Document(PageSize.A4, 50, 50, 80, 50);
    try {//from   w  w w . j  a  v  a2s .  c om
        if (m_shopping_basket.size() > 0) {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
            writer.setBoxSize("art", new Rectangle(50, 50, 560, 790));

            HeaderFooter event = new HeaderFooter();
            writer.setPageEvent(event);

            document.open();

            PdfContentByte cb = writer.getDirectContent();

            document.addAuthor("ywesee GmbH");
            document.addCreator("AmiKo for Windows");
            document.addCreationDate();

            // Logo
            String logoImageStr = m_prefs.get(LogoImageID, Constants.IMG_FOLDER + "empty_logo.png");
            File logoFile = new File(logoImageStr);
            if (!logoFile.exists())
                logoImageStr = Constants.IMG_FOLDER + "empty_logo.png";

            Image logo = Image.getInstance(logoImageStr);
            logo.scalePercent(30);
            logo.setAlignment(Rectangle.ALIGN_RIGHT);
            document.add(logo);
            document.add(Chunk.NEWLINE);

            // Bestelladresse
            // --> String bestellAdrStr = m_prefs.get(BestellAdresseID, m_rb.getString("noaddress1")); 
            String bestellAdrStr = getAddressAsString(BestellAdresseID);
            Paragraph p = new Paragraph(12);
            // p.setIndentationLeft(60);
            p.add(new Chunk(bestellAdrStr, font_norm_10));
            document.add(p);
            document.add(Chunk.NEWLINE);

            // Title
            p = new Paragraph(m_rb.getString("order"), font_bold_16);
            document.add(p);

            // Date
            DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
            Date date = new Date();
            p = new Paragraph(m_rb.getString("date") + ": " + dateFormat.format(date), font_bold_10);
            p.setSpacingAfter(20);
            document.add(p);

            // document.add(Chunk.NEWLINE);

            // Add addresses (Lieferadresse + Rechnungsadresse)
            /* --> OLD
            String lieferAdrStr = m_prefs.get(LieferAdresseID, m_rb.getString("noaddress2"));
            String rechnungsAdrStr = m_prefs.get(RechnungsAdresseID, m_rb.getString("noaddress3"));              
            */
            // --> NEW
            String lieferAdrStr = getAddressAsString(LieferAdresseID);
            String rechnungsAdrStr = getAddressAsString(RechnungsAdresseID);

            PdfPTable addressTable = new PdfPTable(new float[] { 1, 1 });
            addressTable.setWidthPercentage(100f);
            addressTable.getDefaultCell().setPadding(5);
            addressTable.setSpacingAfter(5f);
            addressTable.addCell(getStringCell(m_rb.getString("shipaddress"), font_bold_10, PdfPCell.NO_BORDER,
                    Element.ALIGN_MIDDLE, 1));
            addressTable.addCell(getStringCell(m_rb.getString("billaddress"), font_bold_10, PdfPCell.NO_BORDER,
                    Element.ALIGN_MIDDLE, 1));
            addressTable.addCell(
                    getStringCell(lieferAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1));
            addressTable.addCell(
                    getStringCell(rechnungsAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1));
            document.add(addressTable);

            document.add(Chunk.NEWLINE);

            // Add shopping basket
            if (type.equals("specific"))
                document.add(getShoppingBasketForAuthor(author, cb));
            else if (type.equals("all"))
                document.add(getFullShoppingBasket(cb, "all"));
            else if (type.equals("rest"))
                document.add(getFullShoppingBasket(cb, "rest"));
            LineSeparator separator = new LineSeparator();
            document.add(separator);
        }
    } catch (IOException e) {

    } catch (DocumentException e) {

    }

    document.close();
    // System.out.println("Saved PDF to " + filename);
}