Example usage for com.itextpdf.text Paragraph setAlignment

List of usage examples for com.itextpdf.text Paragraph setAlignment

Introduction

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

Prototype

public void setAlignment(int alignment) 

Source Link

Document

Sets the alignment of this paragraph.

Usage

From source file:controller.PdfManager.java

/**
 * This method will generate an pdf for the applicant
 * @param email the email of the user//from  w w w .ja  v  a 2 s . c o m
 * @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.Receipt.Controller_FXML_Receipt.java

public void createReceipt(String filename, String patientid)
        throws DocumentException, IOException, PrinterException {
    {// www.j a  v  a 2 s. c o  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);
    document.add(paragraph);/*from   www  . j  ava 2  s .  com*/
    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. co  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:crearpdf.CrearPDF.java

private void crearReportePDForacle(String select) throws Exception {

    Class.forName("oracle.jdbc.OracleDriver"); //Invocamos el Driver de Oracle
    Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/xe", "willson"/*usuario*/,
            "123456"/*contrasea*/); //Creamos la conexion para acceder a la base de datos
    Statement stmt = con.createStatement();
    ResultSet resultados = stmt.executeQuery(select); //Hacemos el select de la info que extraeremos de la base de datos
    Document reportePDF = new Document(PageSize.LETTER, 88, 88, 80, 15); //Creamos un nuevo Documento usando la libreria itextpdf importada.
    PdfWriter.getInstance(reportePDF, new FileOutputStream("REPORTE.pdf"));//Instanciamos y creamos el archivo
    reportePDF.open(); //Abrimos el archivo creado arriba.

    Paragraph parrafo = new Paragraph("Reporte del dia");
    parrafo.add("Este es el repote que nos da los datos");
    parrafo.setAlignment(Element.ALIGN_CENTER);

    PdfPTable Treportes = new PdfPTable(5);//Aqui asignamos el numero de columnas que tendra la tabla, en este casi 5.
    PdfPCell celdas_tabla;//Creamos las celdas que seran llenadas con los datos extraidos

    //Agregamos los titulos de cada Columna                   
    Treportes.addCell("ID");
    Treportes.addCell("Nombre");
    Treportes.addCell("Edad");
    Treportes.addCell("Mes Nacimiento");
    Treportes.addCell("Universidad");

    //ciclo para empezar a aadir los datos de la base de datos a las celdas correspondientes en el PDF
    ///System.out.println("Llenando pdf");
    while (resultados.next()) {

        String id = resultados.getString("ID");
        celdas_tabla = new PdfPCell(new Phrase(id));
        Treportes.addCell(celdas_tabla);
        String nombre = resultados.getString("NOMBRE");
        celdas_tabla = new PdfPCell(new Phrase(nombre));
        Treportes.addCell(celdas_tabla);
        String edad = resultados.getString("EDAD");
        celdas_tabla = new PdfPCell(new Phrase(edad));
        Treportes.addCell(celdas_tabla);
        String nacimiento = resultados.getString("MES_NACIMIENTO");
        celdas_tabla = new PdfPCell(new Phrase(nacimiento));
        Treportes.addCell(celdas_tabla);
        String universidad = resultados.getString("UNIVERSIDAD");
        celdas_tabla = new PdfPCell(new Phrase(universidad));
        Treportes.addCell(celdas_tabla);
        //System.out.println(id+" "+nombre+" "+edad);
    }/*from ww w .j a v a 2s . c  o m*/
    // System.out.println("Listo!");
    parrafo.add(Treportes);
    reportePDF.add(parrafo);

    //reportePDF.add(Treportes); //Insertamos los datos de la tabla en el PDF.                      
    reportePDF.close(); //Cerramos el archivo PDF una vez completado

    //Cerrar todas las conexiones
    resultados.close();
    stmt.close();
    con.close();

}

From source file:crearpdf.CrearPDF.java

public static void main(String[] args) throws Exception {

    Class.forName("oracle.jdbc.OracleDriver"); //Invocamos el Driver de Oracle
    Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/xe", "willson"/*usuario*/,
            "123456"/*contrasea*/); //Creamos la conexion para acceder a la base de datos
    Statement stmt = con.createStatement();
    ResultSet resultados = stmt//w  w  w.  j ava2 s  . c  om
            .executeQuery("SELECT ID, NOMBRE, EDAD, MES_NACIMIENTO, UNIVERSIDAD FROM PERSONAS"); //Hacemos el select de la info que extraeremos de la base de datos
    Document reportePDF = new Document(PageSize.B4, 88, 88, 80, 15); //Creamos un nuevo Documento usando la libreria itextpdf importada.
    PdfWriter.getInstance(reportePDF, new FileOutputStream("REPORTE.pdf"));//Instanciamos y creamos el archivo
    reportePDF.open(); //Abrimos el archivo creado arriba.

    Paragraph parrafo = new Paragraph("Reporte del dia");
    parrafo.setAlignment(Element.ALIGN_CENTER);

    PdfPTable Treportes = new PdfPTable(5);//Aqui asignamos el numero de columnas que tendra la tabla, en este casi 5.
    PdfPCell celdas_tabla;//Creamos las celdas que seran llenadas con los datos extraidos

    //Agregamos los titulos de cada Columna                   
    Treportes.addCell("ID");
    Treportes.addCell("Nombre");
    Treportes.addCell("Edad");
    Treportes.addCell("Mes Nacimiento");
    Treportes.addCell("Universidad");

    //ciclo para empezar a aadir los datos de la base de datos a las celdas correspondientes en el PDF
    System.out.println("Llenando pdf");
    while (resultados.next()) {

        String id = resultados.getString("ID");
        celdas_tabla = new PdfPCell(new Phrase(id));
        Treportes.addCell(celdas_tabla);

        String nombre = resultados.getString("NOMBRE");
        celdas_tabla = new PdfPCell(new Phrase(nombre));
        Treportes.addCell(celdas_tabla);

        String edad = resultados.getString("EDAD");
        celdas_tabla = new PdfPCell(new Phrase(edad));
        Treportes.addCell(celdas_tabla);

        String nacimiento = resultados.getString("MES_NACIMIENTO");
        celdas_tabla = new PdfPCell(new Phrase(nacimiento));
        Treportes.addCell(celdas_tabla);

        String universidad = resultados.getString("UNIVERSIDAD");
        celdas_tabla = new PdfPCell(new Phrase(universidad));
        Treportes.addCell(celdas_tabla);

        System.out.println(id + " " + nombre + " " + edad);
    }
    System.out.println("Listo!");
    reportePDF.add(parrafo);
    reportePDF.add(Treportes); //Insertamos los datos de la tabla en el PDF.                      
    reportePDF.close(); //Cerramos el archivo PDF una vez completado

    //Cerrar todas las conexiones
    resultados.close();
    stmt.close();
    con.close();

}

From source file:crs.Manager_DailyReturnController.java

@FXML
private void onDownload(ActionEvent event) {
    if (report_datepicker.getValue() == null)
        return;/*from  w  ww . j  a va  2 s  .c  om*/

    String date = report_datepicker.getValue().toString();

    Vlist = CRS.getDailyReturn(date, -1);
    bdata = getDailyReturnByBranch(date);
    cdata = getReturnByCategory(date);

    String filename = report_datepicker.getValue().toString() + "_DailyRental.pdf";
    DirectoryChooserBuilder builder = DirectoryChooserBuilder.create();
    builder.title("Hello World");
    String cwd = System.getProperty("user.dir");
    File file = new File(cwd);
    builder.initialDirectory(file);
    DirectoryChooser chooser = builder.build();
    File chosenDir = chooser.showDialog(null);
    if (chosenDir != null) {
        System.out.println(chosenDir.getAbsolutePath());
    } else {
        System.out.print("no directory chosen");
    }

    Document document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream(chosenDir.getAbsolutePath() + "/" + filename));

        document.open();
        Paragraph paragraph = new Paragraph();
        paragraph.add("Daily Return Report of " + report_datepicker.getValue().toString());
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setSpacingAfter(40);
        document.add(paragraph);
        document.add(createPDFTableVehicle(Vlist));
        paragraph.clear();
        paragraph.add("  ");
        paragraph.setSpacingAfter(20);
        document.add(paragraph);
        document.add(createPDFTableByCategory(cdata));

        paragraph.setSpacingAfter(20);
        document.add(paragraph);
        document.add(createPDFTableByBranch(bdata));
        document.close();
        label_result.setText("Download successfully");
        label_result.setVisible(true);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:crs.Manager_Report_bybranchController.java

@FXML
private void onDownload(ActionEvent event) {
    if (report_datepicker.getValue() == null || combo_loc.getValue() == null)
        return;//from w ww.j av  a 2 s  . c o  m
    String date = report_datepicker.getValue().toString();
    bid = getBranchid(combo_loc.getValue().toString());
    Vlist = CRS.getDailyRental(date, bid);
    cdata = getRentalByCategory(date);
    String filename = report_datepicker.getValue().toString() + "_DailyRental_"
            + combo_loc.getValue().toString() + ".pdf";
    DirectoryChooserBuilder builder = DirectoryChooserBuilder.create();
    builder.title("Hello World");
    String cwd = System.getProperty("user.dir");
    File file = new File(cwd);
    builder.initialDirectory(file);
    DirectoryChooser chooser = builder.build();
    File chosenDir = chooser.showDialog(null);
    if (chosenDir != null) {
        System.out.println(chosenDir.getAbsolutePath());
    } else {
        System.out.print("no directory chosen");
    }

    Document document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream(chosenDir.getAbsolutePath() + "/" + filename));

        document.open();
        Paragraph paragraph = new Paragraph();
        paragraph.add("Daily Report of " + report_datepicker.getValue().toString() + "  location: "
                + combo_loc.getValue().toString());
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setSpacingAfter(40);
        document.add(paragraph);
        document.add(createPDFTableVehicle(Vlist));
        paragraph.clear();
        paragraph.add("  ");
        paragraph.setSpacingAfter(20);
        document.add(paragraph);
        document.add(createPDFTableByCategory(cdata));

        document.close();
        label_result.setText("Download successfully");
        label_result.setVisible(true);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:crs.Manager_Report_DailyController.java

@FXML
private void onDownload(ActionEvent event) {
    if (report_datepicker.getValue() == null)
        return;/*from w  w w  .j a  va2 s  . c o m*/
    String filename = report_datepicker.getValue().toString() + "_DailyRental.pdf";
    DirectoryChooserBuilder builder = DirectoryChooserBuilder.create();
    builder.title("Hello World");
    String cwd = System.getProperty("user.dir");
    File file = new File(cwd);
    builder.initialDirectory(file);
    DirectoryChooser chooser = builder.build();
    File chosenDir = chooser.showDialog(null);
    if (chosenDir != null) {
        System.out.println(chosenDir.getAbsolutePath());
    } else {
        System.out.print("no directory chosen");
    }

    Document document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream(chosenDir.getAbsolutePath() + "/" + filename));

        document.open();
        Paragraph paragraph = new Paragraph();
        paragraph.add("Daily Report of " + report_datepicker.getValue().toString());
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setSpacingAfter(40);
        document.add(paragraph);
        document.add(createPDFTableVehicle(Vlist));
        paragraph.clear();
        paragraph.add("  ");
        paragraph.setSpacingAfter(20);
        document.add(paragraph);
        document.add(createPDFTableByCategory(cdata));

        paragraph.setSpacingAfter(20);
        document.add(paragraph);
        document.add(createPDFTableByBranch(bdata));
        document.close();
        label_result.setText("Download successfully");
        label_result.setVisible(true);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:crs.Manager_ReturnbybranchController.java

@FXML
private void onDownload(ActionEvent event) {
    if (report_datepicker.getValue() == null || combo_loc.getValue() == null)
        return;/*from  w  w  w.j ava 2s .  c om*/
    String date = report_datepicker.getValue().toString();
    bid = getBranchid(combo_loc.getValue().toString());
    Vlist = CRS.getDailyReturn(date, bid);
    cdata = getReturnByCategory(date);
    String filename = report_datepicker.getValue().toString() + "_DailyRental_"
            + combo_loc.getValue().toString() + ".pdf";
    DirectoryChooserBuilder builder = DirectoryChooserBuilder.create();
    builder.title("Hello World");
    String cwd = System.getProperty("user.dir");
    File file = new File(cwd);
    builder.initialDirectory(file);
    DirectoryChooser chooser = builder.build();
    File chosenDir = chooser.showDialog(null);
    if (chosenDir != null) {
        System.out.println(chosenDir.getAbsolutePath());
    } else {
        System.out.print("no directory chosen");
    }

    Document document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream(chosenDir.getAbsolutePath() + "/" + filename));

        document.open();
        Paragraph paragraph = new Paragraph();
        paragraph.add("Daily Report of " + report_datepicker.getValue().toString() + "  location: "
                + combo_loc.getValue().toString());
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setSpacingAfter(40);
        document.add(paragraph);
        document.add(createPDFTableVehicle(Vlist));
        paragraph.clear();
        paragraph.add("  ");
        paragraph.setSpacingAfter(20);
        document.add(paragraph);
        document.add(createPDFTableByCategory(cdata));

        document.close();
        label_result.setText("Download successfully");
        label_result.setVisible(true);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(Manager_ReportController.class.getName()).log(Level.SEVERE, null, ex);
    }

}