Example usage for com.itextpdf.text Document Document

List of usage examples for com.itextpdf.text Document Document

Introduction

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

Prototype


public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom) 

Source Link

Document

Constructs a new Document -object.

Usage

From source file:ImagetoPDF.java

public void convertToPDF(String folderName, String fileName, float compressionFactor)
        throws DocumentException, FileNotFoundException, BadElementException, IOException {
    File folder = new File(folderName);
    File[] listOfFiles = folder.listFiles();
    Image img = Image.getInstance(listOfFiles[0].getAbsolutePath());
    float width, height, temp;
    width = img.getWidth();//  ww w .j  ava2  s.c  o m
    height = img.getHeight();
    if (height < width) {
        temp = height;
        height = width;
        width = height;
    }
    Rectangle pageSize = new Rectangle(width, height);
    Document document = new Document(pageSize, 0, 0, 0, 0);

    for (int i = 0; i < listOfFiles.length; i++) {
        enhance(listOfFiles[i].getAbsolutePath());
    }
    float scalar;
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
    writer.open();
    writer.setCompressionLevel(5);
    document.open();

    for (int i = 0; i < listOfFiles.length; i++) {
        img = Image.getInstance(listOfFiles[i].getAbsolutePath());
        if (img.getWidth() > img.getHeight()) {
            img.setRotationDegrees(270f);
        }
        scalar = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin() - 0)
                / img.getWidth()) * 100;
        img.scalePercent(scalar);

        document.add(img);
    }
    document.close();
    writer.close();

}

From source file:FullPageTable.java

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document(PageSize.A4, 0, 0, 0, 0);
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();/* w w w.j  av a2  s.  c om*/
    PdfPTable table = new PdfPTable(10);

    table.setWidthPercentage(100);
    table.setSpacingBefore(0f);
    table.setSpacingAfter(0f);

    // first row
    PdfPCell cell = new PdfPCell(new Phrase("DateRange"));
    cell.setColspan(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setPadding(10.0f);
    cell.setBackgroundColor(new BaseColor(140, 221, 8));
    table.addCell(cell);

    table.addCell("Calldate");
    table.addCell("Calltime");
    table.addCell("Source");
    table.addCell("DialedNo");
    table.addCell("Extension");
    table.addCell("Trunk");
    table.addCell("Duration");
    table.addCell("Calltype");
    table.addCell("Callcost");
    table.addCell("Site");

    for (int i = 0; i < 100; i++) {
        table.addCell("date" + i);
        table.addCell("time" + i);
        table.addCell("source" + i);
        table.addCell("destination" + i);
        table.addCell("extension" + i);
        table.addCell("trunk" + i);
        table.addCell("dur" + i);
        table.addCell("toc" + i);
        table.addCell("callcost" + i);
        table.addCell("Site" + i);
    }
    document.add(table);
    document.close();
}

From source file:admission_form.FXMLController1.java

@FXML
private void doPrinting(ActionEvent event) {
    print_btn.setVisible(false);//w  ww. j  av a2  s .c  o  m
    back_btn.setVisible(false);
    Scene scene = print_btn.getScene();
    WritableImage snapshot = scene.snapshot(null);
    BufferedImage image = SwingFXUtils.fromFXImage(snapshot, null);
    File f = new File("test2.png");
    try {
        ImageIO.write(image, "png", f);
    } catch (IOException ex) {

    }
    Document document = new Document(PageSize.A4, 0, 0, 0, 0);
    try {
        PdfWriter.getInstance(document, new FileOutputStream("Image.pdf"));
        document.open();
        // BufferedImage img = ImageIO.read(new File("test1.png"));
        //File f = new File("test1.png");
        Image image1 = Image.getInstance("test2.png");
        document.add(image1);

        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        InputStream is = new BufferedInputStream(new FileInputStream("Image.pdf"));
        DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF;
        PrintService service = PrintServiceLookup.lookupDefaultPrintService();
        DocPrintJob printJob = service.createPrintJob();
        printJob.addPrintJobListener(new JobCompleteMonitor());
        Doc doc = new SimpleDoc(is, flavor, null);
        PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
        //attributes.add(new Destination(new java.net.URI("file:/home/jayesh/NetBeansProjects/myFile.ps")));
        printJob.print(doc, attributes);
        //while(jobRunning)
        //{
        //    Thread.sleep(1000);
        //}
        is.close();
    } catch (Exception ex) {
    } finally {
        System.out.println("exiting");

    }
    System.out.println("Done");
    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost/pro", username, password);
        String query = "insert into log values(?,?)";
        PreparedStatement ps = con.prepareStatement(query);
        ps.setString(1, getCurUser());
        Date date = new Date();
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/YYYY HH:mm:ss");
        ps.setString(2, "Printed Admission Form Page2 at " + df.format(date));
        ps.executeUpdate();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    print_btn.setVisible(true);
    back_btn.setVisible(true);
}

From source file:admission_form.FXMLDocumentController.java

@FXML
private void doPrininting(ActionEvent event) {

    next.setVisible(false);//from  w  w w . j a  v  a2  s  .  com
    print_btn.setVisible(false);
    Scene scene = print_btn.getScene();
    WritableImage snapshot = scene.snapshot(null);
    BufferedImage image = SwingFXUtils.fromFXImage(snapshot, null);
    File f = new File("test2.png");
    try {
        ImageIO.write(image, "png", f);
    } catch (IOException ex) {

    }
    Document document = new Document(PageSize.A4, 0, 0, 0, 0);
    try {
        PdfWriter.getInstance(document, new FileOutputStream("Image.pdf"));
        document.open();
        // BufferedImage img = ImageIO.read(new File("test1.png"));
        //File f = new File("test1.png");
        Image image1 = Image.getInstance("test2.png");
        document.add(image1);

        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        InputStream is = new BufferedInputStream(new FileInputStream("Image.pdf"));
        DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF;
        PrintService service = PrintServiceLookup.lookupDefaultPrintService();
        DocPrintJob printJob = service.createPrintJob();
        printJob.addPrintJobListener(new JobCompleteMonitor());
        Doc doc = new SimpleDoc(is, flavor, null);
        PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
        //attributes.add(new Destination(new java.net.URI("file:/home/jayesh/NetBeansProjects/myFile.ps")));
        printJob.print(doc, attributes);
        //while(jobRunning)
        //{
        //    Thread.sleep(1000);
        //}
        is.close();
    } catch (Exception ex) {
    } finally {
        System.out.println("exiting");

    }
    System.out.println("Done");
    try {
        con1();
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost/pro", username, password);
        String query = "insert into log values(?,?)";
        PreparedStatement ps = con.prepareStatement(query);
        ps.setString(1, getCurUser());
        Date date = new Date();
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/YYYY HH:mm:ss");
        ps.setString(2, "Printed Admission Form Page1 at " + df.format(date));
        ps.executeUpdate();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    next.setVisible(true);
    print_btn.setVisible(true);
}

From source file:avalonscrollmaker20.AnothakScribe.java

License:Open Source License

private void initializeDoc() {
    // Create a Document
    doc_scrolls = new Document(PageSize.LETTER, 18f, 18f, 18f, 18f);

    // Get a DocWriter instance
    try {//from  www  .  j av a  2  s. com
        doc_writer = PdfWriter.getInstance(doc_scrolls, new FileOutputStream(doc_name));
        doc_writer.setPdfVersion(PdfWriter.VERSION_1_6);
    } catch (Exception ex) {
        System.err.println(ex + "\nProgram closing.");
        System.exit(3);
    }

    // Open the Document
    doc_scrolls.addTitle(doc_name.substring(0, doc_name.length() - 3));
    doc_scrolls.addSubject("A collection of Avalon-legal Anothak Scrolls");
    doc_scrolls.addAuthor("Michael Weigle");
    doc_scrolls.addCreator("Avalon Scrollmaker 2.0, powered by iText");
    doc_scrolls.open();
}

From source file:be.zenodotus.creatie.GeneratePDF.java

License:Open Source License

public String vakantieAfdruk(Context context, String name, int jaar) {
    this.context = context;
    PdfWriter w = null;//from  ww  w .ja  v  a  2s  . c om
    Document d = new Document(PageSize.A4.rotate(), 5, 5, 10, 10);
    d.setPageCount(3);
    String fileName = name;
    String file = name;
    GregorianCalendar datum = new GregorianCalendar();
    datum.set(GregorianCalendar.YEAR, jaar);

    String[] maanden = { "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus",
            "September", "Oktober", "November", "December" };
    int[] dagen = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    VerlofDao dao = new VerlofDao(context);
    FeestdagDao feestdagDao = new FeestdagDao(context);
    WerkdagDao werkdagDao = new WerkdagDao(context);
    File folder = new File(context.getFilesDir(), "pdfs");
    folder.mkdirs();
    if (datum.isLeapYear(jaar)) {
        dagen[1] = 29;
    }
    File temp = null;
    temp = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
            "Jacqueline" + jaar + ".pdf");
    fileName = temp.toString();
    try {
        dao.open();
        ArrayList<Verlof> verloflijst = dao.getAlleVerlovenPerJaar(jaar);
        w = PdfWriter.getInstance(d, new FileOutputStream(temp));
        d.open();
        d.addAuthor("Jacqueline Vandenbroecke");
        d.addCreationDate();
        d.addCreator("Verlofplanner");
        d.addTitle("Vakantie " + jaar + " van Jacqueline Vandenbroecke");
        Font standaard = FontFactory.getFont(FontFactory.HELVETICA, 8);
        Font standaardBold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD);
        Paragraph gegeven = new Paragraph("Jacqueline Vandenbroecke Verlof " + jaar + "\n", standaardBold);
        gegeven.setAlignment(Paragraph.ALIGN_CENTER);
        d.add(gegeven);

        for (int paginas = 0; paginas < 2; paginas++) {
            int aantal = 0;
            if (paginas == 1) {
                d.newPage();
                aantal = 6;
            }
            PdfPTable table = new PdfPTable(6);
            for (int i = aantal; i < (aantal + 6); i++) {
                PdfPCell cell = new PdfPCell(new Paragraph(maanden[i], standaardBold));
                cell.setBorder(1);
                table.addCell(cell);
            }
            int dag = 1;
            int k = aantal;
            for (int i = aantal; i < (aantal + 6); i++) {
                for (int j = 0; j < 32; j++) {
                    if (k > ((aantal + 6) - 1)) {
                        k = aantal;
                        dag++;
                    }
                    if (dag > dagen[k]) {
                        PdfPCell cell = new PdfPCell(new Paragraph("", standaard));
                        table.addCell(cell);
                        k++;
                    } else {
                        SimpleDateFormat formatterDag = new SimpleDateFormat("dd");
                        SimpleDateFormat formatterWeek = new SimpleDateFormat("EEE");
                        datum.set(jaar, k, dag);
                        PdfPTable dagTabel = new PdfPTable(4);
                        PdfPCell cellDag = new PdfPCell(
                                new Paragraph(formatterDag.format(datum.getTime()), standaard));
                        PdfPCell cellWeek = new PdfPCell(
                                new Paragraph(formatterWeek.format(datum.getTime()), standaard));
                        ArrayList<Verlof> verlof = new ArrayList<Verlof>();
                        for (int z = 0; z < verloflijst.size(); z++) {
                            if (((verloflijst.get(z).getDag() + 1) == dag)
                                    && (verloflijst.get(z).getMaand() == k)) {
                                verlof.add(verloflijst.get(z));

                            }
                        }
                        feestdagDao.open();
                        Feestdag feestdag = feestdagDao.getFeestdag(jaar, datum.get(GregorianCalendar.MONTH),
                                datum.get(GregorianCalendar.DATE));
                        feestdagDao.close();
                        werkdagDao.open();
                        java.util.List<Werkdag> weekend = werkdagDao.getWeekend();
                        werkdagDao.close();
                        String Verlof = "";
                        String uur = "";
                        if (verlof.size() > 0) {
                            if (verlof.size() > 1) {
                                Verlof = verlof.get(0).getVerlofsoort() + "\n" + verlof.get(1).getVerlofsoort();
                                uur = verlof.get(0).getUrental() + "\n" + verlof.get(1).getUrental();
                            } else {
                                Verlof = verlof.get(0).getVerlofsoort();
                                uur = verlof.get(0).getUrental();
                            }

                        }
                        PdfPCell cellVerlof = new PdfPCell(new Paragraph(Verlof, standaard));
                        PdfPCell uren = new PdfPCell(new Paragraph(uur, standaard));
                        if (verlof.size() > 0) {
                            BaseColor kleur = new BaseColor(Color.GRAY);
                            cellVerlof.setBackgroundColor(kleur);
                            uren.setBackgroundColor(kleur);
                            cellDag.setBackgroundColor(kleur);
                            cellWeek.setBackgroundColor(kleur);
                        }
                        for (int z = 0; z < weekend.size(); z++) {
                            if ((formatterWeek.format(datum.getTime())).equals(weekend.get(z).getDag())) {
                                BaseColor kleur = new BaseColor(Color.LTGRAY);
                                cellVerlof.setBackgroundColor(kleur);
                                uren.setBackgroundColor(kleur);
                                cellDag.setBackgroundColor(kleur);
                                cellWeek.setBackgroundColor(kleur);
                            }
                        }
                        if (feestdag != null) {
                            BaseColor kleur = new BaseColor(Color.GREEN);
                            uren.setBackgroundColor(kleur);
                            cellVerlof.setBackgroundColor(kleur);
                            uren.setBackgroundColor(kleur);
                            cellDag.setBackgroundColor(kleur);
                            cellWeek.setBackgroundColor(kleur);
                        }
                        dagTabel.addCell(cellDag);
                        dagTabel.addCell(cellWeek);
                        dagTabel.addCell(cellVerlof);
                        dagTabel.addCell(uren);
                        table.addCell(dagTabel);
                        k++;
                    }
                }

            }
            d.add(table);
            dao.close();
        }
    } catch (Exception ex) {

        ex.printStackTrace();

    } finally {
        d.close();
        w.close();
    }
    return fileName;
}

From source file:beans.ManagedBeanReportes.java

public void inventario() throws DocumentException, IOException {
    FacesContext facexcontext = FacesContext.getCurrentInstance();
    ValueExpression vex = facexcontext.getApplication().getExpressionFactory()
            .createValueExpression(facexcontext.getELContext(), "#{managedBeanLogin}", ManagedBeanLogin.class);
    ManagedBeanLogin beanLogin = (ManagedBeanLogin) vex.getValue(facexcontext.getELContext());

    FacesContext context = FacesContext.getCurrentInstance();

    Document document = new Document(PageSize.A4, 25, 25, 75, 25);//int marginLeft,   int marginRight,   int marginTop,   int marginBottom

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    writer.setPageEvent(new ManagedBeanReportes.Watermark(""));
    if (!document.isOpen()) {
        document.open();//w w w. ja v a 2  s .c o  m
    }

    try {

        ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
        //String imageUrl1 = extContext.getRealPath("//resources//images/logo0002.png");
        //Image welladigital = Image.getInstance(imageUrl1);
        //welladigital.setAbsolutePosition(377f, 760f);
        //welladigital.scalePercent(40);
        //document.add(welladigital);

        //crear tabla PARA NOMBRE DEL AO
        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100);
        table.setTotalWidth(450f);
        // table.setTotalWidth(540f);
        table.setLockedWidth(true);
        float[] headerWidths = { 120, 20, 310 };
        table.setWidths(headerWidths);
        table.getDefaultCell();

        SimpleDateFormat formato = new SimpleDateFormat("EEEE dd MMMM YYYY");
        StringBuilder cadena = new StringBuilder(formato.format(fecha_inicio));

        Chunk underline = new Chunk("FECHA DE INVENTARIO:" + cadena.toString().toUpperCase(), bigFont12);
        underline.setUnderline(0.2f, -2f); //0.1 thick, -2 y-location
        PdfPCell table5 = new PdfPCell(new Paragraph(underline));
        table5.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
        table5.setColspan(3);
        table5.setBorder(Rectangle.NO_BORDER);
        table.addCell(table5);

        document.add(table);

        document.add(new Paragraph("\n", pequeFont));

        PdfPCell table2 = new PdfPCell();

        table2 = new PdfPCell(
                new Paragraph(beanLogin.getObjetoEmpleado().getTienda().getNombreTienda(), pequeFont));
        table2.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
        table2.setColspan(3);
        table2.setBorder(Rectangle.NO_BORDER);
        table = new PdfPTable(3);
        table.setWidthPercentage(100);
        table.setTotalWidth(450f);
        table.setLockedWidth(true);
        table.setWidths(headerWidths);
        table.getDefaultCell();
        table.addCell(table2);
        document.add(table);

        document.add(new Paragraph("\n", pequeFont));

        document.add(traerSubtabla(beanLogin.getObjetoEmpleado().getTienda()));
        formato = new SimpleDateFormat("yyyy-MM-dd");
        cadena = new StringBuilder(formato.format(fecha_inicio));

        //document.add(traerSubtabla02(cadena.toString()));
        document.add(new Paragraph("\n", pequeFont));
        ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
        String ctxPath = ((ServletContext) ctx.getContext()).getContextPath();
        document.close();
        formato = new SimpleDateFormat("dd_MM_yyyy");
        cadena = new StringBuilder(formato.format(fecha_inicio));
        String fileName = cadena.toString();

        writePDFToResponse(context.getExternalContext(), baos, fileName);
        context.responseComplete();

    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:bestdeal.util.genererPdf.java

public static void main(String[] args) {
    // - Paramtres de connexion  la base de donnes
    Connection connection;//from  w w  w. j  a  v  a2 s . c o m
    String[][] data = new String[][] { { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " },
            { " ", " ", " ", " ", " " }, };

    try {
        String requete = "select c.nom,c.prenom,c.email,k.nom,k.prenom,k.telephone,k.adresse,k.email,d.id_deal,d.nom_deal,v.quantite,v.prix_unitaire from client c INNER JOIN voucher v on v.id_client=c.id_client INNER JOIN deal d on v.id_deal=d.id_deal INNER JOIN vendeur k on d.id_vendeur=k.id_vendeur";
        connection = MyConnection.getInstance();
        mypdf = new Document(PageSize.A4, 50, 50, 50, 50);
        File di = new File("C:/Voucher");
        File fl[] = di.listFiles();
        try {
            OutputStream file = new FileOutputStream(new File("C:/Voucher\\Voucher.pdf"));
            PdfWriter.getInstance(mypdf, file);

            mypdf.open();
            Statement stm;

            mypdf.addAuthor("Best Deal");
            mypdf.addSubject("Voucher ");
            mypdf.add(new Paragraph("Socite BestDeal"));
            mypdf.add(new Paragraph("Adresse La Chotrana ESPRIT "));
            mypdf.add(new Paragraph("TEL : xx xxx xxx"));
            mypdf.add(new Paragraph("FAX : xx xxx xxx"));
            mypdf.add(new Paragraph(
                    "                                                                                                       "
                            + new Date().toString()));
            mypdf.add(new Paragraph("  "));
            mypdf.add(new Paragraph("                                   " + "Voucher N'01",
                    FontFactory.getFont(FontFactory.HELVETICA, 21, Font.BOLDITALIC)));
            mypdf.add(new Paragraph("  "));

            mypdf.add(new Paragraph("CLIENT :",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));
            try {
                stm = connection.createStatement();
                ResultSet rs = stm.executeQuery(requete);

                while (rs.next()) {
                    // add a country to the document as a Chunk
                    //mypdf.add(new Chunk(rs.getString("quantite")));
                    Phrase p = new Phrase("Nom:   ");
                    Phrase p2 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa = new Paragraph();
                    pa.add(p);
                    pa.add(p2);
                    mypdf.add(pa);

                    Phrase p3 = new Phrase("Prenom:  ");
                    Phrase p4 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa1 = new Paragraph();
                    pa1.add(p3);
                    pa1.add(p4);
                    mypdf.add(pa1);

                    Phrase p5 = new Phrase("Adresse:  ");
                    Phrase p6 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa2 = new Paragraph();
                    pa2.add(p5);
                    pa2.add(p6);
                    mypdf.add(pa2);

                    Phrase p7 = new Phrase("Tlphone:  ");
                    Phrase p8 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa3 = new Paragraph();
                    pa3.add(p7);
                    pa3.add(p8);
                    mypdf.add(pa3);

                    mypdf.add(new Paragraph("  "));

                    mypdf.add(new Paragraph("Vendeur :",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));

                    Phrase p9 = new Phrase("Nom:  ");
                    Phrase p10 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa4 = new Paragraph();
                    pa4.add(p9);
                    pa4.add(p10);
                    mypdf.add(pa4);

                    Phrase p11 = new Phrase("Prnom:  ");
                    Phrase p12 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa5 = new Paragraph();
                    pa5.add(p11);
                    pa5.add(p12);
                    mypdf.add(pa5);

                    Phrase p13 = new Phrase("Tlphone:  ");
                    Phrase p14 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa6 = new Paragraph();
                    pa6.add(p13);
                    pa6.add(p14);
                    mypdf.add(pa6);

                    Phrase p15 = new Phrase("Adresse:  ");
                    Phrase p16 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa7 = new Paragraph();
                    pa7.add(p15);
                    pa7.add(p16);
                    mypdf.add(pa7);

                    Phrase p17 = new Phrase("Email:  ");
                    Phrase p18 = new Phrase(new Chunk(rs.getString("email")));
                    Paragraph pa8 = new Paragraph();
                    pa8.add(p17);
                    pa8.add(p18);
                    mypdf.add(pa8);

                    mypdf.add(new Paragraph("  "));
                    mypdf.add(new Paragraph("  "));
                    mypdf.add(new Paragraph("  "));

                    for (int i = 0; i < rs.getRow(); i++) {
                        for (int j = 0; j < data[i].length - 1; j++) {
                            data[i][j] = rs.getString(j + 9);
                            // if (j==3)
                            //     data[i][4]= Float.parseFloat(data[i][3])*Integer.parseInt(data[i][2])+"";
                        }
                    }

                    for (int i = 0; i < rs.getRow(); i++) {
                        float s = Integer.parseInt(data[i][2].trim()) * Float.parseFloat(data[i][3].trim());
                        data[i][4] = s + "";
                    }

                    //mypdf.add(new Phrase("nom"));
                    //mypdf.add(new  Chunk(rs.getString("nom")));
                    //mypdf.add( new Paragraph("nom:", new Chunk(rs.getString("nom"))));
                    //mypdf.add(new Chunk(" "));
                    //Chunk id = new Chunk(rs.getString("id"));
                    // with a background color
                    //id.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f);
                    // and a text rise
                    //id.setTextRise(6);
                    //  mypdf.add(id);
                    mypdf.add(Chunk.NEWLINE);
                }

            } catch (SQLException ex) {
                Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
            // mypdf.add(new Paragraph("Nom "));
            //  mypdf.add(new Paragraph("Prenom "));
            // mypdf.add(new Paragraph("Adresse "));
            //mypdf.add(new Paragraph("Tlphone "));

            // mypdf.add(new Paragraph("Nom "));
            // mypdf.add(new Paragraph("Nom de la socit "));
            //  mypdf.add(new Paragraph("Adresse "));
            // mypdf.add(new Paragraph("Tlphone "));
            // mypdf.add(new Paragraph("  "));

            String[] headers = new String[] { "  Id_deal", "   Nom Deal", "   Quantit", "    Prix unitaire",
                    "   Prix total" };
            PdfPTable table = new PdfPTable(headers.length);
            for (int i = 0; i < headers.length; i++) {
                String header = headers[i];
                PdfPCell cell = new PdfPCell();
                cell.setGrayFill(0.9f);
                cell.setPhrase(new Phrase(header.toUpperCase()));
                table.addCell(cell);
            }
            table.completeRow();
            for (int i = 0; i < data.length; i++) {
                for (int j = 0; j < data[i].length; j++) {
                    String datum = data[i][j];
                    PdfPCell cell = new PdfPCell();
                    cell.setPhrase(new Phrase(datum.toUpperCase()));
                    table.addCell(cell);
                }
                table.completeRow();
            }

            mypdf.add(table);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
        }

        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(
                "Pour toute question concernant cette facture,veuillez contacter Nom,numro de tlphone,adresse de messagerie ",
                FontFactory.getFont(null, 9, Font.NORMAL)));
        mypdf.add(new Paragraph(
                "                                                      Merci pour votre confiance",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLDITALIC)));
        mypdf.add(new Paragraph("      "));
        mypdf.add(new Paragraph("  "));
        mypdf.add(new Paragraph("  "));

        mypdf.close();

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

From source file:bladwin.web.reg.regPDF.java

public void genPed(String loc, regMgr regMgr, dbMgrInterface db) {
    Document document = null;//from   w w w  .  j a  v  a  2  s .  c o  m
    //String loc = "C:/_bisc/_javaApps/jlData/jvp/CellWidths.pdf";

    //regMgr.getCustomerRegBean().setPdf(loc);
    try {

        document = new Document(PageSize.A4, 30, 30, 30, 30);
        PdfWriter.getInstance(document, new FileOutputStream(loc));
        document.open();
        customerRegBean r = regMgr.getCustomerRegBean();
        customerBean c = regMgr.getCustomerBean();
        customerBean a = new custObj().getcustomerBean(r.getRegCustId(), db);
        mgnLookupBean bean = new mgnLookupObj().getLookupBean(-947, db);
        Paragraph pg;
        pg = new Paragraph(r.getLookupDesc());
        pg.setAlignment(Paragraph.ALIGN_CENTER);
        pg.setFont(FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
        document.add(getHeader(r.getLookupDesc()));
        document.add(getHeader("BALDWIN BLAZERS TRACK CLUB"));
        document.add(getHeader("REGISTRATION"));
        pg = new Paragraph("\n\r");
        document.add(pg);
        // -------------------------------------------------------
        document.add(genAthleteInfo(r, a));
        pg = new Paragraph("\n\r");
        document.add(pg);
        document.add(genParentInfo(c));
        pg = new Paragraph("\n\r");
        document.add(pg);
        document.add(genSport(r));
        pg = new Paragraph("\n\r");
        document.add(pg);
        pg = new Paragraph("PARENTS SIGNATURE");
        document.add(pg);
        pg = new Paragraph("\n\r");
        document.add(pg);
        pg = new Paragraph("\n\r");
        document.add(pg);
        pg = new Paragraph("_____________________________________________________________________");
        document.add(pg);
        pg = new Paragraph("\n\r");
        document.add(pg);
        document.add(getHeader(r.getFeeDesc() + "\n\r" + bean.getSubjectBody()));
        // ----------------------------------------------------------------------------

    } catch (DocumentException ex) {
        logger.error("DocumentException", ex);
    } catch (FileNotFoundException ex) {
        logger.error("FileNotFoundException", ex);
    } finally {
        try {
            if (document != null)
                document.close();

            //pdfFileOpen(loc);

        } catch (Exception e) {
            logger.error("FileNotFoundException", e);
        }
    }
}

From source file:br.edu.unipampa.recipemanager.pdf.CreatePDF.java

public boolean newPdf(List<MenuRecipe> menuRecipe, String month, String responsibleName) {
    double valueMonth = 0;
    try {//from w  w w  . j av  a 2s  . c  o  m
        Document doc = new Document(PageSize.A4, 72, 72, 72, 72);
        OutputStream os = new FileOutputStream(namePdf(menuRecipe));
        PdfWriter.getInstance(doc, os);

        doc.open();
        Paragraph p;
        Font f = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);

        p = new Paragraph("Ms: " + month, f);
        doc.add(p);

        f = new Font(Font.FontFamily.COURIER, 14, Font.ITALIC);

        for (MenuRecipe menu : menuRecipe) {
            valueMonth += menu.priceMenu();
            p.setSpacingBefore(5);
            p.setSpacingAfter(5);
            p = new Paragraph(menu.toString(), f);
            doc.add(p);
        }

        p = new Paragraph("Preo total de todos os cardpios: " + valueMonth, f);
        doc.add(p);

        f = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
        p = new Paragraph("_____________________________________\n" + responsibleName, f);
        p.setSpacingAfter(15);
        p.setAlignment(Element.ALIGN_RIGHT);
        doc.add(p);

        doc.close();
        os.close();
        return true;
    } catch (Exception e) {
        return false;
    }
}