Example usage for com.itextpdf.text Document add

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

Introduction

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

Prototype


public boolean add(Element element) throws DocumentException 

Source Link

Document

Adds an Element to the Document.

Usage

From source file:com.ftt.gui.FrameFormation.java

private void pdf1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pdf1ActionPerformed

    if (nomf.getText() == null || descriptionf.getText() == null || "".equals(lieux.getText())
            || dateclot.getDate() == null || dateov.getDate() == null) {
        JOptionPane.showMessageDialog(this, "Vrifier les champs !");
    } else {//from   www.j a va 2 s . c om
        SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy");
        String val1 = lieux.getText();
        String val2 = formateur.format(dateov.getDate());
        String val3 = formateur.format(dateclot.getDate());
        String val4 = combocible.getSelectedItem().toString();
        String val5 = nomf.getText();
        String val6 = descriptionf.getText();
        Document document = new Document();

        try {
            PdfWriter.getInstance(document, new FileOutputStream("rapport.pdf"));

            document.open();

            com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png");
            document.add(image);
            document.add(new Paragraph("Liste des formations",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD)));
            document.add(new Paragraph(formateur.format(new Date())));
            String val322 = formateur.format(new Date());
            document.add(new Paragraph("                    "));

            PdfPTable table = new PdfPTable(2);
            PdfPCell cell = new PdfPCell(new Paragraph("formations"));
            cell.setColspan(4);
            cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
            cell.setBackgroundColor(BaseColor.BLUE);
            table.addCell(cell);
            table.addCell("Nom formation");
            table.addCell(val5);
            table.addCell(cell);
            table.addCell("Description");
            table.addCell(val6);
            table.addCell(cell);
            table.addCell("Lieux");
            table.addCell(val1);
            table.addCell("Date d'ouverture");
            table.addCell(val2);
            table.addCell("Date de cloture");
            table.addCell(val3);
            table.addCell("Cible");
            table.addCell(val4);
            document.add(table);
            document.add(new Paragraph("    "));
            document.add(new Paragraph("    "));
            document.add(new Paragraph("Responsable des formations"));
            document.add(new Paragraph("Federation Tunisenne de Tennis"));
            document.close();
            JOptionPane.showMessageDialog(null, "Rapport Enregistrer");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
    }
}

From source file:com.ftt.gui.FrameFormation.java

private void pdf2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pdf2ActionPerformed

    FormationDAO fd = new FormationDAO();
    ArrayList<Formation> formations = (ArrayList<Formation>) fd.select();
    SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy");

    Document document = new Document();

    try {/*from  w  w w . j a  v  a  2s . c  o  m*/
        PdfWriter.getInstance(document, new FileOutputStream("rapport_formations.pdf"));

        document.open();

        com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png");
        document.add(image);
        document.add(new Paragraph("Liste des formations",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD)));
        document.add(new Paragraph("   "));
        document.add(new Paragraph("    "));
        for (int i = 0; i < formations.size(); i++) {
            document.add(new Paragraph("    "));
            int val = formations.get(i).getId();
            String val1 = formations.get(i).getLieux();
            String val2 = formations.get(i).getDateOuverture();
            String val3 = formations.get(i).getDateCloture();
            String val4 = formations.get(i).getCible();
            String val5 = formations.get(i).getNom();
            String val6 = formations.get(i).getDescription();

            PdfPTable table = new PdfPTable(2);
            PdfPCell cell = new PdfPCell(new Paragraph("formation " + val));
            cell.setColspan(4);
            cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
            cell.setBackgroundColor(BaseColor.GRAY);
            table.addCell(cell);
            table.addCell("Nom formation");
            table.addCell(val5);
            table.addCell("Description");
            table.addCell(val6);
            table.addCell("Lieux");
            table.addCell(val1);
            table.addCell("Date d'ouverture");
            table.addCell(val2);
            table.addCell("Date de cloture");
            table.addCell(val3);
            table.addCell("Cible");
            table.addCell(val4);
            document.add(table);
        }

        document.add(new Paragraph("    "));
        document.add(new Paragraph("    "));
        document.add(new Paragraph("Responsable des formations"));
        document.add(new Paragraph("Federation Tunisenne de Tennis"));
        document.close();
        JOptionPane.showMessageDialog(null, "Rapport Enregistrer");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }
}

From source file:com.ftt.gui.FrameJoueur.java

private void pdf2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pdf2ActionPerformed

    JoueurDAO fd = new JoueurDAO();
    ArrayList<Joueur> joueurs = (ArrayList<Joueur>) fd.select_trie_par_club();
    SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy");

    Document document = new Document();

    try {//from www  .  j  av a  2  s .  c  o m
        PdfWriter.getInstance(document, new FileOutputStream("rapport_joueurs.pdf"));

        document.open();

        com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png");
        document.add(image);
        document.add(new Paragraph("Liste des joueurs",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD)));
        document.add(new Paragraph("   "));

        for (int i = 0; i < joueurs.size(); i++) {
            document.add(new Paragraph("    "));
            document.add(new Paragraph(joueurs.get(i).getNom_club()));
            document.add(new Paragraph("   "));
            Integer val = joueurs.get(i).getId();
            String val1 = joueurs.get(i).getNomJoueur();
            String val2 = joueurs.get(i).getPrenomJoueur();
            String val3 = joueurs.get(i).getDateNaissance();
            String val4 = joueurs.get(i).getCarriere();
            String val5 = joueurs.get(i).getSexe();
            Integer val6 = joueurs.get(i).getPoints();
            PdfPTable table = new PdfPTable(2);
            PdfPCell cell = new PdfPCell(new Paragraph("Joueur id: " + val));
            cell.setColspan(4);
            cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_LEFT);
            cell.setBackgroundColor(BaseColor.GRAY);
            table.addCell(cell);
            table.addCell("Nom");
            table.addCell(val1);
            table.addCell("Prenom");
            table.addCell(val2);
            table.addCell("Date de naissance");
            table.addCell(val3);
            table.addCell("Carriere");
            table.addCell(val4);
            table.addCell("sexe");
            table.addCell(val5);
            table.addCell("points");
            table.addCell(val6.toString());
            document.add(table);
        }

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

        document.add(new Paragraph("Federation Tunisenne de Tennis"));
        document.close();
        JOptionPane.showMessageDialog(null, "Rapport Enregistrer");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }
}

From source file:com.gadroves.gsisinve.controller.FacturarController.java

void PrintToPDF(TbFacturaVenta facturaVenta, TbCLienteFactura cLienteFactura)
        throws DocumentException, IOException {
    Font header = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD);
    Font normalBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD);
    Font normal = new Font(Font.FontFamily.HELVETICA, 12);
    String fileName = "Factura_" + facturaVenta.getId() + ".pdf";
    // step 1//from w w  w . j  a  v  a  2  s  . c  o m
    Document document = new Document();
    // step 2
    PdfWriter.getInstance(document, new FileOutputStream(fileName));
    // step 3
    document.open();
    // step 4
    document.add(new Paragraph("Gadroves S.A Factura De Venta", header));
    document.add(new Paragraph(" "));
    document.add(new Paragraph("Factura N" + facturaVenta.getId(), normalBold));
    document.add(new Chunk("Cliente:            ", normalBold));
    document.add(new Chunk(" "));
    document.add(new Chunk(cLienteFactura.getName(), normal));

    document.add(new Paragraph());
    document.add(new Chunk("Direccin:        ", normalBold));
    document.add(new Chunk(" "));
    document.add(new Chunk(cLienteFactura.getAddress(), normal));

    document.add(new Paragraph());
    document.add(new Chunk("Identificacion: ", normalBold));
    document.add(new Chunk(" "));
    document.add(new Chunk(cLienteFactura.getId(), normal));

    document.add(new Paragraph());
    document.add(new Chunk("Credito:            ", normalBold));
    document.add(new Chunk(" "));
    document.add(new Chunk(Boolean.FALSE.toString(), normal));
    document.add(new Paragraph());

    for (int i = 0; i < 3; i++)
        document.add(new Paragraph(" "));
    createItemsTable(document, facturaVenta);
    document.add(new Paragraph(" "));
    Paragraph subs = new Paragraph();

    subs.setAlignment(Element.ALIGN_RIGHT);
    subs.setIndentationRight(40);
    subs.add(new Chunk("Subtotal:  " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getSub()))));
    subs.add(Chunk.NEWLINE);
    subs.add(new Chunk(
            "Impuestos:  " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getImpuestos()))));
    subs.add(Chunk.NEWLINE);
    subs.add(new Chunk(
            "Total:       " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getTotal()))));
    subs.add(Chunk.NEWLINE);
    document.add(subs);
    // step 5

    document.close();
    Desktop.getDesktop().open(new File(fileName));
}

From source file:com.gadroves.gsisinve.controller.FacturarController.java

private void createItemsTable(Document doc, TbFacturaVenta facturaVenta) throws DocumentException {
    PdfPTable table = new PdfPTable(4);

    PdfPCell c1 = new PdfPCell(new Phrase("Descripcion"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);//w  w  w.ja v  a 2 s.  c om

    c1 = new PdfPCell(new Phrase("Cantidad"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Precio Unitario"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Valor"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    //table.setHeaderRows(1);
    PdfPCell desc;
    PdfPCell cant;
    PdfPCell pu;
    PdfPCell val;
    for (TbLineaFac lineaFac : facturaVenta.getTbLineaFacsById()) {
        desc = new PdfPCell(new Phrase(lineaFac.getDescripcion()));
        cant = new PdfPCell(new Phrase(String.valueOf(lineaFac.getQuant())));
        pu = new PdfPCell(new Phrase(String.valueOf(lineaFac.getP_unitario())));
        val = new PdfPCell(new Phrase(String.valueOf(lineaFac.getTotal())));
        table.addCell(desc);
        table.addCell(cant);
        table.addCell(pu);
        table.addCell(val);
    }
    float[] columnWidths = new float[] { 40f, 10f, 10f, 10f };
    table.setWidths(columnWidths);
    doc.add(table);

}

From source file:com.github.albfernandez.joinpdf.JoinPdf.java

License:Open Source License

private void addImage(final Image image, final Document document, final PdfWriter writer) throws Exception {
    if (image.getWidth() > image.getHeight()) {
        document.setPageSize(new Rectangle(PageSize.A4.getHeight(), PageSize.A4.getWidth()));
    } else {//from w ww.j  a va  2 s  .c o  m
        document.setPageSize(new Rectangle(PageSize.A4.getWidth(), PageSize.A4.getHeight()));
    }
    image.scaleToFit(document.getPageSize().getWidth() - this.margin * 2f,
            document.getPageSize().getHeight() - this.margin * 2f);
    float px = (document.getPageSize().getWidth() - image.getScaledWidth()) / 2f;
    float py = (document.getPageSize().getHeight() - image.getScaledHeight()) / 2f;
    image.setAbsolutePosition(px, py);
    document.newPage();
    document.add(image);
    writePageNumber(writer);
}

From source file:com.github.luischavez.levsym.modulos.funcion.PDF.java

License:Open Source License

public void GeneraPDF(ResultSet Resultados) throws Exception {

    ResultSetMetaData metaData = Resultados.getMetaData();
    Object[] Columnas = new Object[metaData.getColumnCount()];

    String encabezado = "Reportes del Sistema Administrativo" + "\n" + "REGISTROS ACTUALES EN AL BASE DE DATOS"
            + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n";
    Calendar c = Calendar.getInstance();
    String date = Integer.toString(c.get(Calendar.DAY_OF_MONTH)) + "-" + Integer.toString(c.get(Calendar.MONTH))
            + "-" + Integer.toString(c.get(Calendar.YEAR)) + " " + Integer.toString(c.get(Calendar.HOUR_OF_DAY))
            + "-" + Integer.toString(c.get(Calendar.MINUTE)) + "-" + Integer.toString(c.get(Calendar.SECOND));

    Font fuente = new Font(Font.getFamily("ARIAL"), 12, Font.BOLD);

    String choro = "Reporte por fecha de los modulos\n" + "de catalogo" + "\n" + "Systema Administrativo" + "\n"
            + "\n" + "\n" + "\n";

    Image imagen = Image.getInstance(System.getProperty("user.dir") + "/Image/logo.png");
    imagen.setAlignment(Image.TEXTWRAP);

    try {/* w  ww . j av  a  2s  .c o  m*/
        Paragraph linea = new Paragraph(encabezado, fuente);
        Phrase para = new Phrase(choro);
        Paragraph fecha = new Paragraph(date + "\n" + "\n");

        PdfPTable tabla = new PdfPTable(Columnas.length);
        tabla.setWidthPercentage(100);

        //Document documento = new Document(PageSize.LETTER);
        Document documento = new Document(PageSize.A4.rotate(), 50, 50, 100, 72);
        File Dir = new File(System.getProperty("user.dir") + "/Reportes/");
        if (!Dir.exists()) {
            Dir.mkdirs();
        }

        String file = System.getProperty("user.dir") + "/Reportes/" + metaData.getTableName(1) + " " + date
                + ".pdf";

        PdfWriter.getInstance(documento, new FileOutputStream(file));

        documento.open();
        documento.add(imagen);
        documento.add(linea);
        documento.add(para);
        documento.add(fecha);

        for (int x = 0; x < Columnas.length; x++) {
            PdfPCell Celda = new PdfPCell(new Paragraph(metaData.getColumnName(x + 1),
                    FontFactory.getFont("arial", 9, Font.BOLD, BaseColor.RED)));
            Celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(Celda);
        }

        while (Resultados.next()) {
            for (int x = 0; x < Columnas.length; x++) {
                //if(Resultados.getObject(x+1).getClass().getSimpleName().equals("Integer"))
                PdfPCell Celda = new PdfPCell(new Paragraph(String.valueOf(Resultados.getObject(x + 1)),
                        FontFactory.getFont("arial", 9, BaseColor.BLACK)));
                Celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(Celda);
            }
        }

        documento.add(tabla);
        documento.close();
    } catch (DocumentException e) {
        Log.SaveLog(e.toString());
        JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    } catch (IOException e) {
        Log.SaveLog(e.toString());
        JOptionPane.showMessageDialog(null, e.getMessage(), "error", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.github.wolfposd.imsqti2pdf.PDFCreator.java

License:Open Source License

private void writeQuestions(Paragraph paragraph, Document document, boolean showCorrectAnswer,
        ArrayList<Question> qlist) throws DocumentException, IOException {
    for (int i = 0; i < qlist.size(); i++) {
        Question question = qlist.get(i);
        paragraph.clear();//  ww  w . j  a v a 2s.  c o m

        // addQuestionNumber(paragraph, i, qlist.size());

        addQuestionText(paragraph, question, i);

        addAnswerTexts(paragraph, showCorrectAnswer, question);

        fixFonts(paragraph);

        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(100);
        table.setKeepTogether(true);

        PdfPCell cell = new PdfPCell();
        cell.addElement(paragraph);
        cell.setBorderColor(BaseColor.WHITE);
        cell.setBorder(PdfPCell.NO_BORDER);

        table.addCell(cell);

        document.add(table);
    }

}

From source file:com.gp.cong.logisoft.reports.LclExportVoyageNotificationPdf.java

public void createPdf(String realPath, String outputFileName, Long notificationId, String companyName,
        LclFileNumber fileNumber) throws DocumentException, IOException, Exception {
    LclExportNotiFicationForm lclExportNotiFicationForm = new LclExportsVoyageNotificationDAO()
            .getNotificationDetail(notificationId);
    LclSsDetail lclSsDetail = null;//from w w w  .jav  a 2 s  .com
    String pod = "", finalDest = "";
    String voyageHeading = "Voyage Notification";

    if (lclExportNotiFicationForm != null) {
        lclSsDetail = new LclSsDetailDAO().findByTransMode(lclExportNotiFicationForm.getHeaderId(), "V");
        if (lclSsDetail != null) {
            pod = new LclUtils().getConcatenatedOriginByUnlocation(lclSsDetail.getArrival());
            finalDest = new LclUtils()
                    .getConcatenatedOriginByUnlocation(lclSsDetail.getLclSsHeader().getDestination());
        }
    }
    companyCode = new SystemRulesDAO().getSystemRules("CompanyCode");
    String path = LoadLogisoftProperties.getProperty(
            companyCode.equalsIgnoreCase("03") ? "application.image.logo" : "application.image.econo.logo");

    Document document = new Document(PageSize.A4);
    PdfWriter.getInstance(document, new FileOutputStream(outputFileName));
    document.open();
    document.add(imageBlock(realPath, path));
    document.add(headerPage(voyageHeading));
    document.add(informationBlock(companyName, pod, finalDest));
    document.add(changesBlock(lclSsDetail, lclExportNotiFicationForm));
    document.add(containerBlock(companyName, finalDest, fileNumber, lclExportNotiFicationForm));
    document.add(reasonBlock(lclExportNotiFicationForm));
    document.add(footerBlock());
    document.close();
}

From source file:com.grant.report.BillPdf.java

private void addTitlePage(Document document, PrintDetails printDetails) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*from   w w  w . ja  v a  2  s .c o  m*/
    // Lets write a big header
    preface.add(new Paragraph("GRANT TECH HOLDINGS", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("No, 407 A, Colombo Road, Pepiliyana", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            subFont));
    preface.add(new Paragraph("Tel/Fax :0112 199 100 | 0719 192 815 | 0719 392 815", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            subFont));
    preface.add(new Paragraph("E-mail :granttech@sltnet.lk | granttechholdings@gmail.com", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            subFont));
    preface.add(new Paragraph(
            "____________________________________________________________________________________", smallBold));

    preface.add(new Paragraph("Customer Name : " + printDetails.getCustomerName(), smallBold));

    preface.add(new Paragraph("Address : " + printDetails.getAddress(), smallBold));

    preface.add(new Paragraph(
            "Date: " + printDetails.getInvoiceNo() + "                | Order No: " + printDetails.getOrderNo(),
            smallBold));

    preface.add(new Paragraph("Pay Type: " + printDetails.getPayType() + "                | Sales Code: "
            + printDetails.getCustomerName(), smallBold));

    preface.add(new Paragraph("Cheque No: " + printDetails.getNoPay(), smallBold));

    createTable(preface);

    Paragraph preface2 = new Paragraph();
    preface2.setIndentationLeft(350);

    preface2.add(new Paragraph("Sub Total : " + printDetails.getSubTotal(), smallBold));

    preface2.add(new Paragraph("Discount  : " + printDetails.getDiscount() + " %", smallBold));

    preface2.add(new Paragraph("Total  : " + printDetails.getTotal(), smallBold));

    Paragraph preface3 = new Paragraph();

    preface3.add(new Paragraph(
            "____________________________________________________________________________________", smallBold));

    preface3.add(new Paragraph("Goods once sold will not be taken back. ", smallBold2));

    preface3.add(new Paragraph(
            "Cheques to be drawn in favour of Grant Tech Holdings (Pvt) Ltd 1146009208-Commercial Bank-Wadduwa. ",
            verySmBold));
    preface3.add(new Paragraph("goods are accepted in good condition. ", verySmBold));

    preface3.add(new Paragraph(
            "____________________________________________________________________________________", smallBold));

    preface3.add(new Paragraph(
            "Name:___________________________________________                          Signature:__________________________________________",
            smallBold3));

    preface3.add(new Paragraph(
            "I.D No (If credit):__________________________________                          Date:______________________________________________",
            smallBold3));

    preface3.add(new Paragraph(
            "Checked by:_______________________________________                        Authorized by:_______________________________________",
            smallBold3));

    preface3.add(new Paragraph(
            "____________________________________________________________________________________", smallBold));

    // now add all this to the document
    document.add(preface);
    document.add(preface2);
    document.add(preface3);
    document.newPage();
}