Example usage for com.itextpdf.text.pdf BaseFont EMBEDDED

List of usage examples for com.itextpdf.text.pdf BaseFont EMBEDDED

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf BaseFont EMBEDDED.

Prototype

boolean EMBEDDED

To view the source code for com.itextpdf.text.pdf BaseFont EMBEDDED.

Click Source Link

Document

if the font has to be embedded

Usage

From source file:com.thelinh.gui.PreviewExam.java

/**
 * Creates new form PreviewExam//  ww  w .j a va2  s. c om
 */
public PreviewExam(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    this.superParent = null;
    try {
        timesBold_25 = new Font(
                BaseFont.createFont("resources/fonts/vuTimesBold.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED),
                25);
        timesBold_15 = new Font(
                BaseFont.createFont("resources/fonts/vuTimesBold.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED),
                15);
        times_15 = new Font(
                BaseFont.createFont("resources/fonts/vuTimes.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 15);
        times_13 = new Font(
                BaseFont.createFont("resources/fonts/vuTimes.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 13);
    } catch (DocumentException | IOException ex) {
        Logger.getLogger(PreviewExam.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.thelinh.gui.Statistics.java

private void btnExportReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportReportActionPerformed
    Document document = new Document() {
    };//  w  w w .  j ava  2s  .c  o m
    try {
        JFileChooser jfc = new JFileChooser("Save File");
        if (jfc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
            //  String content = this.txtReport.getText();
            jfc.setDialogTitle("Save File");
            FileOutputStream fos = new FileOutputStream(jfc.getSelectedFile());
            PdfWriter.getInstance(document, fos);
            //                Font rfont = FontFactory.getFont("resources/fonts/vuArial.ttf", IDENTITY_H, true);
            Font rfont = new Font(BaseFont.createFont("resources/fonts/vuTimesBold.ttf", BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED));
            document.open();
            document.add(new Paragraph(
                    "                                                    TRNG ?I HC B?CH KHOA H NI",
                    rfont));

            if (k == 1) {
                document.add(new Paragraph(
                        "\t\t                                                                   TH?NG K MN HC\n",
                        rfont));
                String sqlSubject1 = "SELECT Count(SubjectId) AS subjectAll FROM Subjects";
                String sqlSubject2 = "SELECT Subjects.SubjectName AS subjectChap, Count(*) AS subjectNumber FROM Chaps,Subjects WHERE Chaps.SubjectId = Subjects.SubjectId GROUP BY Subjects.SubjectName";
                ResultSet rs1 = LoadTable.Display(sqlSubject1);
                ResultSet rs2 = LoadTable.Display(sqlSubject2);
                try {
                    if (rs1.next()) {
                        document.add(new Paragraph(
                                "Tng s mn h?c l " + rs1.getInt("subjectAll") + "\n", rfont));
                    }
                    document.add(new Paragraph("Thng k s chng ca mn h?c: \n\n", rfont));
                    PdfPTable table = new PdfPTable(2);
                    PdfPCell header1 = new PdfPCell(new Paragraph("Mn h?c", rfont));
                    PdfPCell header2 = new PdfPCell(new Paragraph("S chng", rfont));
                    table.addCell(header1);
                    table.addCell(header2);
                    while (rs2.next()) {
                        PdfPCell header3 = new PdfPCell(new Paragraph(rs2.getString("subjectChap"), rfont));
                        table.addCell(header3);
                        PdfPCell header4 = new PdfPCell(new Paragraph("" + rs2.getInt("subjectNumber")));
                        table.addCell(header4);
                    }
                    document.add(table);
                } catch (SQLException ex) {
                    Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else if (k == 2) {
                try {
                    document.add(new Paragraph(
                            "\t\t                                                                 TH?NG K CU HI\n",
                            rfont));
                    String sqlQuestion1 = "SELECT Count(QuestionId) AS questionAll FROM Questions";
                    String sqlQuestion2 = "SELECT SubjectName AS subjectName, Count(QuestionId) AS questionSubject FROM Questions,Subjects WHERE Subjects.SubjectId = Questions.SubjectId GROUP BY Subjects.SubjectName";
                    ResultSet rs1 = LoadTable.Display(sqlQuestion1);
                    ResultSet rs2 = LoadTable.Display(sqlQuestion2);
                    if (rs1.next()) {
                        document.add(new Paragraph(
                                "Tng s cu h?i l " + rs1.getInt("questionAll") + "\n", rfont));
                    }
                    document.add(new Paragraph("Thng k s cu h?i ca mn h?c: \n\n", rfont));
                    PdfPTable table = new PdfPTable(2);
                    PdfPCell header1 = new PdfPCell(new Paragraph("Mn h?c", rfont));
                    PdfPCell header2 = new PdfPCell(new Paragraph("S cu h?i", rfont));
                    table.addCell(header1);
                    table.addCell(header2);
                    while (rs2.next()) {
                        PdfPCell header3 = new PdfPCell(new Paragraph(rs2.getString("subjectName"), rfont));
                        table.addCell(header3);
                        PdfPCell header4 = new PdfPCell(new Paragraph("" + rs2.getInt("questionSubject")));
                        table.addCell(header4);
                    }
                    document.add(table);
                } catch (SQLException ex) {
                    Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else if (k == 3) {
                try {
                    document.add(new Paragraph(
                            "\t\t                                                                  TH?NG K NGI DNG\n",
                            rfont));
                    String sqlUser1 = "SELECT Count(UserId) AS userAll FROM Users";
                    String sqlUser2 = "SELECT Class AS className, Count(UserId) AS userClass FROM Users GROUP BY Class";
                    ResultSet rs1 = LoadTable.Display(sqlUser1);
                    ResultSet rs2 = LoadTable.Display(sqlUser2);
                    if (rs1.next()) {
                        document.add(new Paragraph(
                                "Tng s ng?i dng l " + rs1.getInt("userAll") + "\n", rfont));
                    }
                    document.add(new Paragraph("Thng k s h?c sinh ca lp: \n\n", rfont));
                    PdfPTable table = new PdfPTable(2);
                    PdfPCell header1 = new PdfPCell(new Paragraph("Lp", rfont));
                    PdfPCell header2 = new PdfPCell(new Paragraph("S h?c sinh", rfont));
                    table.addCell(header1);
                    table.addCell(header2);
                    while (rs2.next()) {
                        PdfPCell header3 = new PdfPCell(new Paragraph(rs2.getString("className"), rfont));
                        table.addCell(header3);
                        PdfPCell header4 = new PdfPCell(new Paragraph("" + rs2.getInt("userClass")));
                        table.addCell(header4);
                    }
                    document.add(table);
                } catch (SQLException ex) {
                    Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else if (k == 4) {
                document.add(new Paragraph(
                        "\t\t                                                                        TH?NG K KT QU\n",
                        rfont));
                String sqlResult1 = "SELECT Count(*) AS resultAll FROM Results";
                String sqlResult2 = "SELECT Count(*) AS exam1 FROM Results WHERE Result <= 4";
                String sqlResult3 = "SELECT Count(*) AS exam2 FROM Results WHERE Result > 4 AND Result < 6";
                String sqlResult4 = "SELECT Count(*) AS exam3 FROM Results WHERE Result >= 6 AND Result < 8";
                String sqlResult5 = "SELECT Count(*) AS exam4 FROM Results WHERE Result >= 8";
                ResultSet rs1 = LoadTable.Display(sqlResult1);
                ResultSet rs2 = LoadTable.Display(sqlResult2);
                ResultSet rs3 = LoadTable.Display(sqlResult3);
                ResultSet rs4 = LoadTable.Display(sqlResult4);
                ResultSet rs5 = LoadTable.Display(sqlResult5);
                if (rs1.next()) {
                    document.add(
                            new Paragraph("Tng s bi thi l " + rs1.getInt("resultAll") + "\n", rfont));
                }
                document.add(new Paragraph("Thng k im thi: \n\n", rfont));
                PdfPTable table = new PdfPTable(2);
                PdfPCell header1 = new PdfPCell(new Paragraph("?im", rfont));
                PdfPCell header2 = new PdfPCell(new Paragraph("S bi thi", rfont));
                table.addCell(header1);
                table.addCell(header2);
                PdfPCell header3 = new PdfPCell(new Paragraph("<= 4"));
                table.addCell(header3);
                if (rs2.next()) {
                    PdfPCell header4 = new PdfPCell(new Paragraph(rs2.getInt("exam1")));
                    table.addCell(header4);
                }
                PdfPCell header5 = new PdfPCell(new Paragraph("> 4 v < 6"));
                table.addCell(header5);
                if (rs3.next()) {
                    PdfPCell header6 = new PdfPCell(new Paragraph(rs3.getInt("exam2")));
                    table.addCell(header6);
                }
                PdfPCell header7 = new PdfPCell(new Paragraph(">= 6 v < 8"));
                table.addCell(header7);
                if (rs4.next()) {
                    PdfPCell header8 = new PdfPCell(new Paragraph(rs4.getInt("exam3")));
                    table.addCell(header8);
                }
                PdfPCell header9 = new PdfPCell(new Paragraph(">= 8"));
                table.addCell(header9);
                if (rs5.next()) {
                    PdfPCell header10 = new PdfPCell(new Paragraph(rs5.getInt("exam4")));
                    table.addCell(header10);
                }
                document.add(table);
            }
            document.add(new Paragraph(
                    "                                                                                                  H Ni, ngy 09 thng 12 nm 2016\n",
                    rfont));
            document.add(new Paragraph(
                    "                                                                                                               Gio Vin\n",
                    rfont));
            document.add(new Paragraph(
                    "                                                                                                          "
                            + Controller.getCurrentAdmin().getAdminName() + "\n",
                    rfont));
            document.close();
            JOptionPane.showMessageDialog(null, "Save success");
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.tomasz.drag.triballocommanderro.controller.MakerPDF.java

public static void printToPDFBoss(ArrayList<Person> workers, EventGig event)
        throws IOException, DocumentException {
    String filename = event.getName() + " Boss" + ".pdf";
    String path = event.getData() + " " + event.getName() + "//";
    //Rectangle rect = new Rectangle(0, 595, 8, 0);
    Document document = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
    //Document document = new Document(rect);
    //document.setMargins(0, 0, 0, 0);
    BaseFont bf;//from  www. j  a  v  a 2s .  c o m
    //BaseFont bf2;
    // bf = BaseFont.createFont("arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    bf = BaseFont.createFont("src\\main\\resources\\font\\arialuni.ttf", BaseFont.IDENTITY_H,
            BaseFont.EMBEDDED);
    //bf2 = BaseFont.createFont("src\\main\\resources\\font\\arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    com.itextpdf.text.Font ft = new com.itextpdf.text.Font(bf, 9);
    //com.itextpdf.text.Font ft2 = new com.itextpdf.text.Font(bf2,9);

    PdfWriter.getInstance(document, new FileOutputStream(path + filename));

    document.open();
    Paragraph p = new Paragraph(event.getName() + " " + event.getData(), ft);
    p.setAlignment(Element.ALIGN_CENTER);
    document.add(p);
    document.add(new Paragraph(" "));
    PdfPTable table = new PdfPTable(workers.size() + 1);
    table.setWidthPercentage(98);
    PdfPCell cell = new PdfPCell(new Phrase("    "));
    table.addCell(cell);
    for (Person tempPerson : workers) {
        cell = new PdfPCell(new Paragraph(tempPerson.getName(), ft));
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);

    }
    if (event.isZaladunekScenaDach()) {
        cell = new PdfPCell(new Paragraph("Za. Sc./Dach", ft));
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getZaladunekScenaDachWyplata() > 0) {
                cell = new PdfPCell(
                        new Paragraph(String.format("%.2f", tempPerson.getZaladunekScenaDachWyplata()), ft));
                cell.setVerticalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }
    if (event.isZaladunekTechniki()) {
        cell = new PdfPCell(new Phrase("Za. Tech.", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getZaladunekTechnikiWyplata() > 0) {
                cell = new PdfPCell(
                        new Paragraph(String.format("%.2f", tempPerson.getZaladunekTechnikiWyplata()), ft));
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isRozladunekScenaDach()) {
        cell = new PdfPCell(new Phrase("Roz Sc/Dach", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getRozladunekScenaDachWyplata() > 0) {
                cell = new PdfPCell(
                        new Phrase(String.format("%.2f", tempPerson.getRozladunekScenaDachWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }
    if (event.isRozladunekTechniki()) {
        cell = new PdfPCell(new Phrase("Roz. Tech.", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getRozladunekTechnikiWyplata() > 0) {
                cell = new PdfPCell(
                        new Phrase(String.format("%.2f", tempPerson.getRozladunekTechnikiWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isMontazDachu()) {
        cell = new PdfPCell(new Phrase("Mon. Dach", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getMontazDachuWyplata() > 0) {
                cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getMontazDachuWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isMontazDzwieku()) {
        cell = new PdfPCell(new Phrase("Mon. Dw.", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getMontazDzwiekuWyplata() > 0) {
                cell = new PdfPCell(
                        new Phrase(String.format("%.2f", tempPerson.getMontazDzwiekuWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isMontazSceny()) {
        cell = new PdfPCell(new Phrase("Mon. Sc.", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getMontazScenyWyplata() > 0) {
                cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getMontazScenyWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isMontazSwiatla()) {
        cell = new PdfPCell(new Phrase("Mon. w.", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getMontazSwiatlaWyplata() > 0) {
                cell = new PdfPCell(
                        new Phrase(String.format("%.2f", tempPerson.getMontazSwiatlaWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isMontazTechniki()) {
        cell = new PdfPCell(new Phrase("Mon. Tech.", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getMontazTechnikiWyplata() > 0) {
                cell = new PdfPCell(
                        new Phrase(String.format("%.2f", tempPerson.getMontazTechnikiWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isDemontazDachu()) {
        cell = new PdfPCell(new Phrase("Dem. Dach", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getDemontazDachuWyplata() > 0) {
                cell = new PdfPCell(
                        new Phrase(String.format("%.2f", tempPerson.getDemontazDachuWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isDemontazDzwieku()) {
        cell = new PdfPCell(new Phrase("Dem. Dw.", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getDemontazDzwiekuWyplata() > 0) {
                cell = new PdfPCell(
                        new Phrase(String.format("%.2f", tempPerson.getDemontazDzwiekuWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isDemontazSceny()) {
        cell = new PdfPCell(new Phrase("Dem. Sc.", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getDemontazScenyWyplata() > 0) {
                cell = new PdfPCell(
                        new Phrase(String.format("%.2f", tempPerson.getDemontazScenyWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isDemontazSwiatla()) {
        cell = new PdfPCell(new Phrase("Dem. w.", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getDemontazSwiatlaWyplata() > 0) {
                cell = new PdfPCell(
                        new Phrase(String.format("%.2f", tempPerson.getDemontazSwiatlaWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase("   "));
                table.addCell(cell);
            }
        }
    }

    if (event.isDemontazTechniki()) {
        cell = new PdfPCell(new Phrase("Dem. Tech.", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getDemontazTechnikiWyplata() > 0) {
                cell = new PdfPCell(
                        new Phrase(String.format("%.2f", tempPerson.getDemontazTechnikiWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isDyzur()) {
        cell = new PdfPCell(new Phrase("Dyur", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getDyzurWyplata() > 0) {
                cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getDyzurWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(""));
                table.addCell(cell);
            }
        }
    }

    if (event.isTechnikSceny()) {
        cell = new PdfPCell(new Phrase("Technik Sc.", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getTechnikScenyWyplata() > 0) {
                cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getTechnikScenyWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isRealizacjaFOH()) {
        cell = new PdfPCell(new Phrase("Real. FOH", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getRealizacjaFOHWyplata() > 0) {
                cell = new PdfPCell(
                        new Phrase(String.format("%.2f", tempPerson.getRealizacjaFOHWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isRealizacjaMON()) {
        cell = new PdfPCell(new Phrase("Real. MON", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getRealizacjaMONWyplata() > 0) {
                cell = new PdfPCell(
                        new Phrase(String.format("%.2f", tempPerson.getRealizacjaMONWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (event.isRealizacjaSwiatla()) {
        cell = new PdfPCell(new Phrase("Real. w.", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getRealizacjaSwiatlaWyplata() > 0) {
                cell = new PdfPCell(
                        new Phrase(String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    if (true) {
        cell = new PdfPCell(new Phrase("Premia", ft));
        table.addCell(cell);
        for (Person tempPerson : workers) {
            if (tempPerson.getPremia() > 0) {
                cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getPremia()), ft));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(" "));
                table.addCell(cell);
            }
        }
    }

    Paragraph ph = new Paragraph("Razem", ft);

    //cell = new PdfPCell(new Phrase(ph));
    cell.addElement(ph);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    for (Person tempPerson : workers) {
        if (tempPerson.getSumaWyplata() >= 0) {
            cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getSumaWyplata()) + " z", ft));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        } else {
            cell = new PdfPCell(new Phrase(" "));
            table.addCell(cell);
        }
    }
    //        for (Object obj : table.getChunks()) {
    //            if (obj instanceof PdfPCell) {
    //                System.out.println("jest PdfCell");
    //                PdfPCell tempCell = (PdfPCell) obj;
    //                tempCell.setVerticalAlignment(Element.ALIGN_CENTER);
    //                //tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    //            }
    //            
    //        }
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    document.add(table);
    document.close();

}

From source file:com.tomasz.drag.triballocommanderro.controller.MakerPDF.java

public static PdfPTable createTable(Person person, EventGig event) throws DocumentException, IOException {
    int a = 0;/*  w w  w.  j  ava 2  s.  com*/
    if (person.getZaladunekScenaDachWyplata() > 0) {
        a++;
    }
    if (person.getZaladunekTechnikiWyplata() > 0) {
        a++;
    }

    if (person.getMontazDachuWyplata() > 0) {
        a++;
    }
    if (person.getMontazDzwiekuWyplata() > 0) {
        a++;
    }

    if (person.getMontazScenyWyplata() > 0) {
        a++;
    }
    if (person.getMontazSwiatlaWyplata() > 0) {
        a++;
    }

    if (person.getMontazTechnikiWyplata() > 0) {
        a++;
    }

    if (person.getDemontazDachuWyplata() > 0) {
        a++;
    }
    if (person.getDemontazDzwiekuWyplata() > 0) {
        a++;
    }

    if (person.getDemontazScenyWyplata() > 0) {
        a++;
    }
    if (person.getDemontazSwiatlaWyplata() > 0) {
        a++;
    }

    if (person.getDemontazTechnikiWyplata() > 0) {
        a++;
    }

    if (person.getRozladunekScenaDachWyplata() > 0) {
        a++;
    }
    if (person.getRozladunekTechnikiWyplata() > 0) {
        a++;
    }
    if (person.getDyzurWyplata() > 0) {
        a++;
    }
    if (person.getTechnikScenyWyplata() > 0) {
        a++;
    }
    if (person.getRealizacjaFOHWyplata() > 0) {
        a++;
    }
    if (person.getRealizacjaMONWyplata() > 0) {
        a++;
    }
    if (person.getRealizacjaSwiatlaWyplata() > 0) {
        a++;
    }

    if (person.getPremia() > 0) {
        a++;
    }

    System.out.println(a);
    BaseFont bf;
    bf = BaseFont.createFont("src\\main\\resources\\font\\arialuni.ttf", BaseFont.IDENTITY_H,
            BaseFont.EMBEDDED);
    // bf = BaseFont.createFont("arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    com.itextpdf.text.Font ft = new com.itextpdf.text.Font(bf);
    PdfPTable table = new PdfPTable(2);
    table.setTotalWidth(new float[] { 90, 190 });
    table.setLockedWidth(true);
    PdfPCell cell;
    cell = new PdfPCell(new Phrase(person.getName() + " " + person.getSurName(), ft));
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase(event.getName() + " " + event.getData(), ft));
    cell.setColspan(2);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase(""));

    cell.setRowspan(a);

    table.addCell(cell);

    if (person.getZaladunekScenaDachWyplata() > 0) {
        table.addCell(new Phrase("Zaadunek Scena/Dach", ft));

    }
    if (person.getZaladunekTechnikiWyplata() > 0) {
        table.addCell(new Phrase("Zaadunek Techniki", ft));
    }

    if (person.getMontazDachuWyplata() > 0) {
        table.addCell(new Phrase("Monta Dachu", ft));

    }
    if (person.getMontazDzwiekuWyplata() > 0) {
        table.addCell(new Phrase("Monta Dwieku", ft));
    }

    if (person.getMontazScenyWyplata() > 0) {
        table.addCell(new Phrase("Monta Sceny", ft));

    }
    if (person.getMontazSwiatlaWyplata() > 0) {
        table.addCell(new Phrase("Monta wiata", ft));
    }

    if (person.getMontazTechnikiWyplata() > 0) {
        table.addCell(new Phrase("Monta Techniki", ft));
    }

    if (person.getDemontazDachuWyplata() > 0) {
        table.addCell(new Phrase("Demonta Dachu", ft));

    }
    if (person.getDemontazDzwiekuWyplata() > 0) {
        table.addCell(new Phrase("Demonta Dwieku", ft));
    }

    if (person.getDemontazScenyWyplata() > 0) {
        table.addCell(new Phrase("Demonta Sceny", ft));

    }
    if (person.getDemontazSwiatlaWyplata() > 0) {
        table.addCell(new Phrase("Demonta wiata", ft));
    }

    if (person.getDemontazTechnikiWyplata() > 0) {
        table.addCell(new Phrase("Demonta Techniki", ft));
    }

    if (person.getRozladunekScenaDachWyplata() > 0) {
        table.addCell(new Phrase("Rozadunek Scena/Dach", ft));

    }
    if (person.getRozladunekTechnikiWyplata() > 0) {
        table.addCell(new Phrase("Rozadunek Techniki", ft));
    }

    if (person.getDyzurWyplata() > 0) {
        table.addCell(new Phrase("Dyur", ft));
    }

    if (person.getTechnikScenyWyplata() > 0) {
        table.addCell(new Phrase("Technik Sceny", ft));
    }

    if (person.getRealizacjaFOHWyplata() > 0) {
        table.addCell(new Phrase("Realizacja FOH", ft));
    }

    if (person.getRealizacjaMONWyplata() > 0) {
        table.addCell(new Phrase("Realizacja MON", ft));
    }

    if (person.getRealizacjaSwiatlaWyplata() > 0) {
        table.addCell(new Phrase("Realizacja wiata", ft));
    }

    if (person.getPremia() > 0) {
        table.addCell(new Phrase("Premia", ft));
    }

    cell = new PdfPCell(new Phrase("Suma: "));
    cell.setColspan(1);
    table.addCell(cell);
    //cell = new PdfPCell(new Phrase(Double.toString(person.getSumaWyplata())));//String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata())
    cell = new PdfPCell(new Phrase(String.format("%.2f", person.getSumaWyplata()) + " z", ft));//String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata())
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);
    //cell = new PdfPCell(new Phrase(Double.toString(person.getSumaWyplata())));//String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata())
    cell = new PdfPCell(new Phrase("  "));//String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata())
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);
    table.setBreakPoints(2 + a);

    return table;

}

From source file:com.VanLesh.macsv10.macs.Models.Pdf.java

License:GNU General Public License

private static void addContent(Document doc, Calculation calc) {
    try {//from w  w w . j  a  v a  2s.  c o m
        //special font so we can render greek characters
        BaseFont bfComic = BaseFont.createFont("/system/fonts/DroidSansFallback.ttf", BaseFont.IDENTITY_H,
                BaseFont.EMBEDDED);
        Font font1 = new Font(bfComic, 12);
        Font tgfont, tipfont;

        if (calc.getRollover() > calc.getDrag()) {
            tipfont = redFont;
            tgfont = smallBold;
        } else {
            tipfont = smallBold;
            tgfont = redFont;
        }
        Anchor anchor = new Anchor("Site", subFont);
        anchor.setName("Site Parameters");
        Paragraph identifier = new Paragraph("Calculation ID:    " + calc.getTitle(), font1);
        Paragraph engineer = new Paragraph("Engineer:    " + calc.getEngineerName(), font1);
        Paragraph jobsite = new Paragraph("Jobsite:     " + calc.getJobSite(), font1);
        Paragraph latitude = new Paragraph("Latitude:     " + calc.getLatitude(), font1);
        Paragraph longitude = new Paragraph("Longitude:     " + calc.getLongitude(), font1);

        Anchor vehicleAnchor = new Anchor("Vehicle", subFont);
        vehicleAnchor.setName("Vehicle");
        Paragraph vehicleclass = new Paragraph("Vehicle Class:     " + calc.getVehicle().getVehicleClass(),
                font1);
        Paragraph vehicletype = new Paragraph("Vehicle Type:     " + calc.getVehicle().getVehicleType(), font1);
        Paragraph vehicleweight = new Paragraph("Wv:     " + calc.getVehicle().getWv(), font1);
        Paragraph vehicletracklength = new Paragraph("Tl:     " + calc.getVehicle().getTrackL(), font1);
        Paragraph vehicletrackwidth = new Paragraph("Tw:     " + calc.getVehicle().getTrackW(), font1);
        Paragraph vehiclebladewidth = new Paragraph("Wb:     " + calc.getVehicle().getBladeW(), font1);

        Anchor soilAnchor = new Anchor("Soil", subFont);
        soilAnchor.setName("Soil");
        Paragraph soiltype = new Paragraph("Soil Type:     " + calc.getSoil().getName(), font1);
        Paragraph soilunitweight = new Paragraph("\u03B3:     " + calc.getSoil().getunitW(), font1);
        Paragraph soilfrictionangle = new Paragraph("\u03A6:     " + calc.getSoil().getfrictA(), font1);
        Paragraph soilcohesion = new Paragraph("c:     " + calc.getSoil().getC(), font1);

        Anchor measurementsAnchor = new Anchor("Measurements", subFont);
        anchor.setName("Measurements");
        Paragraph beta = new Paragraph("\u03B2:     " + calc.getBeta(), font1);
        Paragraph theta = new Paragraph("\u03B8:     " + calc.getTheta(), font1);
        Paragraph Ha = new Paragraph("Ha:     " + calc.getHa(), font1);
        Paragraph La = new Paragraph("La:     " + calc.getLa(), font1);
        Paragraph Db = new Paragraph("Db:     " + calc.getD_b(), font1);

        Anchor resultsAnchor = new Anchor("Results", subFont);
        int drag = (int) calc.getDrag();
        int roll = (int) calc.getRollover();
        Paragraph Tg = new Paragraph("Anchor cap Sliding :     " + drag, tgfont);
        Paragraph tipover = new Paragraph("Anchor cap Overturning:     " + roll, tipfont);

        doc.add(anchor);
        doc.add(identifier);
        doc.add(engineer);
        doc.add(jobsite);
        doc.add(latitude);
        doc.add(longitude);

        doc.add(vehicleAnchor);
        doc.add(vehicleclass);
        doc.add(vehicletype);
        doc.add(vehicleweight);
        doc.add(vehicletracklength);
        doc.add(vehicletrackwidth);
        doc.add(vehiclebladewidth);

        doc.add(soilAnchor);
        doc.add(soiltype);
        doc.add(soilunitweight);
        doc.add(soilfrictionangle);
        doc.add(soilcohesion);

        doc.add(measurementsAnchor);
        doc.add(beta);
        doc.add(theta);
        doc.add(Ha);
        doc.add(La);
        doc.add(Db);

        doc.add(resultsAnchor);
        doc.add(Tg);
        doc.add(tipover);
        Log.e("addingcontent", "complete");

    } catch (Exception e) {
        Font font1 = new Font(Font.FontFamily.HELVETICA, 24, Font.NORMAL, BaseColor.BLACK);

    }

}

From source file:controller.CCInstance.java

License:Open Source License

public final boolean signPdf(final String pdfPath, final String destination, final CCSignatureSettings settings,
        final SignatureListener sl) throws CertificateException, IOException, DocumentException,
        KeyStoreException, SignatureFailedException, FileNotFoundException, NoSuchAlgorithmException,
        InvalidAlgorithmParameterException {
    PrivateKey pk;/*from   www .  j  av  a2 s  .c  om*/

    final PdfReader reader = new PdfReader(pdfPath);
    pk = getPrivateKeyFromAlias(settings.getCcAlias().getAlias());

    if (getCertificationLevel(pdfPath) == PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED) {
        String message = Bundle.getBundle().getString("fileDoesNotAllowChanges");
        if (sl != null) {
            sl.onSignatureComplete(pdfPath, false, message);
        }
        throw new SignatureFailedException(message);
    }

    if (reader.getNumberOfPages() - 1 < settings.getPageNumber()) {
        settings.setPageNumber(reader.getNumberOfPages() - 1);
    }

    if (null == pk) {
        String message = Bundle.getBundle().getString("noSmartcardFound");
        if (sl != null) {
            sl.onSignatureComplete(pdfPath, false, message);
        }
        throw new CertificateException(message);
    }

    if (null == pkcs11ks.getCertificateChain(settings.getCcAlias().getAlias())) {
        String message = Bundle.getBundle().getString("certificateNullChain");
        if (sl != null) {
            sl.onSignatureComplete(pdfPath, false, message);
        }
        throw new CertificateException(message);
    }
    final ArrayList<Certificate> embeddedCertificateChain = settings.getCcAlias().getCertificateChain();
    final Certificate owner = embeddedCertificateChain.get(0);
    final Certificate lastCert = embeddedCertificateChain.get(embeddedCertificateChain.size() - 1);

    if (null == owner) {
        String message = Bundle.getBundle().getString("certificateNameUnknown");
        if (sl != null) {
            sl.onSignatureComplete(pdfPath, false, message);
        }
        throw new CertificateException(message);
    }

    final X509Certificate X509C = ((X509Certificate) lastCert);
    final Calendar now = Calendar.getInstance();
    final Certificate[] filledMissingCertsFromChainInTrustedKeystore = getCompleteTrustedCertificateChain(
            X509C);

    final Certificate[] fullCertificateChain;
    if (filledMissingCertsFromChainInTrustedKeystore.length < 2) {
        fullCertificateChain = new Certificate[embeddedCertificateChain.size()];
        for (int i = 0; i < embeddedCertificateChain.size(); i++) {
            fullCertificateChain[i] = embeddedCertificateChain.get(i);
        }
    } else {
        fullCertificateChain = new Certificate[embeddedCertificateChain.size()
                + filledMissingCertsFromChainInTrustedKeystore.length - 1];
        int i = 0;
        for (i = 0; i < embeddedCertificateChain.size(); i++) {
            fullCertificateChain[i] = embeddedCertificateChain.get(i);
        }
        for (int f = 1; f < filledMissingCertsFromChainInTrustedKeystore.length; f++, i++) {
            fullCertificateChain[i] = filledMissingCertsFromChainInTrustedKeystore[f];
        }
    }

    // Leitor e Stamper
    FileOutputStream os = null;
    try {
        os = new FileOutputStream(destination);
    } catch (FileNotFoundException e) {
        String message = Bundle.getBundle().getString("outputFileError");
        if (sl != null) {
            sl.onSignatureComplete(pdfPath, false, message);
        }
        throw new IOException(message);
    }

    // Aparncia da Assinatura
    final char pdfVersion;
    switch (Settings.getSettings().getPdfVersion()) {
    case "/1.2":
        pdfVersion = PdfWriter.VERSION_1_2;
        break;
    case "/1.3":
        pdfVersion = PdfWriter.VERSION_1_3;
        break;
    case "/1.4":
        pdfVersion = PdfWriter.VERSION_1_4;
        break;
    case "/1.5":
        pdfVersion = PdfWriter.VERSION_1_5;
        break;
    case "/1.6":
        pdfVersion = PdfWriter.VERSION_1_6;
        break;
    case "/1.7":
        pdfVersion = PdfWriter.VERSION_1_7;
        break;
    default:
        pdfVersion = PdfWriter.VERSION_1_7;
    }

    final PdfStamper stamper = (getNumberOfSignatures(pdfPath) == 0
            ? PdfStamper.createSignature(reader, os, pdfVersion)
            : PdfStamper.createSignature(reader, os, pdfVersion, null, true));

    final PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
    appearance.setSignDate(now);
    appearance.setReason(settings.getReason());
    appearance.setLocation(settings.getLocation());
    appearance.setCertificationLevel(settings.getCertificationLevel());
    appearance.setSignatureCreator(SIGNATURE_CREATOR);
    appearance.setCertificate(owner);

    final String fieldName = settings.getPrefix() + " " + (1 + getNumberOfSignatures(pdfPath));
    if (settings.isVisibleSignature()) {
        appearance.setVisibleSignature(settings.getPositionOnDocument(), settings.getPageNumber() + 1,
                fieldName);
        appearance.setRenderingMode(PdfSignatureAppearance.RenderingMode.DESCRIPTION);
        if (null != settings.getAppearance().getImageLocation()) {
            appearance.setImage(Image.getInstance(settings.getAppearance().getImageLocation()));
        }

        com.itextpdf.text.Font font = new com.itextpdf.text.Font(FontFactory
                .getFont(settings.getAppearance().getFontLocation(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0)
                .getBaseFont());

        font.setColor(new BaseColor(settings.getAppearance().getFontColor().getRGB()));
        if (settings.getAppearance().isBold() && settings.getAppearance().isItalic()) {
            font.setStyle(Font.BOLD + Font.ITALIC);
        } else if (settings.getAppearance().isBold()) {
            font.setStyle(Font.BOLD);
        } else if (settings.getAppearance().isItalic()) {
            font.setStyle(Font.ITALIC);
        } else {
            font.setStyle(Font.PLAIN);
        }

        appearance.setLayer2Font(font);
        String text = "";
        if (settings.getAppearance().isShowName()) {
            if (!settings.getCcAlias().getName().isEmpty()) {
                text += settings.getCcAlias().getName() + "\n";
            }
        }
        if (settings.getAppearance().isShowReason()) {
            if (!settings.getReason().isEmpty()) {
                text += settings.getReason() + "\n";
            }
        }
        if (settings.getAppearance().isShowLocation()) {
            if (!settings.getLocation().isEmpty()) {
                text += settings.getLocation() + "\n";
            }
        }
        if (settings.getAppearance().isShowDate()) {
            DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            SimpleDateFormat sdf = new SimpleDateFormat("Z");
            text += df.format(now.getTime()) + " " + sdf.format(now.getTime()) + "\n";
        }
        if (!settings.getText().isEmpty()) {
            text += settings.getText();
        }

        PdfTemplate layer2 = appearance.getLayer(2);
        Rectangle rect = settings.getPositionOnDocument();
        Rectangle sr = new Rectangle(rect.getWidth(), rect.getHeight());
        float size = ColumnText.fitText(font, text, sr, 1024, PdfWriter.RUN_DIRECTION_DEFAULT);
        ColumnText ct = new ColumnText(layer2);
        ct.setRunDirection(PdfWriter.RUN_DIRECTION_DEFAULT);
        ct.setAlignment(Element.ALIGN_MIDDLE);
        int align;
        switch (settings.getAppearance().getAlign()) {
        case 0:
            align = Element.ALIGN_LEFT;
            break;
        case 1:
            align = Element.ALIGN_CENTER;
            break;
        case 2:
            align = Element.ALIGN_RIGHT;
            break;
        default:
            align = Element.ALIGN_LEFT;
        }

        ct.setSimpleColumn(new Phrase(text, font), sr.getLeft(), sr.getBottom(), sr.getRight(), sr.getTop(),
                size, align);
        ct.go();
    } else {
        appearance.setVisibleSignature(new Rectangle(0, 0, 0, 0), 1, fieldName);
    }

    // CRL <- Pesado!
    final ArrayList<CrlClient> crlList = null;

    // OCSP
    OcspClient ocspClient = new OcspClientBouncyCastle();

    // TimeStamp
    TSAClient tsaClient = null;
    if (settings.isTimestamp()) {
        tsaClient = new TSAClientBouncyCastle(settings.getTimestampServer(), null, null);
    }

    final String hashAlg = getHashAlgorithm(X509C.getSigAlgName());

    final ExternalSignature es = new PrivateKeySignature(pk, hashAlg, pkcs11Provider.getName());
    final ExternalDigest digest = new ProviderDigest(pkcs11Provider.getName());

    try {
        MakeSignature.signDetached(appearance, digest, es, fullCertificateChain, crlList, ocspClient, tsaClient,
                0, MakeSignature.CryptoStandard.CMS);
        if (sl != null) {
            sl.onSignatureComplete(pdfPath, true, "");
        }
        return true;
    } catch (Exception e) {
        os.flush();
        os.close();
        new File(destination).delete();
        if ("sun.security.pkcs11.wrapper.PKCS11Exception: CKR_FUNCTION_CANCELED".equals(e.getMessage())) {
            throw new SignatureFailedException(Bundle.getBundle().getString("userCanceled"));
        } else if ("sun.security.pkcs11.wrapper.PKCS11Exception: CKR_GENERAL_ERROR".equals(e.getMessage())) {
            throw new SignatureFailedException(Bundle.getBundle().getString("noPermissions"));
        } else if (e instanceof ExceptionConverter) {
            String message = Bundle.getBundle().getString("timestampFailed");
            if (sl != null) {
                sl.onSignatureComplete(pdfPath, false, message);
            }
            throw new SignatureFailedException(message);
        } else {
            if (sl != null) {
                sl.onSignatureComplete(pdfPath, false, Bundle.getBundle().getString("unknownErrorLog"));
            }
            controller.Logger.getLogger().addEntry(e);
        }
        return false;
    }
}

From source file:Controller.PrintOrderManagedBean.java

public void executePDF(String maDH) {
    try {//from  w w  w.ja  v  a2  s  .  c o m

        DonHang donhang = new DonHang();
        donhang.init(maDH);
        float CONVERT = 28.346457f;// 1 cm
        FacesContext faces = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) faces.getExternalContext().getResponse();
        // setting some response headers
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        //response.setHeader("Content-disposition","inline; filename=kiran.pdf");
        response.setHeader("Pragma", "public");
        response.setContentType("application/pdf");
        //response.setHeader("Content-Disposition", "attachment;filename=\"ContactList.pdf\"");
        response.addHeader("Content-disposition", "attachment;filename=\"DataListBean.pdf\"");
        //step 1: creation of a document-object
        Document document = new Document(PageSize.A4, 0.5f * CONVERT, 0.5f * CONVERT, 1.0f * CONVERT,
                1.0f * CONVERT);
        //step 2: we create a writer that listens to the document
        // and directs a PDF-stream to a temporary buffer
        ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        BaseFont bf = BaseFont.createFont("c:\\windows\\fonts\\arial.ttf", BaseFont.IDENTITY_H,
                BaseFont.EMBEDDED);
        Font font = new Font(bf, 18, Font.BOLD);
        Font font11 = new Font(bf, 11, Font.NORMAL);
        Font font11_bo = new Font(bf, 11, Font.BOLD);
        Font font12 = new Font(bf, 12, Font.NORMAL);
        Font font10 = new Font(bf, 10, Font.NORMAL);
        Font font9 = new Font(bf, 9, Font.NORMAL);
        //step 3: we open the document
        document.open();

        PdfPTable tab_Header1;
        tab_Header1 = new PdfPTable(1);
        tab_Header1.setWidthPercentage(100);

        tab_Header1.setHorizontalAlignment(Element.ALIGN_CENTER);

        PdfPCell cell1;
        cell1 = new PdfPCell(new Phrase("CNG TY TNHH ABC FASHION", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(
                new Phrase("?a ch: 146 Linh Trung,P. Linh Trung, Q. Th ?c, TP HCM", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("S?T: 0909465621", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("?N GIAO HNG", font12));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Bn Bn:", font11_bo));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Tn: CNG TY TNHH ABC FASHION", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(
                new Phrase("?a ch: 146 Linh Trung,P. Linh Trung, Q. Th ?c, TP HCM", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("S in thoi: 0909465621", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Bn Mua:", font11_bo));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Tn: " + donhang.getTenKH(), font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("?a ch: " + donhang.getDiaChiKH(), font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("S in thoi: " + donhang.getSoDTKH(), font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Bn Vn chuyn:", font11_bo));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Tn:....................................", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("?a ch:...............................", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("S in thoi:...............................", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Danh sch hng ha:", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);
        ///////////////////////////////bn sn phm
        float[] crDonHang = { 1.0f * CONVERT, 4.0f * CONVERT, 1.0f * CONVERT, 2.0f * CONVERT, 2.0f * CONVERT };

        PdfPTable tab_Header2;
        tab_Header2 = new PdfPTable(crDonHang.length);
        tab_Header2.setWidthPercentage(100);
        tab_Header2.setWidths(crDonHang);
        tab_Header2.setHorizontalAlignment(Element.ALIGN_CENTER);
        NumberFormat formatter = new DecimalFormat("#,###,###");

        String[] crheader = { "STT", "Tn Hng", "S Lng", "Gi Bn(VN?)", "Thnh Ti?n(VN?)" };

        for (int i = 0; i < crheader.length; i++) {
            PdfPCell cell = new PdfPCell(new Phrase(crheader[i], font11));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);

            tab_Header2.addCell(cell);
        }
        int stt = 1;
        for (SanPhamDH sp : donhang.getListSP()) {

            PdfPCell cell = new PdfPCell(new Phrase(String.valueOf(stt), font11));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);

            tab_Header2.addCell(cell);

            cell = new PdfPCell(new Phrase(sp.getTenSP(), font11));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);

            tab_Header2.addCell(cell);

            cell = new PdfPCell(new Phrase(sp.getSoluong(), font11));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

            tab_Header2.addCell(cell);

            cell = new PdfPCell(new Phrase(formatter.format(Double.parseDouble(sp.getGiaSP())), font11));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

            tab_Header2.addCell(cell);

            cell = new PdfPCell(new Phrase(formatter.format(Double.parseDouble(sp.getThanhTien())), font11));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

            tab_Header2.addCell(cell);

            stt++;
        }
        cell1 = new PdfPCell(tab_Header2);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Tng ti?n hng:   "
                + formatter.format(
                        Double.parseDouble(donhang.getTienTamTinh() == null ? "0" : donhang.getTienTamTinh()))
                + " VN?", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Tng ti?n vn chuyn:   "
                + formatter.format(Double
                        .parseDouble(donhang.getTienVanChuyen() == null ? "0" : donhang.getTienVanChuyen()))
                + " VN?", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Tng ti?n thanh ton:   "
                + formatter.format(Double.parseDouble(donhang.getTongTien())) + " VN?", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("S ti?n thanh ton bng ch: "
                + DocTien.doctien(donhang.getTongTien().replaceAll(" ", "")) + "ng", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase(" ", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("TP H Ch Minh, ngy      thng       nm       ", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell1.setPaddingRight(1.0f * CONVERT);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        cell1 = new PdfPCell(new Phrase(" ", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        PdfPTable tab_Header3;
        tab_Header3 = new PdfPTable(3);
        tab_Header3.setWidthPercentage(100);

        tab_Header3.setHorizontalAlignment(Element.ALIGN_CENTER);

        cell1 = new PdfPCell(new Phrase("Ng?i nhn hng", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header3.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Ng?i giao hng", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header3.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Ng?i bn hng", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header3.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("(k v ghi r h? tn)", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header3.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("(k v ghi r h? tn)", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header3.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("(k v ghi r h? tn)", font11));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setPaddingBottom(5.0f);
        cell1.setBorder(0);
        tab_Header3.addCell(cell1);

        cell1 = new PdfPCell(tab_Header3);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setBorder(0);
        tab_Header1.addCell(cell1);

        document.add(tab_Header1);

        document.close();
        //step 6: we output the writer as bytes to the response output
        // the contentlength is needed for MSIE!!!
        response.setContentLength(baos.size());
        // write ByteArrayOutputStream to the ServletOutputStream
        ServletOutputStream out = response.getOutputStream();
        baos.writeTo(out);
        baos.flush();
        faces.responseComplete();

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

From source file:Controllers.ExportController.java

public static void exportExam(String path) {
    model = (DefaultTableModel) tableExam.getModel();
    int selectRow = tableExam.getSelectedRow();

    if (selectRow != -1) {
        int idExam = (int) model.getValueAt(selectRow, 0) - 1;
        exams = ExamModel.readExam();/*w w  w.ja v a  2s. c  om*/
        Exam ex = exams.getExam(idExam);

        try {
            Document document = new Document();
            PdfWriter.getInstance(document, new FileOutputStream(path));
            document.open();
            BaseFont f = BaseFont.createFont("/font/vuArial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            Font titleExamFont = new Font(f, 25.0f, Font.BOLD);
            Font titlePartFont = new Font(f, 18.0f, Font.BOLD);
            Font headFont = new Font(f, 13.0f, Font.BOLD);
            Font suggestionFont = new Font(f, 13.0f, Font.ITALIC);
            Font contentFont = new Font(f, 13.0f, Font.NORMAL);
            Paragraph align = new Paragraph(" ");
            Paragraph title = new Paragraph(ex.getNameExam(), titleExamFont);
            title.setAlignment(Paragraph.ALIGN_CENTER);
            document.add(title);
            document.add(align);

            ArrayList<Question> question = ex.getQuestions();

            boolean haveMultipleChoice = false;
            boolean haveEssay = false;
            // Kim tra xem c phn t lun khng
            for (Question q : question) {
                if (q instanceof Essay) {
                    haveEssay = true;
                }
                // Kim tra xem c phn trc nghim khng}
                else {
                    haveMultipleChoice = true;
                }
                if (haveEssay && haveMultipleChoice)
                    break;
            }

            int count;
            if (haveMultipleChoice) {
                count = 0;
                Paragraph titlePart = new Paragraph("Trc nghim", titlePartFont);
                document.add(align);
                document.add(titlePart);
                document.add(align);
                for (Question q : question)
                    if (q instanceof MultipleChoice) {
                        count++;
                        Phrase numberQuestion = new Phrase("Cu " + count + ": ", headFont);
                        Phrase contentQuestion = new Phrase(q.getContentQuestion(), contentFont);
                        Paragraph questionParagraph = new Paragraph();
                        questionParagraph.add(numberQuestion);
                        questionParagraph.add(contentQuestion);
                        document.add(questionParagraph);

                        MultipleChoice mc = (MultipleChoice) q;
                        ArrayList<Answer> answers = mc.getAnswers();

                        boolean ok = true;
                        for (int i = 0; i < answers.size(); ++i) {
                            Answer answer = answers.get(i);
                            if (answer.getContentAnswer().length() > 30)
                                ok = false;
                        }

                        if (ok == true) {
                            PdfPTable table = new PdfPTable(2);
                            for (int i = 0; i < answers.size(); ++i) {
                                Answer answer = answers.get(i);
                                PdfPCell answerParagraph = new PdfPCell(new Paragraph(
                                        (char) (65 + i) + ". " + answer.getContentAnswer(), contentFont));
                                answerParagraph.setBorder(Rectangle.NO_BORDER);
                                table.addCell(answerParagraph);
                            }
                            document.add(table);
                        } else {
                            PdfPTable table = new PdfPTable(1);
                            for (int i = 0; i < answers.size(); ++i) {
                                Answer answer = answers.get(i);
                                PdfPCell answerParagraph = new PdfPCell(new Paragraph(
                                        (char) (65 + i) + ". " + answer.getContentAnswer(), contentFont));
                                answerParagraph.setBorder(Rectangle.NO_BORDER);
                                table.addCell(answerParagraph);
                            }
                            document.add(table);
                        }
                    }
            }

            if (haveEssay) {
                count = 0;
                Paragraph titlePart = new Paragraph("T Lun", titlePartFont);
                document.add(align);
                document.add(titlePart);
                document.add(align);
                for (Question q : question)
                    if (q instanceof Essay) {
                        count++;
                        Phrase numberQuestion = new Phrase("Cu " + count + ": ", headFont);
                        Phrase contentQuestion = new Phrase(q.getContentQuestion(), contentFont);
                        Paragraph questionParagraph = new Paragraph();
                        questionParagraph.add(numberQuestion);
                        questionParagraph.add(contentQuestion);

                        Essay es = (Essay) q;
                        Phrase headerSuggestion = new Phrase("Gi : ", suggestionFont);
                        Phrase contentSuggestion = new Phrase(es.getSuggest(), contentFont);
                        Paragraph suggestion = new Paragraph();
                        suggestion.add(headerSuggestion);
                        suggestion.add(contentSuggestion);
                        document.add(questionParagraph);
                        document.add(suggestion);
                    }
            }

            document.close();
        } catch (FileNotFoundException exp) {
            exp.printStackTrace();
        } catch (DocumentException exp) {
            exp.printStackTrace();
        } catch (IOException exp) {
            exp.printStackTrace();
        }
    }
}

From source file:de.aidger.utils.pdf.ActivityReportConverter.java

License:Open Source License

/**
 * Writes the logos and the address of the institute.
 *///from w  ww  .  j  ava 2 s  .  co m
private void writeLogo() {
    try {
        Font generatedByFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 8);
        Image aidger = Image.getInstance(getClass().getResource("/de/aidger/res/pdf/AidgerLogo.png"));
        aidger.scaleAbsolute(80.0f, 20.0f);
        PdfPTable table = new PdfPTable(2);
        table.setTotalWidth(reader.getPageSize(1).getRight());
        PdfPCell cell = new PdfPCell(new Phrase(_("Generated by: "), generatedByFont));
        cell.setBorder(0);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setPaddingBottom(5);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        table.addCell(cell);
        cell = new PdfPCell(Image.getInstance(aidger));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(0);
        table.addCell(cell);
        table.writeSelectedRows(0, -1, 0, 25, contentByte);
    } catch (BadElementException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:de.aidger.utils.pdf.ActivityReportConverter.java

License:Open Source License

/**
 * Creates the table of employments./*from w  ww .  j  a v a  2s  .  c o m*/
 */
private void createTable() {
    try {
        Font tableTitleFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10);
        String[] tableTitles = { "Zeitraum", "Veranstaltung", "Umfang" };
        PdfPTable contentTable = new PdfPTable(1);
        PdfPTable titleTable = new PdfPTable(new float[] { 0.2f, 0.6f, 0.2f });
        /*
         * Create the titles of the table entries.
         */
        for (int i = 0; i < tableTitles.length; i++) {
            PdfPCell cell = new PdfPCell(new Phrase(tableTitles[i], tableTitleFont));
            titleTable.addCell(cell);
        }
        PdfPCell cell = new PdfPCell(titleTable);
        cell.setPaddingTop(10.0f);
        cell.setPaddingBottom(2.0f);
        cell.setBorder(0);
        contentTable.addCell(cell);
        cell = new PdfPCell(addRows());
        cell.setBorder(0);
        contentTable.addCell(cell);
        float xPos = 60, yPos = 500, width = reader.getPageSize(1).getWidth() - 120f;
        if (form.getFieldPositions("TableField") != null) {
            FieldPosition position = form.getFieldPositions("TableField").get(0);
            xPos = position.position.getLeft();
            yPos = position.position.getTop();
            width = position.position.getWidth();
        }
        contentTable.setTotalWidth(width);
        contentTable.writeSelectedRows(0, -1, xPos, yPos, contentByte);
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}