Example usage for com.itextpdf.layout.property TextAlignment LEFT

List of usage examples for com.itextpdf.layout.property TextAlignment LEFT

Introduction

In this page you can find the example usage for com.itextpdf.layout.property TextAlignment LEFT.

Prototype

TextAlignment LEFT

To view the source code for com.itextpdf.layout.property TextAlignment LEFT.

Click Source Link

Usage

From source file:AAMAirline.service.PdfServlet.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    RuntimeTypeAdapterFactory<Jsonable> rta = RuntimeTypeAdapterFactory.of(Jsonable.class, "_class")
            .registerSubtype(Ciudad.class, "Ciudad").registerSubtype(Tiquete.class, "Tiquete")
            .registerSubtype(Ruta.class, "Ruta").registerSubtype(Avion.class, "Avion")
            .registerSubtype(Usuario.class, "Usuario").registerSubtype(Asiento.class, "Asiento")
            .registerSubtype(Vuelo.class, "Vuelo");
    response.setContentType("aplication/pdf");
    response.setHeader("Content-Disposition", "inline;filename=\"report.pdf\"");
    PdfDocument pdf = new PdfDocument(new PdfWriter(response.getOutputStream()));
    Gson gson = new GsonBuilder().registerTypeAdapterFactory(rta).setDateFormat("dd/MM/yyyy").create();
    String json;/*w  w  w.  j  ava 2  s.c  om*/
    try (Document document = new Document(pdf)) {
        Paragraph p;
        p = new Paragraph("TIQUETE DE VUELO");
        p.setTextAlignment(TextAlignment.CENTER);
        p.setBold();
        p.setBackgroundColor(Color.PINK);
        document.add(p);
        String h = "Vuelo %s, %s - %s, %s %s %s";
        String codigo_tiquete = request.getParameter("tiquete");
        Tiquete ticket = AAMAirlineModel.consultaTiquete(codigo_tiquete);
        ArrayList<String> asientosIda = AAMAirlineModel.getAsientosPDF(ticket.getCodigo_Tiquete(),
                ticket.getVueloida().getAvion().getCodigo_Avion());
        ArrayList asientosVuelta;
        String asientos = "";
        String horaVuelta = "";
        Float precio = (ticket.getVueloida().getPrecio()) * (asientosIda.size());
        if (ticket.getVueloVuelta() != null) {
            asientosVuelta = AAMAirlineModel.getAsientosPDF(ticket.getCodigo_Tiquete(),
                    ticket.getVueloVuelta().getAvion().getCodigo_Avion());
            horaVuelta = " / salida vuelo Vuelta " + ticket.getVueloVuelta().getHora_salida() + " horas ";
            asientos = asientos + "Vuelta \n";
            for (int i = 0; i < asientosVuelta.size(); i++) {
                asientos = asientos + asientosVuelta.get(i) + "\n";
            }
            precio += (ticket.getVueloVuelta().getPrecio() * asientosVuelta.size());
        }
        String horaida = ticket.getVueloida().getHora_salida();
        String algo = " horas ";
        h = String.format(h, ticket.getVueloida().getCodigo_Vuelo(),
                ticket.getVueloida().getRuta().getCiudadO().getNombre(),
                ticket.getVueloida().getRuta().getCiudadD().getNombre(), ticket.getVueloida().getDia_salida(),
                " salida vuelo ida :" + horaida + algo, horaVuelta);
        p = new Paragraph(h);
        p.setTextAlignment(TextAlignment.LEFT);
        p.setBold();
        document.add(p);

        for (int i = 0; i < asientosIda.size(); i++) {
            asientos = asientos + "Ida: \n";
            asientos = asientos + asientosIda.get(i) + "\n";
        }
        p = new Paragraph("------------- Asientos ------------- \n" + asientos);
        document.add(p);

        p = new Paragraph("COSTO TOTAL: $ " + precio);
        p.setTextAlignment(TextAlignment.RIGHT);
        p.setBold();
        p.setBackgroundColor(Color.PINK);
        document.add(p);
    } catch (SQLException ex) {
        Logger.getLogger(PdfServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:cl.a2r.wsmicampov2.dao.TrasladoDAO.java

public static void generarDocumentoTraslado(Transaccion trx, Integer trasladoId) throws SQLException {

    Traslado traslado = selectTrasladoById(trx, trasladoId);
    List<String> listDiios = selectDiiosTrasladoById(trx, trasladoId);
    try {//w w  w.  j a  v  a 2 s  . c  o  m

        Integer identificadorTraslado = trasladoId;
        String fundoOrigen = traslado.getFundoOrigen();
        String fundoDestino = traslado.getFundoDestino();
        Integer cantAnimales = listDiios.size();
        Date fecha = traslado.getFecha();
        String nombreChofer = traslado.getNombreChofer();
        String rutChofer = traslado.getRutChofer();
        String patenteCamion = traslado.getPatenteCamion();
        String patenteAcoplado = traslado.getAcopladoPatente();
        String nombreTransportista = traslado.getNombreTransportista();
        String rutTransportista = traslado.getRutTransportista();

        String correoDestino = traslado.getCorreo();

        DateFormat df = new SimpleDateFormat("dd-MM-yyyy hh_mm_ss");
        DateFormat df2 = new SimpleDateFormat("dd-MM-yyyy");
        Date today = Calendar.getInstance().getTime();
        String reportDate = df.format(today);
        String reportDate2 = df2.format(today);

        String fileName = "Traslado Nro. " + identificadorTraslado + "-" + reportDate2 + " " + fundoOrigen + "_"
                + fundoDestino;
        //            String fileRoot="Z:\\Chilterra\\MiCampoGuias\\"+fileName+".pdf";

        String fileRoot = "/usr/share/MiCampoGuiasUpload/" + fileName + ".pdf";

        PdfWriter writer = new PdfWriter(fileRoot);

        PdfDocument pdf = new PdfDocument(writer);

        Document document = new Document(pdf);

        addPageToGuia(traslado, listDiios, document, cantAnimales);
        addSpaces(document);

        //Firmas        
        Table firmas = new Table(3);
        firmas.addCell(CellHelper.getCellFirma("Responsable fundo origen", TextAlignment.CENTER));
        firmas.addCell(CellHelper.getCell("", TextAlignment.LEFT));
        firmas.addCell(CellHelper.getCellFirma("Transportista", TextAlignment.CENTER));
        document.add(firmas);

        copiaPara("Fundo origen", document);

        document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));

        addDiiosPage(document, listDiios);
        document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));

        addPageToGuia(traslado, listDiios, document, cantAnimales);
        addSpaces(document);

        Table firmas2 = new Table(3);
        firmas2.addCell(CellHelper.getCellFirma("Responsable fundo destino", TextAlignment.CENTER));
        firmas2.addCell(CellHelper.getCell("", TextAlignment.LEFT));
        firmas2.addCell(CellHelper.getCellFirma("Transportista", TextAlignment.CENTER));
        document.add(firmas2);

        copiaPara("Fundo destino", document);

        document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));

        addDiiosPage(document, listDiios);

        document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));

        addPageToGuia(traslado, listDiios, document, cantAnimales);
        addSpaces(document);

        Table firmas3 = new Table(3);
        firmas3.addCell(CellHelper.getCellFirma("Responsable fundo origen", TextAlignment.CENTER));
        firmas3.addCell(CellHelper.getCell("", TextAlignment.LEFT));
        firmas3.addCell(CellHelper.getCellFirma("Responsable fundo destino", TextAlignment.CENTER));
        document.add(firmas3);

        copiaPara("Transportista", document);

        document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
        addDiiosPage(document, listDiios);

        document.close();

        File file = new File(fileRoot);
        InputStream inputStream = new FileInputStream(file);
        int fileLength = (int) file.length();

        byte[] bytes = new byte[fileLength];
        inputStream.read(bytes);

        Correo correo = new Correo();
        correo.setFrom("desarrollador@chilterra.com");
        correo.setTo(correoDestino + ";" + "sipec@chilterra.com");

        correo.setSubject("Traslado interno de animales Nro: " + trasladoId);
        correo.setBody("");

        correo.addAdjunto(bytes, "application/pdf", fileName + ".pdf");
        correo.enviar();
    } catch (Exception ex) {

    }
}

From source file:cl.a2r.wsmicampov2.dao.TrasladoDAO.java

public static void addPageToGuia(Traslado traslado, List<String> listDiios, Document document,
        Integer cantAnimales) {//from w  ww . j av  a 2  s.  co  m

    try {

        Integer identificadorTraslado = traslado.getId();
        String fundoOrigen = traslado.getFundoOrigen();
        String fundoDestino = traslado.getFundoDestino();
        Date fecha = traslado.getFecha();
        String nombreChofer = traslado.getNombreChofer();
        String rutChofer = traslado.getRutChofer();
        String patenteCamion = traslado.getPatenteCamion();
        String patenteAcoplado = traslado.getAcopladoPatente();
        String nombreTransportista = traslado.getNombreTransportista();
        String rutTransportista = traslado.getRutTransportista();

        String imagePath = "/usr/share/MiCampoGuiasUpload/A2RLogo.png";
        //        String imagePath="Z:\\Chilterra\\MiCampoGuias\\A2RLogo.png";

        DateFormat df = new SimpleDateFormat("dd-MM-yyyy hh_mm_ss");
        DateFormat df2 = new SimpleDateFormat("dd-MM-yyyy");
        Date today = Calendar.getInstance().getTime();
        String reportDate = df.format(today);
        String reportDate2 = df2.format(today);

        PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD);

        Text fechaText = new Text("Fecha: " + reportDate2).setTextAlignment(TextAlignment.RIGHT);
        Paragraph paragraphFecha = new Paragraph().add(fechaText);
        paragraphFecha.setTextAlignment(TextAlignment.RIGHT);
        document.add(paragraphFecha);

        Text title = new Text("TRASLADO INTERNO DE ANIMALES No. " + identificadorTraslado).setFont(bold);
        title.setFontSize(12);

        Image a2R = new Image(ImageDataFactory.create(imagePath));
        Paragraph p = new Paragraph("").add(a2R).add(title);

        document.add(p);

        //Datos del traslado
        Table table = new Table(2);

        table.addCell(CellHelper.getCell("Fundo origen: ", fundoOrigen, TextAlignment.LEFT));
        table.addCell(CellHelper.getCell("Fundo destino: ", fundoDestino, TextAlignment.LEFT));

        table.addCell(CellHelper.getCell("Nombre Chofer: ", nombreChofer, TextAlignment.LEFT));
        table.addCell(CellHelper.getCell("Rut Chofer: ", nombreChofer, TextAlignment.LEFT));

        table.addCell(CellHelper.getCell("Patente camin: ", patenteCamion, TextAlignment.LEFT));
        table.addCell(CellHelper.getCell("Patente acoplado: ", patenteAcoplado, TextAlignment.LEFT));

        table.addCell(CellHelper.getCell("Nombre transportista: ", nombreTransportista, TextAlignment.LEFT));
        table.addCell(CellHelper.getCell("Rut transportista: ", rutTransportista, TextAlignment.LEFT));

        document.add(table);

        Paragraph totalAnimales = CellHelper.getBoldParagraph("Cantidad total de animales: ",
                cantAnimales.toString());

        document.add(totalAnimales);

        //Observaciones
        Paragraph observaciones = new Paragraph("Observaciones: ").setBold();
        document.add(observaciones);

        Table observTable = new Table(1);
        observTable.addCell(CellHelper.getCellObservaciones("", TextAlignment.LEFT));
        document.add(observTable);

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

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

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

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

    } catch (Exception ex) {

    }

}

From source file:cl.a2r.wsmicampov2.dao.TrasladoDAO.java

public static void addDiiosPage(Document document, List<String> listDiios) {

    try {//from   w  w w  .ja va  2s. c  o m

        Integer cantAnimales = listDiios.size();
        Integer diff = 0;

        if (listDiios.size() < 6) {
            diff = 6 - cantAnimales;
        } else {

            if (cantAnimales % 6 != 0) {

                Integer cociente = cantAnimales / 6;
                diff = ((cociente + 1) * 6) - cantAnimales;
            }

        }

        for (int i = 0; i < diff; i++) {
            listDiios.add(" ");
        }

        PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD);
        Text subTitle = new Text("Diios: ").setFont(bold);
        Paragraph subtitleParagraph = new Paragraph().add(subTitle);

        document.add(subtitleParagraph);
        Table tableDiios = new Table(6);
        for (int i = 0; i < listDiios.size(); i++) {

            tableDiios.addCell(CellHelper.getCellDiios(listDiios.get(i), TextAlignment.LEFT));
        }

        document.add(tableDiios);

    } catch (Exception ex) {

    }

}

From source file:com.asptt.plongee.resa.util.UtilsFSpdf.java

private Table createEntete(FicheSecurite fs, int numeroPage, int nbPage) throws java.io.IOException {
        float[] columnWidths = { 20, 27, 23, 23, 6 };
        // table : premiere table pour les parametres de la plonge
        Table table = new Table(columnWidths);
        table.setMargins(0, 0, 0, 0);//  w ww  . j a  v  a 2  s. c  o  m
        table.setWidthPercent(100);
        // entete style pour les entetes
        Style entete = new Style();
        PdfFont fontEntete = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
        entete.setFont(fontEntete).setFontSize(12);
        entete.setFontColor(Color.BLACK);
        // style pour les libells
        Style libelle = new Style();
        PdfFont fontLibelle = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
        libelle.setFont(fontLibelle).setFontSize(12);
        libelle.setFontColor(Color.RED);

        Paragraph entete1 = new Paragraph();
        entete1.add(new Text("DATE\n").addStyle(entete));
        entete1.add(new Text("DIRECTEUR DE PLONGEE\n").addStyle(entete));
        entete1.add(new Text("PILOTE DU BATEAU\n").addStyle(entete));
        entete1.add(new Text("LIEU DE PLONGEE\n").addStyle(entete));
        entete1.add(new Text("METEO\n").addStyle(entete));

        Paragraph libelle1 = new Paragraph();
        libelle1.add(new Text(": " + ResaUtil.getDateString(fs.getDatePlongee()) + "\n").addStyle(libelle));
        libelle1.add(new Text(": " + fs.getNomDP() + "\n").addStyle(libelle));
        libelle1.add(new Text(": " + fs.getNomPilote() + "\n").addStyle(libelle));
        libelle1.add(new Text(": " + fs.getSite() + "\n").addStyle(libelle));
        libelle1.add(new Text(": " + fs.getMeteo() + "\n").addStyle(libelle));

        Cell cellEntete1 = new Cell();
        cellEntete1.add(entete1);
        cellEntete1.setBorderRight(Border.NO_BORDER);
        cellEntete1.setHorizontalAlignment(HorizontalAlignment.LEFT);
        table.addCell(cellEntete1);

        Cell cellLibelle1 = new Cell();
        cellLibelle1.add(libelle1);
        cellLibelle1.setBorderLeft(Border.NO_BORDER);
        cellLibelle1.setTextAlignment(TextAlignment.LEFT);
        table.addCell(cellLibelle1);

        Paragraph titre = new Paragraph();
        titre.add(new Text("ASPTT MARSEILLE\n").addStyle(entete));
        titre.add(new Text("PLONGEE\n").addStyle(entete));
        titre.add(new Text("---\n").addStyle(entete));
        titre.add(new Text("Fiche de Scurit\n").addStyle(entete));

        Cell cellTitre = new Cell();
        cellTitre.add(titre);
        cellTitre.setTextAlignment(TextAlignment.CENTER);
        cellTitre.setVerticalAlignment(VerticalAlignment.MIDDLE);
        table.addCell(cellTitre);

        Paragraph entete2 = new Paragraph();
        entete2.add(new Text("PLONGEE NUMERO\n").addStyle(entete));
        entete2.add(new Text("NOMBRE DE PLONGEURS\n").addStyle(entete));
        entete2.add(new Text("HEURE DE DEPART\n").addStyle(entete));
        entete2.add(new Text("HEURES BATEAU\n").addStyle(entete));
        entete2.add(new Text("Page \n").addStyle(entete));

        Paragraph libelle2 = new Paragraph();
        libelle2.add(new Text(": " + fs.getNumeroPlongee() + "\n").addStyle(libelle));
        libelle2.add(new Text(": " + fs.getNbPlongeurs() + "\n").addStyle(libelle));
        libelle2.add(new Text(": " + fs.getHhDepart() + ":" + fs.getMnDepart() + "\n").addStyle(libelle));
        libelle2.add(new Text(": " + fs.getNbHeuresBateau() + "\n").addStyle(libelle));
        libelle2.add(new Text(": " + numeroPage + " / " + nbPage + "\n").addStyle(libelle));

        Cell cellEntete2 = new Cell();
        cellEntete2.add(entete2);
        cellEntete2.setBorderRight(Border.NO_BORDER);
        cellEntete2.setHorizontalAlignment(HorizontalAlignment.RIGHT);
        table.addCell(cellEntete2);

        Cell cellLibelle2 = new Cell();
        cellLibelle2.add(libelle2);
        cellLibelle2.setBorderLeft(Border.NO_BORDER);
        cellLibelle2.setTextAlignment(TextAlignment.LEFT);
        table.addCell(cellLibelle2);

        return table;
    }

From source file:controller.ReporteDiarioController.java

public Cell generaCeldaInvitados(ArrayList<Invitado> l) throws IOException {
    Cell c = new Cell();
    c.setBorder(Border.NO_BORDER);
    c.setFont(PdfFontFactory.createRegisteredFont("times-italic"));
    c.setFontSize(8);//from w w w  . jav a2s .  co m
    c.setTextAlignment(TextAlignment.LEFT);
    for (Invitado in : l) {
        if (in.getFecha().equals(date.getValue().format(DateTimeFormatter.ISO_LOCAL_DATE)))
            c.add(in.getNombre() + " " + in.getApellido());
    }
    return c;

}

From source file:controller.ReporteFechaController.java

public Cell generaCeldaInvitados(ArrayList<Invitado> l) throws IOException {
    Cell c = new Cell();
    c.setBorder(Border.NO_BORDER);
    c.setFont(PdfFontFactory.createRegisteredFont("times-italic"));
    c.setFontSize(8);//from   w  w  w.  ja v a 2s.c o  m
    c.setTextAlignment(TextAlignment.LEFT);
    for (Invitado r : l) {
        if (LocalDate.parse(r.getFecha()).plusDays(1).isAfter(from.getValue())
                && LocalDate.parse(r.getFecha()).minusDays(1).isBefore(to.getValue())) {
            c.add(r.getNombre() + " " + r.getApellido());
        }
    }
    return c;

}

From source file:controller.ReporteMesController.java

public Cell generaCeldaInvitados(ArrayList<Invitado> l) throws IOException {
    Cell c = new Cell();
    c.setBorder(Border.NO_BORDER);
    c.setFont(PdfFontFactory.createRegisteredFont("times-italic"));
    c.setFontSize(8);/*from ww w  .  j a va 2 s  . co m*/
    c.setTextAlignment(TextAlignment.LEFT);
    for (Invitado in : l) {
        if (LocalDate.parse(in.getFecha())
                .getMonthValue() == (cbmes.getSelectionModel().getSelectedIndex() + 1)) {
            c.add(in.getNombre() + " " + in.getApellido());
        }
    }
    return c;

}

From source file:controller.VisitasController.java

public com.itextpdf.layout.element.Cell generaCeldaInvitados(ArrayList<Invitado> l) throws IOException {
    com.itextpdf.layout.element.Cell c = new com.itextpdf.layout.element.Cell();
    c.setBorder(Border.NO_BORDER);
    c.setFont(PdfFontFactory.createRegisteredFont("times-italic"));
    c.setFontSize(8);//from  ww  w  . j  a  va 2  s  . c o  m
    c.setTextAlignment(TextAlignment.LEFT);
    for (Invitado in : l) {
        if (in.getFecha().equals(date.getValue().format(DateTimeFormatter.ISO_LOCAL_DATE))) {
            c.add(in.getNombre() + " " + in.getApellido());
        }
    }
    return c;

}

From source file:model.PrintPDF.java

public void inThongKeCanBo(ArrayList<CanBo> listCanBo, String pathName, String nam, int gt, String tongNhanVien,
        String soNVVH) {/*w ww  .j a va 2s .  c o  m*/
    PdfWriter pdfWriter = null;
    String gioiTinh = "";
    if (gt == 1) {
        gioiTinh = "n";
    } else {
        gioiTinh = "nam";
    }

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k cn b " + gioiTinh + " nm " + nam + "\n\n").setFont(hfont)
                .setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 2, 4, 3, 4 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("S in thoi").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));

        //  ni dung ca bng thng k
        for (int i = 0; i < listCanBo.size(); i++) {
            table.addCell(new Paragraph((i + 1) + "").setFont(hfont).setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(listCanBo.get(i).getMaCB()).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(listCanBo.get(i).getHoTen()).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(dateFormat.format(listCanBo.get(i).getNgaySinh())).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(listCanBo.get(i).getSDT()).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
        }
        document.add(table);
        document.add(new Paragraph("\n\n Tng s nhn vin            :  " + tongNhanVien).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));
        document.add(new Paragraph(" Tng s nhn vin sp v? hu :  " + tongNhanVien).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));

        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}