Example usage for com.itextpdf.text FontFactory HELVETICA

List of usage examples for com.itextpdf.text FontFactory HELVETICA

Introduction

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

Prototype

String HELVETICA

To view the source code for com.itextpdf.text FontFactory HELVETICA.

Click Source Link

Document

This is a possible value of a base 14 type 1 font

Usage

From source file:org.openscience.cdk.applications.taverna.renderer.DrawPDF.java

License:Open Source License

public static void drawMoleculesAsPDF(List<IAtomContainer> molecules, File file) throws Exception {
    Document pdf = new Document();
    PdfWriter writer = PdfWriter.getInstance(pdf, new FileOutputStream(file));
    pdf.open();//from www  . j a v  a  2  s.c  o m
    Paragraph para = new Paragraph();
    Font font = FontFactory.getFont(FontFactory.HELVETICA, 24);
    para.setFont(font);
    para.setAlignment(Element.ALIGN_CENTER);
    para.add("CDK-Taverna 2.0");
    pdf.add(para);
    para = new Paragraph();
    font = FontFactory.getFont(FontFactory.HELVETICA, 12);
    para.setFont(font);
    para.setAlignment(Element.ALIGN_CENTER);
    para.add("The open-source chemo-/bioinformatics workflow solution\n\n\n");
    pdf.add(para);
    PdfPTable table = new PdfPTable(ncol);
    for (IAtomContainer molecule : molecules) {
        PdfPCell cell = new PdfPCell();
        cell.disableBorderSide(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
        BufferedImage image = Draw2DStructure.drawMolecule(molecule, (int) pdf.getPageSize().getWidth(), height,
                0.95);
        java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(image.getSource());
        cell.addElement(Image.getInstance(awtImage, null));
        table.addCell(cell);
        cell = new PdfPCell();
        cell.disableBorderSide(PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
        para = new Paragraph();
        font = FontFactory.getFont(FontFactory.HELVETICA, 12);
        para.setFont(font);
        para.add("\n");
        for (Entry<Object, Object> entry : molecule.getProperties().entrySet()) {
            try {
                String key = String.valueOf(entry.getKey());
                String value = String.valueOf(entry.getValue());
                para.add(key + ":\n" + value + "\n\n");
            } catch (Exception e) {
                // Not a String entry --> skip
            }
        }
        cell.addElement(para);
        table.addCell(cell);
    }
    pdf.add(table);
    pdf.close();
}

From source file:PdfCreation.PdfTableWriter.java

public Section addTable(JTable table) {
    DefaultTableModel model = (DefaultTableModel) table.getModel();
    Section ourTableSection = new Chapter(0)
            .addSection(this.newParagraph("Information Table", true, false, false));
    ourTableSection.add(new Paragraph(" "));
    PdfPTable ourTable = new PdfPTable(model.getColumnCount() + 1);
    int count = 1;

    ourTable.addCell(new Phrase("    ", FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD)));
    for (int i = 0; i < model.getColumnCount(); i++) {
        Phrase phrase = new Phrase(model.getColumnName(i).toString(),
                FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD));
        ourTable.addCell(new PdfPCell(phrase));

    }//from   ww  w  . java  2s. com

    for (int i = 0; i < model.getRowCount(); i++) {
        ourTable.addCell(new Phrase("" + count++, FontFactory.getFont(FontFactory.HELVETICA, 8)));
        for (int j = 0; j < model.getColumnCount(); j++) {
            Phrase phrase = new Phrase(model.getValueAt(i, j).toString(),
                    FontFactory.getFont(FontFactory.HELVETICA, 8));
            ourTable.addCell(phrase);
        }
    }

    ourTableSection.add(ourTable);

    return ourTableSection;
}

From source file:presentation.frmReportForm.java

private void btnGenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateActionPerformed
    Date dateNow = new Date();
    SimpleDateFormat df = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss");

    System.out.println(dtcMonthChooser.getMonth());
    System.out.println(dtcYearChooser.getYear());

    if (radInMonth.isSelected()) {
        List<Transfer> transferList = new ArrayList<>();

        transferList = empObj.searchRecordByMonth(dtcMonthChooser.getMonth() + 1, dtcYearChooser.getYear());

        Document document = new Document();
        try {/*from  w  w w.ja  va 2  s  .  c  o m*/
            Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD);

            String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf";
            PdfWriter.getInstance(document, new FileOutputStream(fileName));

            document.open();

            Image imageLogo = Image
                    .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png"));
            imageLogo.setAbsolutePosition(20, 750f);
            document.add(imageLogo);

            Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle);
            titlePara.setAlignment(Element.ALIGN_CENTER);
            titlePara.setSpacingAfter(5);
            document.add(titlePara);

            Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh",
                    FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC));
            creditPara.setAlignment(Element.ALIGN_CENTER);
            creditPara.setSpacingAfter(10);
            document.add(creditPara);

            Paragraph slashPara = new Paragraph(
                    "Transfer records at " + (dtcMonthChooser.getMonth() + 1) + "/" + dtcYearChooser.getYear(),
                    FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD));
            slashPara.setSpacingAfter(40);
            slashPara.setAlignment(Element.ALIGN_CENTER);
            document.add(slashPara);

            PdfPTable table = new PdfPTable(5);
            table.setWidthPercentage(100);

            Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD);
            Paragraph paragraphCellHeading = new Paragraph("Report", font);

            PdfPCell cellHeading = new PdfPCell(paragraphCellHeading);
            BaseColor myColor = WebColors.getRGBColor("#41a5c2");
            cellHeading.setColspan(5);
            cellHeading.setBackgroundColor(myColor);
            cellHeading.setFixedHeight(30.3f);
            cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellHeading);

            Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK);

            PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody));
            cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle1);
            PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody));
            cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle2);
            PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody));
            cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle3);
            PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody));
            cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle4);
            PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody));
            cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitleStatus);

            int cellColorCheck = 1;
            for (Transfer e : transferList) {
                PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId()));
                PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId()));
                PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId()));
                PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId()));
                PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus()));
                if (cellColorCheck % 2 == 1) {
                    cellBody1.setBackgroundColor(BaseColor.ORANGE);
                    cellBody2.setBackgroundColor(BaseColor.ORANGE);
                    cellBody3.setBackgroundColor(BaseColor.ORANGE);
                    cellBody4.setBackgroundColor(BaseColor.ORANGE);
                    cellBody5.setBackgroundColor(BaseColor.ORANGE);
                }
                table.addCell(cellBody1);
                table.addCell(cellBody2);
                table.addCell(cellBody3);
                table.addCell(cellBody4);
                table.addCell(cellBody5);
                cellColorCheck++;
            }

            document.add(table);

            JOptionPane.showMessageDialog(this, "Report saved");

            if (Desktop.isDesktopSupported()) {
                File reportFile = new File(fileName);
                Desktop.getDesktop().open(reportFile);
                ;
            }

            document.close();
        } catch (DocumentException | FileNotFoundException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    if (radInDateRange.isSelected()) {
        try {
            List<Transfer> transferList = new ArrayList<>();

            java.sql.Date fromDateSql = formatDateForSearching(dtcFromDate.getDate());
            java.sql.Date toDateSql = formatDateForSearching(dtcToDate.getDate());
            transferList = empObj.searchRecordByDate(fromDateSql, toDateSql);

            Document document = new Document();
            try {
                Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD);

                String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf";
                PdfWriter.getInstance(document, new FileOutputStream(fileName));

                document.open();

                Image imageLogo = Image
                        .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png"));
                imageLogo.setAbsolutePosition(20, 750f);
                document.add(imageLogo);

                Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle);
                titlePara.setAlignment(Element.ALIGN_CENTER);
                titlePara.setSpacingAfter(5);
                document.add(titlePara);

                Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh",
                        FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC));
                creditPara.setAlignment(Element.ALIGN_CENTER);
                creditPara.setSpacingAfter(10);
                document.add(creditPara);

                SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yyyy");
                String fromDate = df2.format(dtcFromDate.getDate());
                String toDate = df2.format(dtcToDate.getDate());

                Paragraph slashPara = new Paragraph("Transfer records from " + fromDate + " to " + toDate,
                        FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD));
                slashPara.setSpacingAfter(40);
                slashPara.setAlignment(Element.ALIGN_CENTER);
                document.add(slashPara);

                PdfPTable table = new PdfPTable(5);
                table.setWidthPercentage(100);

                Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD);
                Paragraph paragraphCellHeading = new Paragraph("Report", font);

                PdfPCell cellHeading = new PdfPCell(paragraphCellHeading);
                BaseColor myColor = WebColors.getRGBColor("#41a5c2");
                cellHeading.setColspan(5);
                cellHeading.setBackgroundColor(myColor);
                cellHeading.setFixedHeight(30.3f);
                cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cellHeading);

                Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK);

                PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody));
                cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cellTitle1);
                PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody));
                cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cellTitle2);
                PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody));
                cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cellTitle3);
                PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody));
                cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cellTitle4);
                PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody));
                cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cellTitleStatus);

                int cellColorCheck = 1;
                for (Transfer e : transferList) {
                    PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId()));
                    PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId()));
                    PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId()));
                    PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId()));
                    PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus()));
                    if (cellColorCheck % 2 == 1) {
                        cellBody1.setBackgroundColor(BaseColor.ORANGE);
                        cellBody2.setBackgroundColor(BaseColor.ORANGE);
                        cellBody3.setBackgroundColor(BaseColor.ORANGE);
                        cellBody4.setBackgroundColor(BaseColor.ORANGE);
                        cellBody5.setBackgroundColor(BaseColor.ORANGE);
                    }
                    table.addCell(cellBody1);
                    table.addCell(cellBody2);
                    table.addCell(cellBody3);
                    table.addCell(cellBody4);
                    table.addCell(cellBody5);
                    cellColorCheck++;
                }

                document.add(table);
                JOptionPane.showMessageDialog(this, "Report saved");

                if (Desktop.isDesktopSupported()) {
                    File reportFile = new File(fileName);
                    Desktop.getDesktop().open(reportFile);
                    ;
                }

                document.close();
            } catch (DocumentException | FileNotFoundException ex) {
                Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ParseException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    if (radInProject.isSelected()) {
        String fromProjectId = (String) cbxFromProject.getSelectedItem();
        String toProjectId = (String) cbxToProject.getSelectedItem();
        List<Transfer> transferList = new ArrayList<>();
        String andOr = "";
        if (cbxAndOr.getSelectedItem().equals("And")) {
            andOr = "and";
            transferList = empObj.searchRecordByFromAndToProject(fromProjectId, toProjectId, andOr);
        } else {
            andOr = "or";
            transferList = empObj.searchRecordByFromAndToProject(fromProjectId, toProjectId, andOr);
        }

        Document document = new Document();
        try {
            Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD);

            String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf";
            PdfWriter.getInstance(document, new FileOutputStream(fileName));

            document.open();

            Image imageLogo = Image
                    .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png"));
            imageLogo.setAbsolutePosition(20, 750f);
            document.add(imageLogo);

            Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle);
            titlePara.setAlignment(Element.ALIGN_CENTER);
            titlePara.setSpacingAfter(5);
            document.add(titlePara);

            Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh",
                    FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC));
            creditPara.setAlignment(Element.ALIGN_CENTER);
            creditPara.setSpacingAfter(10);
            document.add(creditPara);

            Paragraph slashPara = new Paragraph(
                    "Transfer records from Project ID " + fromProjectId + " " + andOr + " " + toProjectId,
                    FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD));
            slashPara.setSpacingAfter(40);
            slashPara.setAlignment(Element.ALIGN_CENTER);
            document.add(slashPara);

            PdfPTable table = new PdfPTable(5);
            table.setWidthPercentage(100);

            Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD);
            Paragraph paragraphCellHeading = new Paragraph("Report", font);

            PdfPCell cellHeading = new PdfPCell(paragraphCellHeading);
            BaseColor myColor = WebColors.getRGBColor("#41a5c2");
            cellHeading.setColspan(5);
            cellHeading.setBackgroundColor(myColor);
            cellHeading.setFixedHeight(30.3f);
            cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellHeading);

            Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK);

            PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody));
            cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle1);
            PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody));
            cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle2);
            PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody));
            cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle3);
            PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody));
            cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle4);
            PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody));
            cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitleStatus);

            int cellColorCheck = 1;
            for (Transfer e : transferList) {
                PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId()));
                PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId()));
                PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId()));
                PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId()));
                PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus()));
                if (cellColorCheck % 2 == 1) {
                    cellBody1.setBackgroundColor(BaseColor.ORANGE);
                    cellBody2.setBackgroundColor(BaseColor.ORANGE);
                    cellBody3.setBackgroundColor(BaseColor.ORANGE);
                    cellBody4.setBackgroundColor(BaseColor.ORANGE);
                    cellBody5.setBackgroundColor(BaseColor.ORANGE);
                }
                table.addCell(cellBody1);
                table.addCell(cellBody2);
                table.addCell(cellBody3);
                table.addCell(cellBody4);
                table.addCell(cellBody5);
                cellColorCheck++;
            }

            document.add(table);
            JOptionPane.showMessageDialog(this, "Report saved");

            if (Desktop.isDesktopSupported()) {
                File reportFile = new File(fileName);
                Desktop.getDesktop().open(reportFile);
                ;
            }

            document.close();
        } catch (DocumentException | FileNotFoundException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (radAllRecord.isSelected()) {
        List<Transfer> transferList = new ArrayList<>();
        transferList = empObj.searchAllRecord();

        Document document = new Document();
        try {
            Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD);

            String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf";
            PdfWriter.getInstance(document, new FileOutputStream(fileName));

            document.open();

            Image imageLogo = Image
                    .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png"));
            imageLogo.setAbsolutePosition(20, 750f);
            document.add(imageLogo);

            Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle);
            titlePara.setAlignment(Element.ALIGN_CENTER);
            titlePara.setSpacingAfter(5);
            document.add(titlePara);

            Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh",
                    FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC));
            creditPara.setAlignment(Element.ALIGN_CENTER);
            creditPara.setSpacingAfter(10);
            document.add(creditPara);

            Paragraph slashPara = new Paragraph("All transfer records",
                    FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD));
            slashPara.setSpacingAfter(40);
            slashPara.setAlignment(Element.ALIGN_CENTER);
            document.add(slashPara);

            PdfPTable table = new PdfPTable(5);
            table.setWidthPercentage(100);

            Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD);
            Paragraph paragraphCellHeading = new Paragraph("Report", font);

            PdfPCell cellHeading = new PdfPCell(paragraphCellHeading);
            BaseColor myColor = WebColors.getRGBColor("#41a5c2");
            cellHeading.setColspan(5);
            cellHeading.setBackgroundColor(myColor);
            cellHeading.setFixedHeight(30.3f);
            cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellHeading);

            Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK);

            PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody));
            cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle1);
            PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody));
            cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle2);
            PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody));
            cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle3);
            PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody));
            cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle4);
            PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody));
            cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitleStatus);

            int cellColorCheck = 1;
            for (Transfer e : transferList) {
                PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId()));
                PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId()));
                PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId()));
                PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId()));
                PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus()));
                if (cellColorCheck % 2 == 1) {
                    cellBody1.setBackgroundColor(BaseColor.ORANGE);
                    cellBody2.setBackgroundColor(BaseColor.ORANGE);
                    cellBody3.setBackgroundColor(BaseColor.ORANGE);
                    cellBody4.setBackgroundColor(BaseColor.ORANGE);
                    cellBody5.setBackgroundColor(BaseColor.ORANGE);
                }
                table.addCell(cellBody1);
                table.addCell(cellBody2);
                table.addCell(cellBody3);
                table.addCell(cellBody4);
                table.addCell(cellBody5);
                cellColorCheck++;
            }

            document.add(table);
            JOptionPane.showMessageDialog(this, "Report saved");

            if (Desktop.isDesktopSupported()) {
                File reportFile = new File(fileName);
                Desktop.getDesktop().open(reportFile);
                ;
            }

            document.close();
        } catch (DocumentException | FileNotFoundException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:project1.GENERALCV.java

private void createcvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createcvActionPerformed
    String firstname, lastname, contactno, email, phonenumber, address;
    String dob, martialStatus, cast, careerObjectives;
    String university, city, startdatee, enddatee, coursesAndQualification;
    String acedemicQualification, certificates, experience, techskills, addSkills;
    String achivements, additionalCertificates, references, hobbies;
    firstname = txtname.getText();// www .j  a  v  a 2  s .co  m
    lastname = txtlastname.getText();

    email = txtemail.getText();
    phonenumber = txtMobileNo.getText();

    address = txtAddress.getText();

    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");

    String link = txtLink.getText();

    // dob= dateFormat.format(dateOfBirth.getDate());
    martialStatus = cmbMartialStatus.getSelectedItem().toString();
    // cast=txtcast.getText();
    //  careerObjectives=txtcareer.getText();

    university = txtCollegeName.getText();
    city = txtCity.getText();
    // startdatee=dateFormat.format(startdate.getDate());
    // enddatee=dateFormat.format(enddate.getDate());
    coursesAndQualification = txtExtraCourses.getText();

    //  certificates=txtcertificats.getText();
    // experience=txtexperience.getText();
    techskills = txttechnical.getText();
    // addSkills=txtadditional.getText();

    references = txtreference.getText();

    try {
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/cvmaker", "root", "12345");

        pInsertPerson = con
                .prepareStatement("INSERT INTO PERSONS(NAMEE,CONTACTNO,EMAILID,ADDRESS) VALUES(?,?,?,?)");

        pInsertPerson.setString(1, firstname + lastname);
        pInsertPerson.setString(2, phonenumber);
        pInsertPerson.setString(3, email);
        pInsertPerson.setString(4, address);
        pInsertPerson.executeUpdate();

        JOptionPane.showMessageDialog(null, "Data Is Alo Saved In Database....");

        showRecords();

    } catch (Exception e) {

        System.out.println(e.toString());

    }

    Statement statement;

    String selectTableSQL = "SELECT ID FROM PERSONS";
    int ss = 0;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/cvmaker", "root", "12345");

        statement = con.createStatement();

        //System.out.println(selectTableSQL);
        // execute select SQL stetementS
        ResultSet rs = statement.executeQuery(selectTableSQL);

        while (rs.next()) {

            ss = rs.getInt("ID");
        }
    } catch (SQLException e) {
        System.out.println(e.toString());

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

    int newcvid = ss;

    try {

        OutputStream file = new FileOutputStream(new File("D:\\PDFFILES\\" + firstname + lastname + ".pdf"));

        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();
        //     Image im=Image.getInstance("E:\\PDFFILES\\FUUAST.png");
        //   document.add(new Paragraph(""));
        // document.add(im);

        Paragraph title1 = new Paragraph(firstname + " " + lastname + " Cv", FontFactory
                .getFont(FontFactory.HELVETICA, 36, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));

        Chapter chapter1 = new Chapter(title1, 1);

        chapter1.setNumberDepth(0);
        document.add(chapter1);

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

        List unorderedList = new List(List.UNORDERED);
        unorderedList.add(new ListItem("Mobile No:" + phonenumber));
        unorderedList.add(new ListItem("Email:" + city));
        unorderedList.add(new ListItem("Address:" + address));
        //    unorderedList.add(new ListItem("End Date:" + enddatee));
        document.add(unorderedList);

        //  document.add(new Paragraph("Address:"+address));
        Paragraph title2 = new Paragraph("Personal Information", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title2.setAlignment(Element.ALIGN_CENTER);

        document.add(title2);
        //   document.add(new Paragraph("Date Of Birth:" + dob));

        document.add(new Paragraph("Martial Status:" + martialStatus));
        //   document.add(new Paragraph("Cast:"+cast));
        //   document.add(new Paragraph("Career Objectives:"+careerObjectives));

        Paragraph title3 = new Paragraph("Qualification", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title3.setAlignment(Element.ALIGN_CENTER);
        document.add(title3);
        PdfPTable table = new PdfPTable(2); // 3 columns.
        document.add(new Paragraph("\n\n"));
        PdfPCell cell1 = new PdfPCell(new Paragraph("Insituite Name:"));
        PdfPCell cell2 = new PdfPCell(new Paragraph(university));

        PdfPCell cell3 = new PdfPCell(new Paragraph("City:"));
        PdfPCell cell4 = new PdfPCell(new Paragraph(city));

        PdfPCell cell5 = new PdfPCell(new Paragraph("Start Date:"));
        // PdfPCell cell6 = new PdfPCell(new Paragraph(startdatee));

        PdfPCell cell7 = new PdfPCell(new Paragraph("End Date:"));
        //PdfPCell cell8 = new PdfPCell(new Paragraph(enddatee));

        PdfPCell cell71 = new PdfPCell(new Paragraph("Extra Courses:"));
        PdfPCell cell81 = new PdfPCell(new Paragraph(coursesAndQualification));
        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);
        table.addCell(cell4);
        table.addCell(cell5);
        //   table.addCell(cell6);
        table.addCell(cell7);
        //   table.addCell(cell8);
        table.addCell(cell71);
        table.addCell(cell81);

        document.add(table);

        //  document.add(new Paragraph("Extra Courses:"+coursesAndQualification));
        //   document.add(new Paragraph("Certificates:"+certificates));
        //
        Paragraph title4 = new Paragraph("Experience", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title4.setAlignment(Element.ALIGN_CENTER);
        document.add(title4);
        //      document.add(new Paragraph(""+experience));

        Paragraph title5 = new Paragraph("Skills", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title5.setAlignment(Element.ALIGN_CENTER);
        document.add(title5);

        document.add(new Paragraph("Technical Skills:" + techskills));
        //    document.add(new Paragraph("Additional Skills:"+addSkills));
        Paragraph title6 = new Paragraph("References", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title6.setAlignment(Element.ALIGN_CENTER);
        document.add(title6);
        document.add(new Paragraph("References:" + references));

        //     Anchor anchor;
        //     anchor = new Anchor(link, FontFactory.getFont(FontFactory.HELVETICA,12, Font.UNDERLINE, new CMYKColor(0, 0,0,255)));
        //    anchor.setReference( link);
        Paragraph paragraph = new Paragraph("Profile Link:");
        //     paragraph.add(anchor);
        document.add(paragraph);
        Paragraph title11 = new Paragraph(
                "                                                 Cv Number:" + newcvid, FontFactory
                        .getFont(FontFactory.HELVETICA, 15, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));

        document.add(new Paragraph("\n\n"));
        document.add(title11);
        try {
            Desktop desktop = Desktop.getDesktop();
            if (desktop.isSupported(Desktop.Action.OPEN)) {
                desktop.open(new File("D:\\PDFFILES\\" + firstname + lastname + ".pdf"));
            } else {
                System.out.println("Open is not supported");
            }
        } catch (IOException exp) {
            exp.printStackTrace();
        }
        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:project1.SimplePdf.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:

    int id;/*from   www  .  jav a 2 s . c  o m*/
    String name;
    id = Integer.parseInt(txtid.getText());
    name = txtname.getText();

    try {

        OutputStream file = new FileOutputStream(new File("F:\\PDFFILES\\" + id + ".pdf"));

        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();
        //     Image im=Image.getInstance("E:\\PDFFILES\\FUUAST.png");
        //   document.add(new Paragraph(""));
        // document.add(im);
        Paragraph title1 = new Paragraph(name + id,

                FontFactory.getFont(FontFactory.HELVETICA,

                        36, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));

        Chapter chapter1 = new Chapter(title1, 1);

        chapter1.setNumberDepth(0);
        document.add(chapter1);

        document.add(new Paragraph("\n\n\n\n"));
        document.add(new Paragraph("Name: " + name));
        document.add(new Paragraph("Id: " + id));

        try {
            Desktop desktop = Desktop.getDesktop();
            if (desktop.isSupported(Desktop.Action.OPEN)) {
                desktop.open(new File("D:\\PDFFILES\\" + id + ".pdf"));
            } else {
                System.out.println("Open is not supported");
            }
        } catch (IOException exp) {
            exp.printStackTrace();
        }
        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }

}

From source file:reporteFertilizacion.ReporteResultadoLaboratorio.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   www .  j a  v  a 2 s  . com*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/pdf");
    try {
        Font font9BoldWhite = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.BOLD, BaseColor.WHITE);
        Font font7Bold = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.BOLD);
        Font font7Normal = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.NORMAL);
        Font font8Bold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD);
        Font font8Normal = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL);
        Font font9Bold = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.BOLD);
        Font font9Normal = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL);
        Font font10Bold = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD);
        Font font10Normal = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);
        Font font12Bold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
        Font font12Normal = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
        Font font14Bold = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD);
        Font font14Normal = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL);
        Font font18Bold = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD);
        Font font22Bold = FontFactory.getFont(FontFactory.HELVETICA, 22, Font.BOLD);

        //obtencion parametros *********************************************************
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Map params = facesContext.getExternalContext().getRequestParameterMap();
        ObjectId parametroObtenido = new ObjectId(params.get("idMuestra").toString());

        ResultadoLaboratorio resLab = ResultadoLaboratorio.getResultadoLaboratorioById(parametroObtenido);
        MuestraLaboratorio muestra = MuestraLaboratorio.getMuestraLaboratorioById(resLab.getMuestra());
        Cliente cli = Cliente.getClienteById(
                Hacienda.getHaciendaById(muestra.getSiembraCultivo().getIdHacienda()).getIdCliente());
        Hacienda hac = Hacienda
                .getHaciendaById(Hacienda.getHaciendaById(muestra.getSiembraCultivo().getIdHacienda()).getId());
        //Lote lot = Lote.getLoteById(muestra.getLote());
        //String lot = muestra.getLote();
        Cultivo cul = Cultivo.getCultivoById(muestra.getSiembraCultivo().getIdCultivo());

        String cliente = cli.getNombre().toUpperCase();
        String ubicacion = Canton.getCantonById(cli.getCanton()).getNombre() + " - "
                + Canton.getCantonById(cli.getCanton()).getLeyendaProvincia() + " - "
                + Canton.getCantonById(cli.getCanton()).getLeyendaPais();
        String codigMuestra = muestra.getCodigo();

        String hacienda = hac.getNombre();
        String cultivo = cul.getNombre();
        //String varie = Variedad.getVariedadById(lot.getIdVariedad()).getNombre();
        String varie = muestra.getSiembraCultivo().getLeyendaVariedad();
        //String estacionMonitoreo = lot.getEstacion().get(0).getCodigo();
        String estacionMonitoreo = muestra.getSiembraCultivo().getUnidadManejo();
        //String estacionMonitoreo = muestra.getLoteCompleto().getListadoMonitoreo().get(0).getCodigo();
        String tituloProyecto = "Anlisis" + resLab.getLeyendaMatriz();
        String tipoMuestra = resLab.getLeyendaMatriz();
        String numeroMuestra = Integer.toString(
                MuestraLaboratorio.getNumberMuestraLaboratorio(muestra.getId(), muestra.getIdSiembraCultivo()));
        String numeroMonitoreo = numeroMuestra;
        //String lote = lot.getCodigo();
        String lote = "";
        int nn = muestra.getSiembraCultivo().getListaLotesSiembra().size();
        for (int i = 0; i < nn; i++) {
            lote = lote.concat(muestra.getSiembraCultivo().getListaLotesSiembra().get(i).getLeyendaLote());
        }

        String muestreador = muestra.getMuestreador();
        String fechaMuestreo = muestra.getFechaFormatMuestreo();
        String fechaRecepcionMuestra = muestra.getFechaFormatEnvio();
        String fechaResultado = resLab.getFechaFormatResultado();
        String periodoPrueba = resLab.getFechaFormatRecepcion() + " al " + resLab.getFechaFormatResultado();

        String contenidoHoja1 = TextoReporteResultadoLaboratorio.getByReferencia("HOJA 1 TEXTO INFORME")
                .getDescripcion();
        String responsableTecnico = TextoReporteResultadoLaboratorio.getByReferencia("RESPONSABLE TECNICO")
                .getDescripcion();
        String datosLaboratorio = TextoReporteResultadoLaboratorio.getByReferencia("DATOS LABORATORIO")
                .getDescripcion();
        String piePagina = TextoReporteResultadoLaboratorio.getByReferencia("PIE DE PAGINA").getDescripcion();
        String contenidoHoja2 = TextoReporteResultadoLaboratorio.getByReferencia("HOJA 2 OBSERVACION")
                .getDescripcion();

        //fin obtencion parametros *****************************************************

        /* TODO output your page here. You may use following sample code. */
        float left = 60;
        float right = 30;
        float top = 0;
        float bottom = 0;
        Document document = new Document(PageSize.A4, left, right, top, bottom);
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());

        //FOOTER TABLE *****************************************************************
        PdfPTable table = new PdfPTable(1);
        table.setTotalWidth(550);
        PdfPCell cell = new PdfPCell(new Phrase(piePagina, font8Normal));
        cell.setBackgroundColor(BaseColor.GREEN);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("www.agrorum.com.ec", font9BoldWhite));
        cell.setBackgroundColor(BaseColor.ORANGE);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        table.addCell(cell);

        FooterTable event = new FooterTable(table);
        writer.setPageEvent(event);
        //FIN FOOTER TABLE *****************************************************************

        document.open();

        //HOJA 1 *********************************************************************************************************************************                        
        //IMAGE **********************************************************************************
        String relativeWebPathAg = "/images/agrorum.png";
        String absoluteDiskPathAg = getServletContext().getRealPath(relativeWebPathAg);
        Image logoAg = Image.getInstance(absoluteDiskPathAg);
        logoAg.setAbsolutePosition(10f, 750f);
        logoAg.scalePercent(80f);
        document.add(logoAg);

        String relativeWebPathEu = "/images/eurofins.png";
        String absoluteDiskPathEu = getServletContext().getRealPath(relativeWebPathEu);
        Image logoEu = Image.getInstance(absoluteDiskPathEu);
        logoEu.setAbsolutePosition(500f, 770f);
        logoEu.scalePercent(60f);
        document.add(logoEu);
        //FIN IMAGE ********************************************************************************         

        //CLIENTE UBICACION MUESTRA*****************************************************************
        Paragraph parphRepor = new Paragraph("Reporte de anlisis 1/2", font10Normal);
        parphRepor.setAlignment(Element.ALIGN_RIGHT);
        parphRepor.setSpacingBefore(90f);
        Paragraph parphCli = new Paragraph(cliente, font10Bold);
        parphCli.setAlignment(Element.ALIGN_LEFT);
        parphCli.setSpacingBefore(15f);
        Paragraph parphUbi = new Paragraph(ubicacion, font10Bold);
        parphUbi.setAlignment(Element.ALIGN_LEFT);
        parphUbi.setSpacingBefore(15f);
        //PARRAFO combinado con frases********************************************
        Phrase p1 = new Phrase("Cdigo de la Muestra:     ", font10Normal);
        Phrase p2 = new Phrase(codigMuestra, font10Bold);
        Paragraph parphMue = new Paragraph(p1);
        parphMue.add(p2);
        parphMue.setAlignment(Element.ALIGN_LEFT);
        parphMue.setSpacingBefore(15f);
        //FIN PARRAFO combinado***************************************************

        document.add(parphRepor);
        document.add(parphCli);
        document.add(parphUbi);
        document.add(parphMue);

        //FIN CLIENTE UBICACION MUESTRA*************************************************************
        //TABLA ***********************************************************************************
        PdfPTable tableDatos = new PdfPTable(new float[] { 0.20f, 0.80f });
        tableDatos.setWidthPercentage(100);

        tableDatos.addCell(getCell("Propiedad:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(hacienda, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Cultivo Actual:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(cultivo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Estacin Monitoreo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(estacionMonitoreo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Ttulo Proyecto:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(tituloProyecto, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Tipo Muestra:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(tipoMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Nmero Muestra:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(numeroMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Nmero Monitoreo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(numeroMonitoreo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Lote:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(lote, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Muestreador:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(muestreador.toUpperCase(), PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Fecha Muestreo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(fechaMuestreo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Recepcin Muestra:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(fechaRecepcionMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.addCell(getCell("Perodo de Prueba:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatos.addCell(getCell(periodoPrueba, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatos.setSpacingBefore(20f);
        document.add(tableDatos);
        //FIN TABLA ********************************************************************************

        //CONTENIDO ********************************************************************************
        Paragraph parphCont = new Paragraph(contenidoHoja1, font8Normal);
        parphCont.setAlignment(Element.ALIGN_JUSTIFIED);
        parphCont.setSpacingBefore(20f);

        Paragraph parphLLeida = new Paragraph("LLeida, " + fechaResultado, font8Normal);
        parphLLeida.setAlignment(Element.ALIGN_LEFT);
        parphLLeida.setSpacingBefore(20f);

        Paragraph parphTecnico = new Paragraph(responsableTecnico, font9Bold);
        parphTecnico.setAlignment(Element.ALIGN_LEFT);
        parphTecnico.setSpacingBefore(20f);

        Paragraph parphResponsable = new Paragraph("Responsable Tcnico", font8Normal);
        parphResponsable.setAlignment(Element.ALIGN_LEFT);
        parphResponsable.setSpacingBefore(1f);

        Paragraph parphLaboratorio = new Paragraph(datosLaboratorio, font8Bold);
        parphLaboratorio.setAlignment(Element.ALIGN_LEFT);
        parphLaboratorio.setSpacingBefore(30f);

        document.add(parphCont);
        document.add(parphLLeida);
        document.add(parphTecnico);
        document.add(parphResponsable);
        document.add(parphLaboratorio);
        //FIN CONTENIDO ****************************************************************************

        //FIN HOJA 1 *****************************************************************************************************************************
        document.newPage();

        //HOJA 2 *********************************************************************************************************************************                        
        //IMAGE **********************************************************************************
        String relativeWebPathAg1 = "/images/agrorum.png";
        String absoluteDiskPathAg1 = getServletContext().getRealPath(relativeWebPathAg1);
        Image logoAg1 = Image.getInstance(absoluteDiskPathAg1);
        logoAg1.setAbsolutePosition(10f, 750f);
        logoAg1.scalePercent(80f);
        document.add(logoAg1);

        String relativeWebPathEu1 = "/images/eurofins.png";
        String absoluteDiskPathEu1 = getServletContext().getRealPath(relativeWebPathEu1);
        Image logoEu1 = Image.getInstance(absoluteDiskPathEu1);
        logoEu1.setAbsolutePosition(500f, 770f);
        logoEu1.scalePercent(60f);
        document.add(logoEu1);

        Paragraph ini = new Paragraph("", font12Bold);
        ini.setAlignment(Element.ALIGN_CENTER);
        ini.setSpacingBefore(100f);

        PdfPTable cabT = new PdfPTable(new float[] { 1f });
        cabT.setWidthPercentage(100);
        PdfPCell cellCab = new PdfPCell(new Phrase("Informe de Prueba", font12Bold));
        cellCab.setPadding(2f);
        cellCab.setHorizontalAlignment(Element.ALIGN_CENTER);
        cabT.addCell(cellCab);

        Paragraph parphRep = new Paragraph("Reporte de anlisis 2/2", font10Normal);
        parphRep.setAlignment(Element.ALIGN_RIGHT);

        document.add(ini);
        document.add(cabT);
        document.add(parphRep);

        //TABLA ***********************************************************************************
        PdfPTable tableDatosH2 = new PdfPTable(new float[] { 0.20f, 0.80f });
        tableDatosH2.setWidthPercentage(100);

        tableDatosH2.addCell(getCell("Cliente:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(cliente, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell(" ", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(" ", PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Propiedad:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(hacienda, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Estacin Monitoreo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(estacionMonitoreo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Nmero Monitoreo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(numeroMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Codigo Muestra:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(codigMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Matriz:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(tipoMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Cultivo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(cultivo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Variedad:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(varie, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Fecha Muestreo:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(fechaMuestreo, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Recepcin Muestra:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(fechaRecepcionMuestra, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.addCell(getCell("Perodo de Prueba:", PdfPCell.ALIGN_LEFT, font8Normal));
        tableDatosH2.addCell(getCell(periodoPrueba, PdfPCell.ALIGN_LEFT, font8Bold));

        tableDatosH2.setSpacingBefore(20f);
        document.add(tableDatosH2);
        //FIN TABLA ********************************************************************************

        Paragraph parphCont1 = new Paragraph(contenidoHoja2, font8Normal);
        parphCont1.setAlignment(Element.ALIGN_JUSTIFIED);
        parphCont1.setSpacingBefore(20f);

        PdfPTable tableDatosH3 = new PdfPTable(new float[] { 0.30f, 0.70f });
        tableDatosH3.setWidthPercentage(100);

        tableDatosH3.addCell(getCell(datosLaboratorio, PdfPCell.ALIGN_LEFT, font8Bold));

        PdfPTable subTable = new PdfPTable(new float[] { 1f });
        subTable.setWidthPercentage(100);

        subTable.addCell(getCell("LLeida, " + fechaResultado, PdfPCell.ALIGN_CENTER, font8Normal));
        subTable.addCell(getCell(" ", PdfPCell.ALIGN_CENTER, font8Normal));
        subTable.addCell(getCell(" ", PdfPCell.ALIGN_CENTER, font8Normal));
        subTable.addCell(getCell(" ", PdfPCell.ALIGN_CENTER, font8Normal));

        subTable.addCell(getCell(responsableTecnico, PdfPCell.ALIGN_CENTER, font9Bold));
        subTable.addCell(getCell("Responsable Tcnico", PdfPCell.ALIGN_CENTER, font8Normal));

        PdfPCell cellsub = new PdfPCell(subTable);
        cellsub.setBorder(PdfPCell.NO_BORDER);
        cellsub.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        tableDatosH3.addCell(cellsub);

        tableDatosH3.setSpacingBefore(20f);

        document.add(parphCont1);
        document.add(tableDatosH3);

        //FIN IMAGE ********************************************************************************            
        //FIN HOJA 2 *****************************************************************************************************************************
        document.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }
}

From source file:servlet.PdfGenerator.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  w  ww  .  j a  v a2  s . c om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Document report = new Document();
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(report, baos);

        DBManager manager = (DBManager) getServletContext().getAttribute("dbmanager");
        Group groupToReport = manager.getGroup(Integer.parseInt(request.getParameter("id")));
        LinkedList<User> groupUsers = manager.getUsersForGroupAndVisible(groupToReport.getId());
        Timestamp lastPosted = manager.getLatestPost(groupToReport);
        int numberOfPosts = manager.getGroupPosts(groupToReport).size();
        String context = request.getServletContext().getRealPath("/");
        Iterator<User> groupIterator = groupUsers.iterator();

        report.open();
        // INSERTING DOCUMENT CONTENT AREA
        Font title = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 24);
        Font text = FontFactory.getFont(FontFactory.HELVETICA, 12);
        Paragraph documentHead = new Paragraph(groupToReport.getName(), title);
        Paragraph newLine = new Paragraph(Chunk.NEWLINE);
        Paragraph latestPost = new Paragraph("Latest post inserted on: " + lastPosted, text);
        Paragraph postsNumberToReport = new Paragraph("Number of posts: " + numberOfPosts, text);

        //LAYOUT AND FINAL PARAGRAPH EDITING AREA
        report.add(documentHead);
        report.add(newLine);
        report.add(postsNumberToReport);
        report.add(newLine);
        report.add(latestPost);
        report.add(newLine);
        PdfPTable usersTable = new PdfPTable(5);

        // LOOP FOR SETTING TABLE
        while (groupIterator.hasNext()) {
            User u = groupIterator.next();
            String userName = u.getName();
            PdfPCell avatarCell = new PdfPCell(Image.getInstance(context + u.getAvatar(request)));
            avatarCell.setBorder(0);
            avatarCell.setPaddingBottom(10);
            avatarCell.setColspan(1);
            PdfPCell userNameCell = new PdfPCell(new Phrase(userName));
            userNameCell.setColspan(4);
            userNameCell.setBorder(0);
            userNameCell.setPaddingBottom(10);
            userNameCell.setPaddingLeft(10);
            usersTable.addCell(avatarCell);
            usersTable.addCell(userNameCell);
        }
        usersTable.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
        report.add(usersTable);

        report.close();

        // SETTING SOME RESPONSE HEADER
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");
        // SETTING THE CONTENT TYPE
        response.setContentType("application/pdf");
        // THE CONTENTLENGHT
        response.setContentLength(baos.size());
        System.out.println("ci sono");
        try (OutputStream os = response.getOutputStream()) {
            baos.writeTo(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:simz1.ManagerHomeScreen.java

private void btnGenerateReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateReportActionPerformed
    int reply = JOptionPane.showConfirmDialog(null, "Do you wish to fianlize Accounts Report now?", "",
            JOptionPane.YES_NO_OPTION);
    if (reply == JOptionPane.YES_OPTION) {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {/* w  ww  .  j  av a 2s .c om*/
            String date = today.replace(":", "_");
            //New PDF File will be created as ACCReport2016_01_01 //today's date
            PdfWriter.getInstance(document,
                    new FileOutputStream("C:\\#SIMZ\\Account Reports\\ACCReport" + date + "" + ".pdf"));
            document.open();
            Image image2 = Image.getInstance("C:\\#SIMZ\\logo1.jpg");
            document.add(image2);
            Paragraph paragraph1 = new Paragraph(
                    "Perera and Sons Bakers(pvt)Ltd.\nAddress: 1/52, Galle Road,Colombo 03.\nT.P:0112552225\n\n");
            document.add(paragraph1);
            paragraph1 = new Paragraph("                Finalized Accounts Report - " + today + "",
                    FontFactory.getFont(FontFactory.HELVETICA, 18));
            document.add(paragraph1);
            //adding a table
            PdfPTable t = new PdfPTable(3);
            t.setSpacingBefore(25);
            t.setSpacingAfter(25);

            t.addCell(new PdfPCell(new Phrase("Description")));
            t.addCell(new PdfPCell(new Phrase("Credit(Rs.)")));
            t.addCell(new PdfPCell(new Phrase("Debit(Rs.)")));
            int rows = tblIncome.getRowCount();

            for (int i = 0; i < rows; i++) {
                t.addCell(new PdfPCell(new Phrase(tblIncome.getValueAt(i, 0) + "")));
                if (tblIncome.getValueAt(i, 1) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblIncome.getValueAt(i, 1) + "")));
                }
                if (tblIncome.getValueAt(i, 2) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblIncome.getValueAt(i, 2) + "")));
                }
            }
            document.add(t);
            float totalIncome = 0;
            for (int i = 0; i < rows; i++) {
                if (tblIncome.getValueAt(i, 1) != null) {
                    totalIncome = totalIncome + Float.parseFloat(tblIncome.getValueAt(i, 1).toString());
                } else {
                    totalIncome = totalIncome + 0;
                }
            }
            paragraph1 = new Paragraph("Total Income (Rs.) : " + totalIncome + "");
            document.add(paragraph1);
            float totalExpences = 0;
            for (int i = 0; i < rows; i++) {
                if (tblIncome.getValueAt(i, 2) != null) {
                    totalExpences = totalExpences + Float.parseFloat(tblIncome.getValueAt(i, 2).toString());
                } else {
                    totalExpences = totalExpences + 0;
                }
            }
            DecimalFormat roundValue = new DecimalFormat("###.##");
            float expense = Float.parseFloat(roundValue.format(totalExpences));
            paragraph1 = new Paragraph("Total Expence (Rs.) : " + expense + "");
            document.add(paragraph1);
            float profit = 0;
            profit = totalIncome - expense;
            totProfit = profit;
            trigger1 = 1;
            paragraph1 = new Paragraph("Total Profit (Rs.) : " + profit + "" + "\n\n");
            document.add(paragraph1);
            String name = dbOps.getName(name1.getText());
            paragraph1 = new Paragraph("Report Generated By : " + name);
            document.add(paragraph1);
            //view report
            int reply1 = JOptionPane.showConfirmDialog(null,
                    "Finalized Accounts Report named ACCReportToday'sDate successfully generated.\nDo you want to view the report?",
                    "", JOptionPane.YES_NO_OPTION);
            if (reply1 == JOptionPane.YES_OPTION) {
                if ((new File("C:\\#SIMZ\\Account Reports\\ACCReport" + date + "" + ".pdf")).exists()) {

                    Process p = Runtime.getRuntime()
                            .exec("rundll32 url.dll,FileProtocolHandler C:\\#SIMZ\\Account Reports\\ACCReport"
                                    + date + "" + ".pdf");
                    p.waitFor();
                }
            }
        } catch (Exception ex) {
            System.out.println(ex);
            JOptionPane.showMessageDialog(this, "File already exists!!!");
        }
        document.close();
    }
}

From source file:simz1.ManagerHomeScreen.java

private void btnFinalReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFinalReportActionPerformed
    int reply = JOptionPane.showConfirmDialog(null, "Do you wish to fianlize Products Report now?", "",
            JOptionPane.YES_NO_OPTION);
    if (reply == JOptionPane.YES_OPTION) {
        Document document = new Document(PageSize.A4);
        try {// www  . j a  va  2 s  .  c om
            String date = today.replace(":", "_");
            //New PDF File will be created as ProReport2016_01_01 //today's date
            PdfWriter.getInstance(document,
                    new FileOutputStream("C:\\#SIMZ\\Product Reports\\ProReport" + date + "" + ".pdf"));
            document.open();
            Image image2 = Image.getInstance("C:\\#SIMZ\\logo1.jpg");
            document.add(image2);
            Paragraph paragraph1 = new Paragraph(
                    "Perera and Sons Bakers(pvt)Ltd.\nAddress: 1/52, Galle Road,Colombo 03.\nT.P:0112552225\n\n");
            document.add(paragraph1);
            //Following blank space is for the alignment of the topic
            paragraph1 = new Paragraph("                Finalized Products Report - " + today + "",
                    FontFactory.getFont(FontFactory.HELVETICA, 18));
            document.add(paragraph1);
            //adding a table
            PdfPTable t = new PdfPTable(3);
            t.setSpacingBefore(25);
            t.setSpacingAfter(25);
            t.addCell(new PdfPCell(new Phrase("Product Name")));
            t.addCell(new PdfPCell(new Phrase("Received Quantity")));
            t.addCell(new PdfPCell(new Phrase("Remained Quantity")));
            int rows = tblReports.getRowCount();
            for (int i = 0; i < rows; i++) {
                t.addCell(new PdfPCell(new Phrase(tblReports.getValueAt(i, 0) + "")));
                if (tblReports.getValueAt(i, 1) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblReports.getValueAt(i, 1) + "")));
                }
                if (tblReports.getValueAt(i, 2) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblReports.getValueAt(i, 2) + "")));
                }
            }
            document.add(t);
            paragraph1 = new Paragraph("Expired Item Details");
            document.add(paragraph1);
            PdfPTable t2 = new PdfPTable(2);
            t2.setSpacingBefore(25);
            t2.setSpacingAfter(25);
            t2.addCell(new PdfPCell(new Phrase("Product Name")));
            t2.addCell(new PdfPCell(new Phrase("Remained Quantity")));
            String dateToday = today.replace(":", "-");
            ResultSet rs = dbOps.getExpiredItemList(dateToday);
            while (rs.next()) {
                t2.addCell(new PdfPCell(new Phrase(rs.getString(1))));
                t2.addCell(new PdfPCell(new Phrase(rs.getString(3))));
            }
            document.add(t2);
            String user = dbOps.getName(name1.getText());
            paragraph1 = new Paragraph("Report Generated By : " + user);
            document.add(paragraph1);
            //view report
            int reply1 = JOptionPane.showConfirmDialog(null,
                    "Finalized Products Report named ProReportToday'sDate successfully generated.\nDo you want to view the report?",
                    "", JOptionPane.YES_NO_OPTION);
            trigger2 = 1;
            if (reply1 == JOptionPane.YES_OPTION) {
                if ((new File("C:\\#SIMZ\\Product Reports\\ProReport" + date + "" + ".pdf")).exists()) {

                    Process p = Runtime.getRuntime()
                            .exec("rundll32 url.dll,FileProtocolHandler C:\\#SIMZ\\Product Reports\\ProReport"
                                    + date + "" + ".pdf");
                    p.waitFor();
                }
            }

        } catch (SQLException | HeadlessException | IOException | InterruptedException | DocumentException ex) {
            System.out.println(ex);
            JOptionPane.showMessageDialog(this, "File already exists!!!");
        }
        document.close();
    }
}

From source file:storybook.export.ExportPDF.java

public void open() {
    SbApp.trace("ExportPDF.open()");
    outDoc = new Document();
    Rectangle rectangle = new Rectangle(PageSize.getRectangle(parent.parent.paramExport.pdfPageSize));
    if (parent.parent.paramExport.pdfLandscape) {
        rectangle = new Rectangle(PageSize.getRectangle(parent.parent.paramExport.pdfPageSize).rotate());
    }//  w ww . ja va  2s  .  com
    outDoc.setPageSize(rectangle);
    try {
        writer = PdfWriter.getInstance(outDoc, new FileOutputStream(fileName));
    } catch (FileNotFoundException | DocumentException ex) {
        SbApp.error(ExportPDF.class.getName(), ex);
    }
    outDoc.open();

    addMetaData();
    try {
        outDoc.add(new Phrase(parent.bookTitle + " - " + parent.exportData.getKey() + "\n",
                FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD)));
    } catch (DocumentException ex) {
        SbApp.error("ExportPDF.open()", ex);
    }
    if (headers == null)
        return;
    float hsize[] = new float[headers.size()];
    int i = 0;
    for (ExportHeader header : headers) {
        hsize[i] = header.getSize();
        i++;
    }

    table = new PdfPTable(hsize);

    for (ExportHeader header : headers) {
        table.addCell(new Phrase(header.getName(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
    }
}