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:privilege.mouchard.MouchardCtrl.java

@Override
public void imprimerTraceurPdf() {
    try {/*from ww  w .j  a v  a2 s .c  om*/

    } catch (Exception e) {

        Personnel user = UtilitaireSession.getInstance().getuser();
        if (user != null) {
            String fichier = "Liste_actionUtilisateur du " + new Date() + "_.pdf";
            Document mouchard = new Document();
            try {
                PdfWriter.getInstance(mouchard, new FileOutputStream(Utilitaires.path + "/" + fichier));
                mouchard.setMargins(5, 5, 5, 5);
                mouchard.addCreator("School Manager");
                mouchard.setPageSize(PageSize.A4);

                mouchard.open();

                if (!getTraceurs().isEmpty()) {

                    PdfPTable table = new PdfPTable(6);
                    table.setComplete(true);

                    table.addCell(PrintUtils.createPdfPCell("Liste des actions utilisateur", 6, detail));

                    table.addCell(new Paragraph("Nom"));
                    table.addCell(PrintUtils.createPdfPCell("Prnom ", true));
                    table.addCell(PrintUtils.createPdfPCell("Action ", 3, true));
                    table.addCell(PrintUtils.createPdfPCell("Date", true));

                    for (int i = 0; i < getTraceurs().size(); i++) {

                    }

                    JsfUtil.addSuccessMessage("Liste cre avec succs !");
                }
                mouchard.close();
            } catch (DocumentException | FileNotFoundException ex) {
                Logger.getLogger(MouchardCtrl.class.getName()).log(Level.SEVERE, null, ex);
            }

        } else {
            JsfUtil.addWarningMessage("Aucune session utilisateur initie !");
        }
    }
}

From source file:probe.com.model.util.vaadintoimageutil.A4PdfDocumentHandler.java

public final void setPageSize(Rectangle pageSize) {
    if (pageSize == PageSize.A4) {
        document.setPageSize(pageSize);//from  w  w  w .  j  a  v a 2s  .  co  m
        width = 595;
        height = 842;

    } else {
        document.setPageSize(pageSize);
        height = 595;
        width = 842;
    }
}

From source file:PROCESOS.ImprimirPDF.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/pdf");
    String precio_unitario = request.getParameter("precio");

    String id_vale = request.getParameter("codigo");

    //  if(request.getParameter("codigo")!=null){
    OutputStream salida = response.getOutputStream();
    try {//w  w w . j  av  a2s .  c  o m

        try {

            DTO.ClaseTransaccion clase = new ClaseTransaccion();
            clase = consulta.Transaccion();
            Document documento = new Document(PageSize.A4, 36, 36, 45, 20);
            PdfWriter pw = PdfWriter.getInstance(documento, salida);
            documento.open();
            Paragraph parrafo1 = new Paragraph();
            Font font_titulo = new Font(Font.FontFamily.HELVETICA, 16, Font.UNDERLINE, BaseColor.BLACK);
            parrafo1.add(new Phrase("TecnoBencina, COMPROBANTE", font_titulo));
            parrafo1.setAlignment(Element.ALIGN_CENTER);
            parrafo1.add(new Phrase(Chunk.NEWLINE));
            parrafo1.add(new Phrase(Chunk.NEWLINE));
            documento.add(parrafo1);

            Paragraph parrafo2 = new Paragraph();
            Font font_titulo_p2 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK);

            if (id_vale.length() > 0) {
                parrafo2.add(new Phrase("Comprobante de transaccion : codigo del vale : " + id_vale,
                        font_titulo_p2));
            } else {
                parrafo2.add(new Phrase("Comprobante de transaccion ", font_titulo_p2));
            }

            parrafo2.setAlignment(Element.ALIGN_JUSTIFIED);
            parrafo2.add(new Phrase(Chunk.NEWLINE));
            parrafo2.add(new Phrase(Chunk.NEWLINE));
            parrafo2.add(new Phrase(Chunk.NEWLINE));
            documento.add(parrafo2);

            PdfPTable tabla = new PdfPTable(9);
            PdfPCell celda1 = new PdfPCell(new Paragraph("ID transaccion ",
                    FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda2 = new PdfPCell(
                    new Paragraph("Estado ", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda3 = new PdfPCell(new Paragraph("ID de surtidor",
                    FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda4 = new PdfPCell(
                    new Paragraph("Litros", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda5 = new PdfPCell(
                    new Paragraph("Monto", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda6 = new PdfPCell(
                    new Paragraph("Fecha", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda7 = new PdfPCell(
                    new Paragraph("ID pago", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda8 = new PdfPCell(new Paragraph("Precio unitario",
                    FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));

            tabla.addCell(celda1);
            tabla.addCell(celda2);
            tabla.addCell(celda3);
            tabla.addCell(celda4);
            tabla.addCell(celda5);
            tabla.addCell(celda6);
            tabla.addCell(celda7);
            tabla.addCell(celda8);

            tabla.addCell(String.valueOf(clase.getId_transaccion()));
            tabla.addCell(clase.getEstado());
            tabla.addCell(String.valueOf(clase.getId_transaccion()));
            tabla.addCell(String.valueOf(clase.getLitros()));
            tabla.addCell(String.valueOf(clase.getMonto()));
            tabla.addCell(String.valueOf(clase.getFecha()));
            tabla.addCell(String.valueOf(clase.getId_pago()));
            tabla.addCell(precio_unitario);

            documento.add(tabla);
            documento.addAuthor("TecnoBencina");
            documento.addTitle("Comprobante");
            documento.addLanguage("Espaol");
            documento.add(new Paragraph(new Phrase(Chunk.NEWLINE)));
            documento.add(new Paragraph(new Phrase(Chunk.NEWLINE)));

            documento.add(new Paragraph(new Phrase(Chunk.NEWLINE)));
            documento.add(new Paragraph(new Phrase(Chunk.NEWLINE)));
            documento.add(new Paragraph("texto....", font_titulo_p2));
            documento.close();
        } catch (Exception s) {
            s.getMessage();
        }

    } catch (Exception s) {
        System.out.println("" + s.getMessage());
    } finally {
        salida.close();
    }
    // }
}

From source file:projetohorus.DadosColetadosPDF.java

void GerarPDF() throws IOException, DocumentException, EmailException {
    Document doc = null;//from   ww  w .  ja  v  a 2 s  .  co  m
    OutputStream os = null;

    try {
        doc = new Document(PageSize.A4, 72, 72, 72, 72);
        os = new FileOutputStream("tesfinal11.pdf");
        PdfWriter.getInstance(doc, os);
        doc.open();
        Image img = Image.getInstance("LogoProject.png");
        img.setAlignment(Element.ALIGN_CENTER);

        doc.add(img);

        InetAddress localHost = Inet4Address.getLocalHost();
        NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost);
        short x = networkInterface.getInterfaceAddresses().get(0).getNetworkPrefixLength();
        String n = localHost.getHostAddress() + "/" + x;
        SubnetUtils utils = new SubnetUtils(n);
        ;

        PdfPTable table = new PdfPTable(new float[] { 0.50f, 0.70f, 0.90f });

        table = new PdfPTable(3);

        Paragraph p = new Paragraph("");
        p.setAlignment(Element.ALIGN_CENTER);
        p.setSpacingAfter(30);
        doc.add(p);
        p = new Paragraph("Informaes da Network");
        p.setAlignment(Element.ALIGN_CENTER);
        p.setSpacingAfter(30);

        doc.add(p);
        Paragraph paragraph = new Paragraph("" + utils.getInfo());
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setSpacingAfter(30);
        doc.add(paragraph);
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        PdfPCell header = new PdfPCell(new Paragraph("Diagnostico do Scanner da Rede"));
        header.setColspan(3);
        table.addCell(header);
        table.addCell("IP");
        table.addCell("HostName");
        table.addCell("Portas Abertas");
        for (int i = 0; i < IP.size(); i++) {

            table.addCell(IP.get(i));
            table.addCell(NameHost.get(i));
            table.addCell("" + PortasA.get(i));
        }
        doc.add(table);

    } finally {
        if (doc != null) {

            doc.close();
        }
        if (os != null) {

            os.close();
        }

    }
    EnvioEmail sc = new EnvioEmail();
    sc.EnvioEmail();

}

From source file:psManage.StructSheet.java

public void createPdf(String mainTitle, String subTitle, String url, String userName,
        //String scanType,
        String comment,//from   www  .  j a v a2 s  .co m
        //String thisPassCode,
        String passCodeA, String passCodeB, String fileDir, Boolean noBarCodePrint)
        throws IOException, DocumentException, RuntimeException {
    Document document = null;
    try {
        // step 1
        document = new Document(PageSize.A4, 60, 50, 50, 35);
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileDir));
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        /*
         Properties props = new Properties();
         String jarPath = System.getProperty("java.class.path");
         String dirPath = jarPath.substring(0, jarPath.lastIndexOf(File.separator)+1);
         FontFactory.registerDirectory("/res");
         FontFactory.register("ipag.ttf");
         Font ipaGothic = FontFactory.getFont("ipag", BaseFont.IDENTITY_H, 
         BaseFont.EMBEDDED, 10); //10 is the size
                
         InputStream is = getClass().getResourceAsStream("/res/ipag.ttf");
         */

        Properties props = new Properties();
        String jarPath = System.getProperty("java.class.path");
        String dirPath = jarPath.substring(0, jarPath.lastIndexOf(File.separator) + 1);
        System.out.println(jarPath);
        System.out.println(dirPath);
        System.out.println(System.getProperty("user.dir"));

        Font ipaGothic = new Font(BaseFont.createFont(System.getProperty("user.dir") + "\\res\\ipag.ttf",
                BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 11);

        Font ipaGothic14 = new Font(BaseFont.createFont(System.getProperty("user.dir") + "\\res\\ipag.ttf",
                BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 14);

        //?(2)
        PdfPTable pdfPTable = new PdfPTable(2);

        pdfPTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
        pdfPTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        pdfPTable.getDefaultCell().setFixedHeight(150);

        pdfPTable.setWidthPercentage(100f);

        int pdfPTableWidth[] = { 10, 90 };
        pdfPTable.setWidths(pdfPTableWidth);

        PdfPCell cell_1_1 = new PdfPCell(new Paragraph("??", ipaGothic));
        cell_1_1.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell_1_1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell_1_1.setFixedHeight(50);
        PdfPCell cell_1_2 = new PdfPCell(new Paragraph(mainTitle, ipaGothic));
        cell_1_2.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell_1_2.setHorizontalAlignment(Element.ALIGN_CENTER);

        PdfPCell cell_2_1 = new PdfPCell(new Paragraph("", ipaGothic));
        cell_2_1.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell_2_1.setHorizontalAlignment(Element.ALIGN_CENTER);
        PdfPCell cell_2_2 = new PdfPCell(new Paragraph(subTitle, ipaGothic));
        cell_2_2.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell_2_2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell_2_2.setFixedHeight(50);
        pdfPTable.addCell(cell_1_1);
        pdfPTable.addCell(cell_1_2);
        pdfPTable.addCell(cell_2_1);
        pdfPTable.addCell(cell_2_2);

        PdfPCell cellUrlKey = new PdfPCell(new Paragraph("?", ipaGothic));
        cellUrlKey.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellUrlKey.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellUrlKey.setRowspan(2);
        pdfPTable.addCell(cellUrlKey);

        PdfPCell cellUrlValue = new PdfPCell(new Paragraph(url, ipaGothic));
        Chunk chunk = new Chunk(url, ipaGothic); // ??????????????
        System.out.println("??" + chunk.getWidthPoint());
        cellUrlValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
        if (chunk.getWidthPoint() > 410) { // ??????????
            cellUrlValue.setHorizontalAlignment(Element.ALIGN_LEFT);
        } else { // ?????????
            cellUrlValue.setHorizontalAlignment(Element.ALIGN_CENTER);
        }

        cellUrlValue.setFixedHeight(50);
        pdfPTable.addCell(cellUrlValue);

        if (url.length() != 0 && !noBarCodePrint) {
            /* ?
             BarcodeQRCode qr = new BarcodeQRCode(url, 50, 50, null);
             PdfPCell cellUrlValueQr = new PdfPCell(qr.getImage());
             cellUrlValueQr.setVerticalAlignment(Element.ALIGN_MIDDLE);
             cellUrlValueQr.setHorizontalAlignment(Element.ALIGN_CENTER);
             cellUrlValueQr.setFixedHeight(80);
             pdfPTable.addCell(cellUrlValueQr);
             */
            Image image = ZxingUti.getQRCode(url); //  SHIFT_JIS
            com.itextpdf.text.Image iTextImage = com.itextpdf.text.Image.getInstance(image, null);
            PdfPCell cell = new PdfPCell(iTextImage);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setFixedHeight(100);
            pdfPTable.addCell(cell); //  SIFT_JIS
        } else {
            PdfPCell cellUrlValueQr = new PdfPCell(new Paragraph("", ipaGothic));
            cellUrlValueQr.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellUrlValueQr.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellUrlValueQr.setFixedHeight(80);
            pdfPTable.addCell(cellUrlValueQr);
        }

        PdfPCell cellUserNameKey = new PdfPCell(new Paragraph("", ipaGothic));
        cellUserNameKey.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellUserNameKey.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellUserNameKey.setRowspan(2);
        pdfPTable.addCell(cellUserNameKey);

        PdfPCell cellUserNameValue = new PdfPCell(new Paragraph(userName, ipaGothic14));
        cellUserNameValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellUserNameValue.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellUserNameValue.setFixedHeight(30);
        pdfPTable.addCell(cellUserNameValue);

        if (userName.length() != 0 && !noBarCodePrint) {
            Barcode128 code128 = new Barcode128();
            code128.setCode(userName);
            code128.setFont(ipaGothic.getBaseFont());
            code128.setBarHeight(40f);
            PdfPCell cellUserNameValueBc = new PdfPCell(code128.createImageWithBarcode(cb, null, null));
            cellUserNameValueBc.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellUserNameValueBc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellUserNameValueBc.setFixedHeight(80);
            pdfPTable.addCell(cellUserNameValueBc);
        } else {
            PdfPCell cellUserNameValueBc = new PdfPCell(new Paragraph("---", ipaGothic));
            cellUserNameValueBc.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellUserNameValueBc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellUserNameValueBc.setFixedHeight(80);
            pdfPTable.addCell(cellUserNameValueBc);
        }

        PdfPCell cellPassCodeKey = new PdfPCell(new Paragraph("?", ipaGothic));
        cellPassCodeKey.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellPassCodeKey.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellPassCodeKey.setRowspan(3);
        pdfPTable.addCell(cellPassCodeKey);

        PdfPCell cellPassCodeValue = new PdfPCell(new Paragraph(passCodeA + passCodeB, ipaGothic14));
        cellPassCodeValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellPassCodeValue.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellPassCodeValue.setFixedHeight(30);
        pdfPTable.addCell(cellPassCodeValue);

        if (passCodeA.length() != 0 && !noBarCodePrint) {
            Barcode128 code128 = new Barcode128();
            code128.setCode(passCodeA);
            code128.setFont(ipaGothic.getBaseFont());
            code128.setBarHeight(40f);
            PdfPCell cellPassCodeA_Bc = new PdfPCell(code128.createImageWithBarcode(cb, null, null));
            cellPassCodeA_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellPassCodeA_Bc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellPassCodeA_Bc.setFixedHeight(80);
            pdfPTable.addCell(cellPassCodeA_Bc);
        } else {
            PdfPCell cellPassCodeA_Bc = new PdfPCell(new Paragraph("---", ipaGothic));
            cellPassCodeA_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellPassCodeA_Bc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellPassCodeA_Bc.setFixedHeight(80);
            pdfPTable.addCell(cellPassCodeA_Bc);
        }

        if (passCodeB.length() != 0 && !noBarCodePrint) {
            Barcode128 code128 = new Barcode128();
            code128.setCode(passCodeB);
            code128.setFont(ipaGothic.getBaseFont());
            code128.setBarHeight(40f);
            PdfPCell cellPassCodeB_Bc = new PdfPCell(code128.createImageWithBarcode(cb, null, null));
            cellPassCodeB_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellPassCodeB_Bc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellPassCodeB_Bc.setFixedHeight(80);
            pdfPTable.addCell(cellPassCodeB_Bc);
        } else {
            PdfPCell cellPassCodeB_Bc = new PdfPCell(new Paragraph("---", ipaGothic));
            cellPassCodeB_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellPassCodeB_Bc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellPassCodeB_Bc.setFixedHeight(80);
            pdfPTable.addCell(cellPassCodeB_Bc);
        }

        PdfPCell cellCommentKey = new PdfPCell(new Paragraph("?", ipaGothic));
        cellCommentKey.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellCommentKey.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdfPTable.addCell(cellCommentKey);

        PdfPCell cellCommentValue = new PdfPCell(new Paragraph(comment, ipaGothic));
        cellCommentValue.setVerticalAlignment(Element.ALIGN_TOP);
        cellCommentValue.setHorizontalAlignment(Element.ALIGN_LEFT);
        cellCommentValue.setFixedHeight(150);
        pdfPTable.addCell(cellCommentValue);

        PdfPCell cellIssueKey = new PdfPCell(new Paragraph("", ipaGothic));
        cellIssueKey.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellIssueKey.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdfPTable.addCell(cellIssueKey);

        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        String strDate = sdf.format(cal.getTime());
        PdfPCell cellIssueValue = new PdfPCell(new Paragraph(strDate, ipaGothic));
        cellIssueValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellIssueValue.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellIssueValue.setFixedHeight(20);
        pdfPTable.addCell(cellIssueValue);

        //??
        document.add(pdfPTable);
        /*
                
         // CODE 128
         document.add(new Paragraph("?? : " + mainTitle, ipaGothic));
         document.add(new Paragraph(" : " + subTitle, ipaGothic));
         document.add(new Paragraph("-------------------------------------------------------"));
         document.add(new Paragraph(" " + strDate));
         document.add(new Paragraph("-------------------------------------------------------"));
                
                
         BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.WINANSI, BaseFont.EMBEDDED);
         Font font = new Font(bf, 12);
         document.add(new Paragraph("", ipaGothic));
         document.add(new Paragraph(url, ipaGothic));
         code128.setCode(url);
         code128.setFont(bf);
         code128.setX(1);
         //document.add(code128.createImageWithBarcode(cb, null, null));
                
         document.add(new Paragraph("USER", ipaGothic));
         if (userName.length() != 0) {
         document.add(new Paragraph(userName, ipaGothic));
         code128.setCode(userName);
         code128.setFont(bf);
         code128.setBarHeight(40f);
         document.add(code128.createImageWithBarcode(cb, null, null));
         }
                
         document.add(new Paragraph("CODE", ipaGothic));
         if (passCode.length() != 0) {
         document.add(new Paragraph(passCode, ipaGothic));
         code128.setCode(passCode);
         code128.setFont(bf);
         document.add(code128.createImageWithBarcode(cb, null, null));
         }
                
         document.add(new Paragraph("?", ipaGothic));
         document.add(new Paragraph(comment, ipaGothic));
         */
        // step 5
        document.close();
    } catch (RuntimeException ex) {
        document.close();
        throw ex;

    }
}

From source file:quanlyhoadon.PDFProcess.java

public boolean printPDF(String dest, Company company, Bill bill, LinhTinh lt) {
    try {/* w w w  .j  ava  2 s  .  c  o  m*/
        BaseFont urName = BaseFont.createFont("font/Time_New_Roman.TTF", BaseFont.IDENTITY_H,
                BaseFont.EMBEDDED);
        Font nameFont = new Font(urName, 16, Font.BOLD);
        Font addFont = new Font(urName, 12);
        Font boldFont = new Font(urName, 14, Font.BOLD);
        Font contentFont = new Font(urName, 14);
        Font footFont = new Font(urName, 16);

        Document document = new Document(PageSize.A4.rotate());
        PdfWriter.getInstance(document, new FileOutputStream(dest));
        document.open();

        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100);
        table.setWidths(new float[] { 2, 6, 3 });

        //logo
        Image img = Image.getInstance("logo.jpg");
        img.scaleAbsolute(100, 100);
        PdfPCell cell = new PdfPCell(img);
        cell.setBorder(PdfPCell.NO_BORDER);

        //middle content
        String name = company.getName();
        String address = "\n\n?C: " + company.getAddress();
        String phone = "\n\n?T: " + company.getPhone();
        String hed = "\n\n     PHIU B?O GI?";

        Phrase mid = new Phrase();
        mid.add(new Chunk(name, nameFont));
        mid.add(new Chunk(address + phone, addFont));
        mid.add(new Chunk(hed, nameFont));

        PdfPCell midCell = new PdfPCell(mid);
        //      midCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        midCell.setPaddingTop(15);
        midCell.setPaddingLeft(40);
        midCell.setPaddingRight(15);
        midCell.setPaddingBottom(15);
        midCell.setBorder(PdfPCell.NO_BORDER);

        // right content
        String soCt = "S CT: " + bill.getId();
        String date = "\n\nNgy: " + bill.getDate() + "\n\nKho : " + lt.getKho();

        Phrase right = new Phrase();
        right.add(new Chunk(soCt + date, addFont));
        PdfPCell rightCell = new PdfPCell(right);
        rightCell.setPadding(15);
        rightCell.setBorder(PdfPCell.NO_BORDER);

        table.addCell(cell);
        table.addCell(midCell);
        table.addCell(rightCell);

        document.add(table);

        Phrase p1 = new Phrase();
        p1.add(new Chunk("?n v: ", addFont));
        p1.add(new Chunk(lt.getDonVi(), boldFont));
        p1.add(new Chunk("\n?a Ch: \n", addFont));

        Paragraph pagra = new Paragraph(p1);
        pagra.setIndentationLeft(15);
        pagra.setSpacingBefore(10);
        pagra.setSpacingAfter(10);
        document.add(pagra);

        //table lt
        PdfPTable tablList = new PdfPTable(6);

        tablList.setWidthPercentage(100);
        tablList.setWidths(new float[] { 1, 5, 7, 2, 3, 4 });

        String title[] = { "STT", "M Hng", "Tn Hng", "SL", "?n Gi", "Thnh Ti?n" };
        for (int i = 0; i < title.length; ++i) {
            Phrase phr = new Phrase();
            phr.add(new Chunk(title[i], boldFont));
            PdfPCell p = new PdfPCell(phr);
            p.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            tablList.addCell(p);
        }
        //--- add content
        for (int i = 0; i < bill.getCount(); ++i) {
            Phrase[] phrase = new Phrase[6];
            PdfPCell[] pCell = new PdfPCell[6];

            for (int k = 0; k < 6; ++k) {
                phrase[k] = new Phrase();
            }
            phrase[0].add(new Chunk((i + 1) + "", contentFont));
            phrase[1].add(new Chunk(bill.getMaHangAt(i), contentFont));
            phrase[2].add(new Chunk(bill.getTenHangAt(i), contentFont));
            phrase[3].add(new Chunk(bill.getSoLuongAt(i) + "", contentFont));
            phrase[4].add(new Chunk(bill.getDonGiaAt(i) + "", contentFont));
            phrase[5].add(new Chunk(bill.getThanhTienAt(i) + "", contentFont));

            for (int j = 0; j < 6; ++j) {
                pCell[j] = new PdfPCell(phrase[j]);
                pCell[j].setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

                tablList.addCell(pCell[j]);
            }
        }

        PdfPCell cell1 = new PdfPCell(new Phrase(new Chunk("Tng", boldFont)));
        cell1.setColspan(3);
        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        tablList.addCell(cell1);

        //
        PdfPCell cell2 = new PdfPCell(new Phrase(new Chunk("" + bill.getTong(), boldFont)));
        cell2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        tablList.addCell(cell2);

        //
        PdfPCell cell3 = new PdfPCell(new Phrase(new Chunk("", boldFont)));
        cell3.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        tablList.addCell(cell3);

        //
        PdfPCell cell4 = new PdfPCell(new Phrase(new Chunk(String.format("%,d", bill.tongTien()), boldFont)));
        cell4.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        tablList.addCell(cell4);

        document.add(tablList);
        //-------------------in phuong thuc thanh toan
        Phrase p2 = new Phrase();
        p2.add(new Chunk("Phng thc thanh ton: ", contentFont));
        p2.add(new Chunk(lt.getThanhToan(), boldFont));
        p2.add(new Chunk("\nLu  mua hng min tr li. Vui lng gi phiu trong 7 ngy: ",
                contentFont));

        Paragraph pagra2 = new Paragraph(p2);
        pagra2.setSpacingBefore(5);
        pagra2.setSpacingAfter(5);
        document.add(pagra2);

        //---- footer content
        PdfPTable tblFoot = new PdfPTable(3);

        tblFoot.setWidthPercentage(100);
        tblFoot.setWidths(new float[] { 1, 1, 1 });

        PdfPCell leftFootCell = new PdfPCell(new Phrase(new Chunk("NGI LP ", footFont)));
        PdfPCell midFootCell = new PdfPCell(new Phrase(new Chunk("K TO?N ", footFont)));
        PdfPCell rightFootCell = new PdfPCell(new Phrase(new Chunk("TH TRNG ?N V ", footFont)));

        leftFootCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        leftFootCell.setBorder(PdfPCell.NO_BORDER);
        midFootCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        midFootCell.setBorder(PdfPCell.NO_BORDER);
        rightFootCell.setBorder(PdfPCell.NO_BORDER);
        rightFootCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

        tblFoot.addCell(leftFootCell);
        tblFoot.addCell(midFootCell);
        tblFoot.addCell(rightFootCell);

        document.add(tblFoot);

        //
        document.close();
        JOptionPane.showMessageDialog(null, "In hoadon.pdf thnh cng");
        return true;
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null,
                "hoadon.pdf ang c m\nVui lng ng li. Sau  th li");
        e.printStackTrace();
        return false;
    }
}

From source file:relatorios.relatorio.java

public static void gerarRelatorio(CaixaDAO caixadao) { // criao do objeto documento
    Document document = new Document(PageSize.A4, 30, 20, 20, 30);
    OutputStream output;//w w  w . j  a  va 2  s. c  om
    try {
        output = new FileOutputStream("PDF_LinhaCodigo.pdf");
        try {
            PdfWriter.getInstance(document, output);
            document.open(); // adicionando um pargrafo ao documento 
            document.add(new Paragraph("Relatrio de BD - Fluxo de Caixa"));
            PdfPTable tabela = new PdfPTable(6);
            tabela.addCell("Cdigo");
            tabela.addCell("Saldo Inicial");
            tabela.addCell("Saldo Aplicado");
            tabela.addCell("Saldo Final");
            tabela.addCell("Abertura");
            tabela.addCell("Fechamento");
            List<Caixa> caixas = caixadao.listarTodos();
            for (Caixa a : caixas) {
                SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
                String data1, data2 = null;
                data1 = sdf.format(a.getData());
                data2 = sdf.format(a.getData_f());
                tabela.addCell("" + a.getId());
                tabela.addCell("" + a.getSaldo_incial());
                tabela.addCell("" + a.getSaldo_aplicado());
                tabela.addCell("" + a.getSaldo_final());
                tabela.addCell(data1);
                tabela.addCell(data2);
            }
            document.add(tabela);
            document.close();
        } catch (DocumentException de) {
            System.err.println(de.getMessage());
            document.close();

        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(relatorio.class.getName()).log(Level.SEVERE, null, ex);
        System.err.println(ex.getMessage());

    }

}

From source file:relatorios.RelatorioCliente.java

public static void gerarRelatorio() throws ClassNotFoundException { // criao do objeto documento
    Document document = new Document(PageSize.A4, 30, 20, 20, 30);
    Connection conecta; // o objeto que conecta com o banco de dados
    PreparedStatement pst;//from w  w w  . jav a 2s . c o  m
    ResultSet rs;
    conecta = ConectaBd.conectabd();

    OutputStream output;
    try {
        output = new FileOutputStream("relatorios/Relatrio de Clientes.pdf");
        try {
            PdfWriter.getInstance(document, output);
            document.open(); // adicionando um pargrafo ao documento 
            document.add(new Paragraph("                                    Relatrio de Clientes"));
            document.add(new Paragraph("\n"));
            Font bfBold10 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD, new BaseColor(0, 0, 0));
            Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL, new BaseColor(0, 0, 0));
            Font bf8 = new Font(Font.FontFamily.TIMES_ROMAN, 8);
            PdfPTable tabela = new PdfPTable(6);
            PdfPCell cell;
            cell = new PdfPCell(new Phrase("Nome", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("CPF", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("Endereo", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("Cidade", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("UF", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("Telefone", bfBold10));
            tabela.addCell(cell);

            String sql = "Select * from clientes order by codigo Asc"; //orderna pelo numero do codigo ascendentemente
            try {
                pst = conecta.prepareStatement(sql);
                rs = pst.executeQuery();
                while (rs.next()) {
                    String fornec = rs.getString("nome");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("cpf");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("endereco");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("cidade");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("uf");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("telefone");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);

                }
            } catch (SQLException error) {
                JOptionPane.showMessageDialog(null, error);
            }

            document.add(tabela);
            document.close();
        } catch (DocumentException de) {
            System.err.println(de.getMessage());
            document.close();

        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RelatorioFornecedor.class.getName()).log(Level.SEVERE, null, ex);
        System.err.println(ex.getMessage());

    }

}

From source file:relatorios.RelatorioCompra.java

public static void gerarRelatorio(String sql) throws ClassNotFoundException { // criao do objeto documento
    Document document = new Document(PageSize.A4, 30, 20, 20, 30);
    Connection conecta; // o objeto que conecta com o banco de dados
    PreparedStatement pst;/*ww w  .  j av  a 2  s . c  o  m*/
    ResultSet rs;
    conecta = ConectaBd.conectabd();

    OutputStream output;
    try {
        output = new FileOutputStream("relatorios/Relatrio de Compras.pdf");
        try {
            PdfWriter.getInstance(document, output);
            document.open(); // adicionando um pargrafo ao documento 
            document.add(new Paragraph("                                    Relatrio de Compras"));
            document.add(new Paragraph("\n"));
            Font bfBold10 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD, new BaseColor(0, 0, 0));
            Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL, new BaseColor(0, 0, 0));
            Font bf8 = new Font(Font.FontFamily.TIMES_ROMAN, 6);
            PdfPTable tabela = new PdfPTable(6);
            PdfPCell cell;
            cell = new PdfPCell(new Phrase("Fornecedor", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("Produto", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("Qtde do Produto", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("Valor por Unidade", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("Valor Total", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("Data", bfBold10));
            tabela.addCell(cell);

            try {
                pst = conecta.prepareStatement(sql);
                rs = pst.executeQuery();
                while (rs.next()) {
                    String fornec = rs.getString("fornecedor");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("produto");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("quantidade");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("valorunitariocompra");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("valortotalcompra");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("data_compra");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                }
            } catch (SQLException error) {
                JOptionPane.showMessageDialog(null, error);
            }

            document.add(tabela);
            document.close();
        } catch (DocumentException de) {
            System.err.println(de.getMessage());
            document.close();

        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RelatorioCompra.class.getName()).log(Level.SEVERE, null, ex);
        System.err.println(ex.getMessage());

    }

}

From source file:relatorios.RelatorioFornecedor.java

public static void gerarRelatorio() throws ClassNotFoundException { // criao do objeto documento
    Document document = new Document(PageSize.A4, 30, 20, 20, 30);
    Connection conecta; // o objeto que conecta com o banco de dados
    PreparedStatement pst;// w  ww . j  av a 2 s . c  o m
    ResultSet rs;
    conecta = ConectaBd.conectabd();

    OutputStream output;
    try {
        output = new FileOutputStream("relatorios/Relatrio de Fornecedores.pdf");
        try {
            PdfWriter.getInstance(document, output);
            document.open(); // adicionando um pargrafo ao documento 
            document.add(new Paragraph("                                    Relatrio de Fornecedores"));
            document.add(new Paragraph("\n"));
            Font bfBold10 = new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD, new BaseColor(0, 0, 0));
            Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 8, Font.NORMAL, new BaseColor(0, 0, 0));
            Font bf8 = new Font(FontFamily.TIMES_ROMAN, 8);
            PdfPTable tabela = new PdfPTable(7);
            PdfPCell cell;
            cell = new PdfPCell(new Phrase("Fornecedor", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("CPF", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("CNPJ", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("Endereo", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("Cidade", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("Email", bfBold10));
            tabela.addCell(cell);
            cell = new PdfPCell(new Phrase("Telefone", bfBold10));
            tabela.addCell(cell);

            String sql = "Select * from fornecedores order by codigo Asc"; //orderna pelo numero do codigo ascendentemente
            try {
                pst = conecta.prepareStatement(sql);
                rs = pst.executeQuery();
                while (rs.next()) {
                    String fornec = rs.getString("fornecedor");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("cpf");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("cnpj");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("endereco");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("cidade");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("email");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);
                    fornec = rs.getString("telefone");
                    cell = new PdfPCell(new Phrase(fornec, bf8));
                    tabela.addCell(cell);

                }
            } catch (SQLException error) {
                JOptionPane.showMessageDialog(null, error);
            }

            document.add(tabela);
            document.close();
        } catch (DocumentException de) {
            System.err.println(de.getMessage());
            document.close();

        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RelatorioFornecedor.class.getName()).log(Level.SEVERE, null, ex);
        System.err.println(ex.getMessage());

    }

}