Example usage for com.itextpdf.text Font BOLD

List of usage examples for com.itextpdf.text Font BOLD

Introduction

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

Prototype

int BOLD

To view the source code for com.itextpdf.text Font BOLD.

Click Source Link

Document

this is a possible style.

Usage

From source file:controller.PdfManager.java

/**
 * This method will generate an pdf for the applicant
 * @param email the email of the user/*from  www  . jav  a2  s.  c  om*/
 * @param competences the competences that the applican has added
 * @param dates the availability periods that the applicant added
 * @throws IOException 
 */
public void downloadPDF(String email, List<CompetenceProfileDTO> competences, List<String> dates)
        throws IOException {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
    try {
        Font font1 = new Font(Font.FontFamily.HELVETICA, 30, Font.BOLD);
        Font font2 = new Font(Font.FontFamily.HELVETICA, 25, Font.UNDERLINE);
        Font font3 = new Font(Font.FontFamily.HELVETICA, 14);
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);
        document.open();
        Paragraph h1 = new Paragraph("" + email + " Application", font1);
        h1.setAlignment(Element.ALIGN_CENTER);
        document.add(h1);
        //Add all competences
        document.add(new Paragraph("Competences", font2));
        for (CompetenceProfileDTO s : competences) {
            document.add(new Paragraph(
                    "Work: " + s.getName() + " Years of Experience: " + s.getYearsOfExperience() + " ", font3));
        }

        document.add(new Paragraph("Availability", font2));
        for (String ava : dates) {
            document.add(new Paragraph("" + ava + "", font3));
        }
        document.close();

        // setting some response headers
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");
        response.setHeader("Content-Disposition", "inline; filename=\"" + email + "\".pdf");
        response.setContentType("application/pdf");

        // the contentlength
        response.setContentLength(baos.size());
        // write ByteArrayOutputStream to the ServletOutputStream
        OutputStream os = response.getOutputStream();
        baos.writeTo(os);
        os.flush();
        os.close();
    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:Controller.PrintOrderManagedBean.java

public void executePDF(String maDH) {
    try {/*from   ww  w .  j a  va2s . 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:Controller.Receipt.Controller_FXML_Receipt.java

public void createReceipt(String filename, String patientid)
        throws DocumentException, IOException, PrinterException {
    {/* ww w .  j  a va  2  s .  co  m*/

        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        Document document = new Document();
        String receipt_id = null;
        String patientname = null;
        String date = null;
        String total_sum = null;
        try {
            try {
                PdfWriter.getInstance(document, new FileOutputStream(filename));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (DocumentException ex) {
            Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.open();
        Font font = new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD);
        //getFont("c:/windows/fonts/Shruti.ttf",
        //BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10);
        //document.add(new Paragraph("english",font));
        com.itextpdf.text.Image img = null;
        //            try {
        //                img = com.itextpdf.text.Image.getInstance("C:");
        //                img.scalePercent(80f);
        //            } catch (BadElementException ex) {
        //                Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
        //            } catch (IOException ex) {
        //                Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
        //            }

        /*try {
         document.add(img);
         } catch (DocumentException ex) {
         Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
         }*/
        Paragraph title = new Paragraph("RECEIPT", font);
        Paragraph header = new Paragraph("SHARDA HOSPITAL");
        header.setAlignment(Element.ALIGN_CENTER);
        title.setAlignment(Element.ALIGN_CENTER);
        Paragraph receiptid = new Paragraph("R.No" + receipt_id, font);
        receiptid.setAlignment(Element.ALIGN_LEFT);
        Paragraph Date = new Paragraph("Date :" + date, font);
        Date.setAlignment(Element.ALIGN_RIGHT);
        try {
            document.add(header);
        } catch (DocumentException ex) {
            Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            document.add(title);
        } catch (DocumentException ex) {
            Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            document.add(receiptid);
        } catch (DocumentException ex) {
            Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            document.add(Date);
        } catch (DocumentException ex) {
            Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex);
        }
        String DOJ = null;
        String diagnosis = null;
        String no_of_days = null;
        String DOD = null;
        Paragraph patient_details = new Paragraph("Received " + total_sum + "from Mr./Mrs. " + patientname
                + " towards indoor/outdoor charges detailed as below."
                + " He/She was admitted in hospital/under treatment from" + DOJ + "to " + DOD
                + ". He/She is suffering from " + diagnosis + "." + " He/She has to take future medicie for"
                + no_of_days + ".", font);
        try {
            document.add(patient_details);
        } catch (DocumentException ex) {
            Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println("Chaitanya");
        Object newValue = null;
        //Check whether item is selected and set value of selected item to Label
        if (table.getSelectionModel().getSelectedItem() != null) {
            TableView.TableViewSelectionModel selectionModel = table.getSelectionModel();
            ObservableList selectedCells = selectionModel.getSelectedCells();
            TablePosition tablePosition = (TablePosition) selectedCells.get(0);
            Object val1 = tablePosition.getTableColumn().getCellData(newValue);
            System.out.println("Fee Type Value" + val1);
            TablePosition tablePosition1 = (TablePosition) selectedCells.get(1);
            Object val2 = tablePosition1.getTableColumn().getCellData(newValue);
            System.out.println("Charges Value" + val2);
        }

        document.close();
        String pdfFile = "report.pdf";
        try {
            printPDF(pdfFile);
        } catch (IOException ex) {
            Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex);
        } catch (PrinterException ex) {
            Logger.getLogger(Controller_FXML_Receipt.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:controllerPDF.Pdf3DTAlpha.java

private void addHeader() throws DocumentException {
    Paragraph paragraph = new Paragraph("3D&T - Defensores de Tquio 3 Edio Alpha");
    paragraph.setFont(new Font(FontFamily.TIMES_ROMAN, 15, Font.BOLD, BaseColor.BLACK));
    paragraph.setAlignment(1);// w  w  w  .j  av a2  s  .  com
    document.add(paragraph);
    paragraph = new Paragraph("FICHA DE PERSONAGEM");
    paragraph.setFont(new Font(FontFamily.TIMES_ROMAN, 15, Font.BOLD, BaseColor.BLUE));
    document.add(paragraph);

}

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  . j  av a 2 s.c  o m*/
        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:cv.mikusher.outros.exemploescola.PrimeiroPDF.java

License:Open Source License

public static void main(String[] args) throws Exception {
    Document doc = null;/*from w w w. ja  v  a2  s.c om*/
    OutputStream os = null;

    try {
        doc = new Document(PageSize.A4, 72, 72, 72, 72);

        os = new FileOutputStream("C://outPdf.pdf");

        PdfWriter.getInstance(doc, os);

        doc.open();
        Font ftT = new Font(Font.FontFamily.COURIER, 20, Font.BOLD);

        Paragraph pr_1 = new Paragraph("Meu primeiro arquivo PDF.", ftT);
        doc.add(pr_1);

        Paragraph pr_2 = new Paragraph("Ola mundo, um documento PDF criado em JAVA");
        doc.add(pr_2);

        //Image img = Image.getInstance("mikusher.jpg");
        //img.setAlignment(Element.ALIGN_CENTER);
        //doc.add(img);

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

From source file:cz.zcu.kiv.eegdatabase.logic.pdf.PDFUtils.java

License:Apache License

public Paragraph setHeader(Document document, String title) throws IOException, BadElementException {
    Paragraph paragraph = new Paragraph(title,
            FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD, BaseColor.BLACK));
    paragraph.setAlignment(Element.ALIGN_CENTER);

    Image img = GetResizedAndCenteredImage(path + convertPath("/files/images/" + HEADERIMG));
    float topMargin = img.getHeight() + 2 * PADDING[0];
    img.setAbsolutePosition(PADDING[3], (PageSize.A4.getHeight() - img.getHeight()) - PADDING[0]);
    paragraph.add(img);// ww  w  .  j ava2 s  .c om
    img = GetResizedAndCenteredImage(path + convertPath("/files/images/" + FOOTERIMG));
    img.setAbsolutePosition((PageSize.A4.getWidth() - img.getWidth()) / 2, PADDING[2]);
    paragraph.add(img);
    float bottomMargin = img.getHeight() + 2 * PADDING[2];

    document.setMargins(topMargin, PADDING[1], bottomMargin, PADDING[3]);

    paragraph.setSpacingAfter(1.5f * PADDING[0]);

    return paragraph;
}

From source file:cz.zcu.kiv.eegdatabase.logic.pdf.ReservationPDF.java

License:Apache License

public static PdfPTable formatReservation(Reservation reservation) {
    int padding = 5;

    GregorianCalendar created = new GregorianCalendar();
    created.setTime(reservation.getCreationTime());
    GregorianCalendar startTime = new GregorianCalendar();
    startTime.setTime(reservation.getStartTime());
    GregorianCalendar endTime = new GregorianCalendar();
    endTime.setTime(reservation.getEndTime());

    String personName = BookingRoomUtils.formatPersonName(reservation.getPerson());

    Font title = FontFactory.getFont("Trebuchet MS", "utf-8", 15, Font.BOLD, new BaseColor(59, 70, 00));
    Font header = FontFactory.getFont(FontFactory.TIMES_BOLD, 13, Font.BOLD, BaseColor.BLACK);
    Font value = FontFactory.getFont(FontFactory.TIMES, 13);

    PdfPTable table = new PdfPTable(2);
    PdfPCell cell;/*from  w  ww. j  ava  2  s. com*/
    Phrase phrase;

    phrase = new Phrase("Reservation by " + personName);
    phrase.setFont(title);
    cell = new PdfPCell(phrase);
    cell.setColspan(2);
    cell.setBorder(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorderWidthTop(1);
    cell.setBorderWidthLeft(1);
    cell.setBorderWidthRight(1);
    cell.setPadding(padding);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    phrase = new Phrase("Date: ");
    phrase.setFont(header);
    cell = new PdfPCell(phrase);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    cell.setBorderWidthLeft(1);
    cell.setPadding(padding);
    table.addCell(cell);

    phrase = new Phrase(BookingRoomUtils.getDate(startTime));
    phrase.setFont(value);
    cell = new PdfPCell(phrase);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    cell.setBorderWidthRight(1);
    cell.setPadding(padding);
    table.addCell(cell);

    phrase = new Phrase("Start: ");
    phrase.setFont(header);
    cell = new PdfPCell(phrase);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    cell.setBorderWidthLeft(1);
    cell.setPadding(padding);
    table.addCell(cell);

    phrase = new Phrase(BookingRoomUtils.getHoursAndMinutes(startTime));
    phrase.setFont(value);
    cell = new PdfPCell(phrase);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    cell.setBorderWidthRight(1);
    cell.setPadding(padding);
    table.addCell(cell);

    phrase = new Phrase("End: ");
    phrase.setFont(header);
    cell = new PdfPCell(phrase);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    cell.setBorderWidthLeft(1);
    cell.setBorderWidthBottom(1);
    cell.setPadding(padding);
    table.addCell(cell);

    phrase = new Phrase(BookingRoomUtils.getHoursAndMinutes(endTime));
    phrase.setFont(value);
    cell = new PdfPCell(phrase);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    cell.setBorderWidthRight(1);
    cell.setBorderWidthBottom(1);
    cell.setPadding(padding);
    table.addCell(cell);

    table.setSpacingBefore(10);
    table.setSpacingAfter(10);

    return table;
}

From source file:dbms.Bills1Controller.java

@FXML
void OnMouseClick(ActionEvent event)
        throws ClassNotFoundException, SQLException, FileNotFoundException, DocumentException {
    int c = check(phone_no.getText());
    int c1 = phone_no.getText().length();
    String s1 = product_id.getText();
    String s3 = cb1.getSelectionModel().getSelectedItem();
    String s7 = cb2.getSelectionModel().getSelectedItem();
    int s8 = cb3.getSelectionModel().getSelectedItem();
    String s2 = cust_name.getText();
    String s4 = address.getText();
    String s6 = date.getValue().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    String s5 = phone_no.getText();
    String s10 = total.getText();
    String s11 = cb4.getSelectionModel().getSelectedItem();
    String s12 = payment.getText();
    int to = Integer.parseInt(s10);

    if (c == 0 || c1 != 10 || total.getText().equals("") || cust_name.getText().equals("")
            || address.getText().equals("") || payment.getText().equals("")) {
        JOptionPane.showMessageDialog(null, "Something is wrong");
    } else {// ww  w  . ja  va  2 s . co  m
        try {
            Class.forName("com.mysql.jdbc.Driver");
            java.sql.Connection con = DriverManager
                    .getConnection("jdbc:mysql://localhost/dbms?user=root&password=india123");
            String str1 = "insert into sold_item values(?,?,?,?,?,?,?,?,?,?)";
            //  System.out.println(str1);
            java.sql.PreparedStatement stmt1 = con.prepareStatement(str1);
            stmt1.setString(1, s1);
            stmt1.setString(2, s3);
            stmt1.setString(3, s7);
            stmt1.setInt(4, s8);
            stmt1.setString(5, s2);
            stmt1.setString(6, s4);
            stmt1.setString(7, s5);
            stmt1.setString(8, s6);
            stmt1.setInt(9, to);
            stmt1.setString(10, s11);
            //   ResultSet rs1 = stmt1.executeQuery();
            stmt1.executeUpdate();
            //   con.close();
            JOptionPane.showMessageDialog(null, "Bill Generated");

            String str6 = "select * from sold_item where billid= '" + s1 + "'";
            PreparedStatement stmt2 = con.prepareStatement(str6);
            ResultSet rs = stmt2.executeQuery(str6);
            Document my_bill = new Document();
            PdfWriter.getInstance(my_bill, new FileOutputStream(s1 + ".pdf"));
            my_bill.open();
            Font f1 = new Font(FontFamily.TIMES_ROMAN, 20.0f, Font.BOLD, BaseColor.BLACK);
            Paragraph p2 = new Paragraph("XYZ Electronics", f1);
            p2.setAlignment(Paragraph.ALIGN_CENTER);
            my_bill.add(p2);
            //my_bill.add(Chunk.NEWLINE);
            Paragraph p3 = new Paragraph("BILL", f1);
            p3.setAlignment(Paragraph.ALIGN_CENTER);
            my_bill.add(p3);
            my_bill.add(Chunk.NEWLINE);
            PdfPTable bill_table = new PdfPTable(2);
            PdfPCell table_cell;
            while (rs.next()) {
                bill_table.addCell("Bill ID");
                String dept_id = rs.getString(1);
                table_cell = new PdfPCell(new Phrase(dept_id));
                bill_table.addCell(table_cell);

                bill_table.addCell("Product Type");
                String dept_name = rs.getString(2);
                table_cell = new PdfPCell(new Phrase(dept_name));
                bill_table.addCell(table_cell);

                bill_table.addCell("Product name");
                String dept_pname = rs.getString(3);
                table_cell = new PdfPCell(new Phrase(dept_pname));
                bill_table.addCell(table_cell);

                bill_table.addCell("Quantity");
                int dept_quan = rs.getInt(4);
                table_cell = new PdfPCell(new Phrase("" + dept_quan));
                bill_table.addCell(table_cell);

                bill_table.addCell("Customer Name");
                String manager_id = rs.getString(5);
                table_cell = new PdfPCell(new Phrase(manager_id));
                bill_table.addCell(table_cell);

                bill_table.addCell("Address");
                String location_id = rs.getString(6);
                table_cell = new PdfPCell(new Phrase(location_id));
                bill_table.addCell(table_cell);

                bill_table.addCell("Phone Number");
                String s = rs.getString(7);
                table_cell = new PdfPCell(new Phrase(s));
                bill_table.addCell(table_cell);

                bill_table.addCell("DATE");
                String ss = rs.getString(8);
                table_cell = new PdfPCell(new Phrase(ss));
                bill_table.addCell(table_cell);

                bill_table.addCell("Total");
                int dept_total = rs.getInt(9);
                table_cell = new PdfPCell(new Phrase("Rs. " + dept_total));
                bill_table.addCell(table_cell);

            }
            my_bill.add(bill_table);
            my_bill.add(Chunk.NEWLINE);
            Font f2 = new Font(FontFamily.TIMES_ROMAN, 20.0f, Font.UNDERLINE, BaseColor.BLACK);
            Paragraph p4 = new Paragraph("Manager Signature", f1);
            p4.setAlignment(Paragraph.ALIGN_RIGHT);
            my_bill.add(p4);

            my_bill.close();
            String spl[] = s7.split("-");
            String strr = "select Quantity from " + s3 + " where Company = '" + spl[0] + "' and ProductName = '"
                    + spl[1] + "'";
            PreparedStatement stmt3 = con.prepareStatement(strr);
            ResultSet rs3 = stmt3.executeQuery();
            rs3.next();
            int f = rs3.getInt(1);
            f = f - s8;
            String strr1 = "Update " + s3 + " set Quantity = " + f + " where Company = '" + spl[0]
                    + "' and ProductName = '" + spl[1] + "' ";
            PreparedStatement stmt4 = con.prepareStatement(strr1);
            stmt4.executeUpdate();

            String strr2 = "insert into payment values(?,?)";
            PreparedStatement stmt5 = con.prepareStatement(strr2);
            stmt5.setString(1, product_id.getText());
            stmt5.setString(2, payment.getText());
            stmt5.executeUpdate();
            rs.close();
            stmt2.close();
            con.close();

            product_id.setText("");
            // prdct_name.setText("");
            cust_name.setText("");
            address.setText("");
            phone_no.setText("");
        } catch (DocumentException | HeadlessException | FileNotFoundException | ClassNotFoundException
                | SQLException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
    }

}

From source file:de.domjos.schooltools.core.utils.fileUtils.PDFBuilder.java

License:Open Source License

public void addFont(String key, Font.FontFamily fontFamily, float size, boolean bold, boolean italic,
        BaseColor color) {//from  ww  w .  j  a  v a 2 s.  co m
    if (bold) {
        if (italic) {
            this.fonts.put(key, new Font(fontFamily, size, Font.BOLDITALIC, color));
        } else {
            this.fonts.put(key, new Font(fontFamily, size, Font.BOLD, color));
        }
    } else {
        if (italic) {
            this.fonts.put(key, new Font(fontFamily, size, Font.ITALIC, color));
        } else {
            this.fonts.put(key, new Font(fontFamily, size, Font.NORMAL, color));
        }
    }
}