Example usage for com.itextpdf.text Image setAbsolutePosition

List of usage examples for com.itextpdf.text Image setAbsolutePosition

Introduction

In this page you can find the example usage for com.itextpdf.text Image setAbsolutePosition.

Prototype


public void setAbsolutePosition(final float absoluteX, final float absoluteY) 

Source Link

Document

Sets the absolute position of the Image.

Usage

From source file:managedbeans.descargas.PDFConversionDemo.java

public static void main(String[] args) {
    try {/*from   w ww .  j  a va  2  s  .c om*/
        //Read file using PdfReader
        PdfReader pdfReader = new PdfReader("HelloWorld.pdf");

        //Modify file using PdfReader
        PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream("HelloWorld-modified.pdf"));

        Image image = Image.getInstance("temp.png");
        image.scaleAbsolute(100, 50);
        image.setAbsolutePosition(100f, 700f);

        for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {
            PdfContentByte content = pdfStamper.getUnderContent(i);
            content.addImage(image);
        }

        pdfStamper.close();

    } catch (IOException | DocumentException e) {
        logger.warn("failed to ...." + e);
    }
}

From source file:Modelo.CotizacionDAO.java

public void writePdf(OutputStream outputStream, Cotizacion x, int idcotizacion) throws Exception {

    DateFormat df = new SimpleDateFormat("dd/MM/YYYY");
    Calendar cdos = Calendar.getInstance();
    Date datediamas = new Date();
    Date dateaniomas = new Date();
    cdos.add(Calendar.DATE, 1);/*from   w w w.  j  av  a  2s  .  c om*/
    datediamas = cdos.getTime();
    String fechadiamas = df.format(datediamas);
    cdos.add(Calendar.YEAR, 1);
    dateaniomas = cdos.getTime();
    String fechavencimiento = df.format(dateaniomas);

    Document document = new Document(PageSize.LETTER, 50, 50, 50, 30);
    Font boldFontTitulo = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD);
    Font boldFontTexto = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD);
    Font FontTexto = new Font(Font.FontFamily.HELVETICA, 10);

    // document.setPageSize(null);
    PdfWriter writer = PdfWriter.getInstance(document, outputStream);

    Image imagen = Image.getInstance("http://54.67.56.185/BSeguros_pa18/img/BSeguroLogo.png");
    //      Image imagen = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\BSeguroLogo.png");
    Image imagen2 = Image.getInstance(
            "http://54.67.56.185/BSeguros_pa18/img/Aseguradoras/" + x.getId_aseguradora() + ".png");
    //Image imagen2 = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\Mapfre.png");

    document.open();

    PdfContentByte canvas = writer.getDirectContent();
    Rectangle rect = new Rectangle(36, 36, 579, 756);
    rect.setBorder(Rectangle.BOX);
    rect.setBorderWidth(2);
    canvas.rectangle(rect);

    document.addTitle("Cotizacion");
    document.addSubject("Cotizacion");
    document.addKeywords("Cotizacion, seguros");
    document.addAuthor("BSeguro");
    document.addCreator("Bseguro");

    imagen.scaleAbsoluteHeight(30f);
    imagen.setAbsolutePosition(45f, 720f);
    imagen2.scaleAbsoluteHeight(30f);
    imagen2.setAbsolutePosition(450f, 720f);
    document.add(imagen);
    document.add(imagen2);

    Paragraph paragraph2 = new Paragraph("DATOS DE TU POLIZA", boldFontTitulo);
    paragraph2.setAlignment(Element.ALIGN_CENTER);
    document.add(paragraph2);

    //creas una tabla con un ancho de 3 celdas, el salto a la siguiente fila sera automatico
    PdfPTable table = new PdfPTable(3);
    table.getDefaultCell().setBorder(0);
    PdfPCell cell;

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

    document.add(new Paragraph(" Datos de tu poliza folio: " + "BC" + x.getId_aseguradora().substring(0, 1)
            + x.getMetododepago().substring(0, 1) + ": 0000" + idcotizacion, boldFontTitulo));
    document.add(new Paragraph(" Vigencia de la poliza del: " + fechadiamas + " al: " + fechavencimiento,
            boldFontTitulo));
    document.add(saltodelinea);

    document.add(new Paragraph(" Datos del Contratante: ", boldFontTitulo));
    //document.add(saltodelinea);

    //agrego otra tabla
    table = new PdfPTable(6);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell(new Paragraph("Nombre: ", boldFontTexto));
    PdfPCell celdaNombre = new PdfPCell(
            new Paragraph(x.getNombre_contratante() + " " + x.getApellido_paterno(), FontTexto));
    celdaNombre.setColspan(5);
    celdaNombre.setBorder(0);
    table.addCell(celdaNombre);
    table.addCell(new Paragraph("RFC : ", boldFontTexto));
    PdfPCell celdaRFC = new PdfPCell(new Paragraph(x.getRfc(), FontTexto));
    celdaRFC.setColspan(5);
    celdaRFC.setBorder(0);
    table.addCell(celdaRFC);
    table.addCell(new Paragraph("Direccion: ", boldFontTexto));
    PdfPCell celdaDir = new PdfPCell(
            new Paragraph(x.getCall() + ", " + x.getNo_ext() + ", " + x.getNo_int() + ", " + x.getColonia()
                    + ", " + x.getDelegacion() + ", " + x.getEstado() + ", " + x.getCp(), FontTexto));
    celdaDir.setColspan(5);
    celdaDir.setBorder(0);
    table.addCell(celdaDir);
    table.addCell(new Paragraph("Email: ", boldFontTexto));
    table.addCell(AddCell(x.getMail(), 5));
    table.addCell(new Paragraph("Telefono ", boldFontTexto));
    PdfPCell celdaTel = new PdfPCell(new Paragraph(x.getTelefono(), FontTexto));
    celdaTel.setColspan(5);
    celdaTel.setBorder(0);
    table.addCell(celdaTel);

    document.add(table);
    document.add(saltodelinea);

    document.add(new Paragraph(" Datos del Vehiculo: ", boldFontTitulo));
    //      document.add(saltodelinea);

    //agrego otra tabla
    table = new PdfPTable(6);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell(new Paragraph("Marca: ", boldFontTexto));
    table.addCell(AddCell(x.getId_marca(), 5));
    table.addCell(new Paragraph("Modelo:", boldFontTexto));
    table.addCell(AddCell(x.getId_anio().toString(), 5));
    table.addCell(new Paragraph("Tipo: ", boldFontTexto));
    table.addCell(AddCell(x.getId_submarca(), 5));
    table.addCell(new Paragraph("Version:  ", boldFontTexto));
    table.addCell(AddCell(x.getId_modelo(), 5));
    table.addCell(new Paragraph("No. De Serie: ", boldFontTexto));
    table.addCell(AddCell(x.getSerie(), 5));

    document.add(table);
    document.add(saltodelinea);

    document.add(new Paragraph(" Informacion de la Poliza: ", boldFontTitulo));
    //    document.add(saltodelinea);

    //agrego otra tabla
    table = new PdfPTable(6);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell(new Paragraph("Pago: ", boldFontTexto));
    table.addCell(AddCell(x.getTipo_pago(), 5));
    table.addCell(new Paragraph("Aseguradora: ", boldFontTexto));
    table.addCell(AddCell(x.getId_aseguradora(), 5));

    document.add(table);
    document.add(saltodelinea);

    document.add(new Paragraph(" Detalles de la Cobertura: Cobertura Amplia ", boldFontTitulo));
    //  document.add(saltodelinea);

    //agrego otra tabla
    table = new PdfPTable(3);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell(new Paragraph("Cobertura ", boldFontTexto));
    table.addCell(new Paragraph("Responsabilidad Civil", boldFontTexto));
    table.addCell(new Paragraph("Deducible ", boldFontTexto));
    table.addCell(new Paragraph("Daos Materiales", FontTexto));
    table.addCell(new Paragraph("Valor Comercial", FontTexto));
    table.addCell(new Paragraph("5%", FontTexto));
    table.addCell(new Paragraph("Robo Total", FontTexto));
    table.addCell(new Paragraph("Valor Comercial", FontTexto));
    table.addCell(new Paragraph("10%", FontTexto));
    table.addCell(new Paragraph("Responsabilidad Civil", FontTexto));
    table.addCell(new Paragraph("$4,000,000.00", FontTexto));
    table.addCell(new Paragraph("", FontTexto));
    table.addCell(new Paragraph("Gastos Medicos Ocupantes", FontTexto));
    table.addCell(new Paragraph("$500,000.00", FontTexto));
    table.addCell(new Paragraph("", FontTexto));
    table.addCell(new Paragraph("Asistencia Legal", FontTexto));
    table.addCell(new Paragraph("Amparada", FontTexto));
    table.addCell(new Paragraph("", FontTexto));
    table.addCell(new Paragraph("Asistencia Vial", FontTexto));
    table.addCell(new Paragraph("Amparada", FontTexto));
    table.addCell(new Paragraph("", FontTexto));

    document.add(table);
    document.add(saltodelinea);

    document.add(new Paragraph(" Informacion del Pago ", boldFontTitulo));
    document.add(new Paragraph(" Instrumento de Pago: " + x.getMetododepago(), boldFontTexto));

    //agrego otra tabla
    table = new PdfPTable(6);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell(AddCell("Concepto ", 2));
    table.addCell(AddCell("Monto", 4));
    table.addCell(AddCell("Prima Total ", 2));
    table.addCell(AddCell(x.getMonto(), 4));
    table.addCell(AddCell("Prima Inicial", 2));
    table.addCell(AddCell(x.getMonto(), 4));
    table.addCell(AddCell("Pago Subsecuente ", 2));
    table.addCell(AddCell("0", 4));

    document.add(table);
    document.add(saltodelinea);

    if (x.getCobertura_auto_siempre() == true) {

        document.add(new Paragraph(" Informacion de Modulos HDI ", boldFontTitulo));
        table = new PdfPTable(6);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(0);
        table.addCell(AddCell("Modulos ", 2));
        table.addCell(AddCell("Contratados", 4));
        table.addCell(AddCell("HDI - Autos por Siempre ", 2));
        table.addCell(AddCell("$ 1,799.00", 4));
        document.add(table);

    } else {
        if (x.getCobertura_auto_amante() == true) {

            document.add(new Paragraph(" Informacion de Modulos HDI ", boldFontTitulo));
            table = new PdfPTable(6);
            table.setWidthPercentage(100);
            table.getDefaultCell().setBorder(0);
            table.addCell(AddCell("Modulos ", 2));
            table.addCell(AddCell("Contratados", 4));
            table.addCell(AddCell("HDI - Amante de los Autos ", 2));
            table.addCell(AddCell("$ 1,799.00", 4));
            document.add(table);

        } else {

        }
        document.add(saltodelinea);
    }
    document.add(new Paragraph("* Estaras asegurado a partir de las 12 horas del siguiente dia habil.",
            boldFontTexto));

    document.close();

}

From source file:Modelo.DAO.InformeDAO.java

public String generaPDF(String Diagnostico, String Tratamiento, String Datos, Integer idPaciente,
        Integer idPersona, Paciente paciente) throws FileNotFoundException, DocumentException, IOException {

    Calendar cal = Calendar.getInstance();
    String time = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(cal.getTime());
    String timename = new SimpleDateFormat("yyyyMMddHHmm").format(cal.getTime());

    File file = new File("informe" + timename + ".pdf");
    FileOutputStream fileout = new FileOutputStream(file);
    Document document = new Document();
    PdfWriter writer;//from   w w  w.j  ava2 s.c  om
    writer = PdfWriter.getInstance(document, fileout);

    Font fuente = new Font();
    Font fuente2 = new Font();
    Font fuente3 = new Font();

    // fuente.setColor(BaseColor.BLUE);
    fuente.setStyle(Font.UNDERLINE | Font.BOLDITALIC);
    fuente2.setStyle(Font.BOLD);
    fuente2.setSize(12);
    fuente3.setSize(20);
    fuente3.setStyle(Font.BOLD);

    document.open();
    document.add(new Paragraph("\n \n \n \n \n"));
    document.add(new Paragraph("Clnica Mdica INFTEL", fuente3));

    String imageUrl = "src/Imagen/logo.png";
    //  String imagen="src\Imagen\logo.png"; 
    Image image = Image.getInstance(imageUrl);
    image.setAbsolutePosition(300, 750);
    image.scalePercent(80f);
    document.add(image);

    document.add(new Paragraph(" "));
    document.add(new Paragraph("---------------------"));

    document.add(new Paragraph("DATOS DEL PACIENTE", fuente));
    document.add(new Paragraph(" "));
    document.add(
            new Paragraph("Apellidos y Nombre : " + paciente.getApellidos() + ", " + paciente.getNombre()));
    document.add(new Paragraph("NIF : " + paciente.getNif()));
    document.add(new Paragraph("NSS : " + paciente.getNumSS()));
    document.add(new Paragraph("Direccion : " + paciente.getDireccion()));
    document.add(new Paragraph("Telefono : " + paciente.getTelefono()));
    document.add(new Paragraph("Email : " + paciente.getEmail()));
    document.add(new Paragraph("ID Paciente : " + idPaciente));

    document.add(new Paragraph(" "));
    document.add(new Paragraph("---------------------"));
    document.add(new Paragraph(" "));

    document.add(new Paragraph("DATOS CL?NICOS", fuente));
    document.add(new Paragraph(" "));

    document.add(new Paragraph("Diagnstico : ", fuente2));
    document.add(new Paragraph(Diagnostico));
    document.add(new Paragraph(" "));

    document.add(new Paragraph("Tratamiento : ", fuente2));
    document.add(new Paragraph(Tratamiento));
    document.add(new Paragraph(" "));

    document.add(new Paragraph("Datos : ", fuente2));
    document.add(new Paragraph(Datos));
    document.add(new Paragraph(" "));

    absText(writer, time, 450, 50);

    document.close();

    File myFile = new File("informe" + timename + ".pdf");
    Desktop.getDesktop().open(myFile);

    return myFile.toString();

}

From source file:Modelo.DAO.RecetasDAO.java

public void generaPDF(String Indicaciones, String Medicamentos, Paciente paciente, Integer idPaciente)
        throws FileNotFoundException, DocumentException, IOException {

    Calendar cal = Calendar.getInstance();
    String time = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(cal.getTime());
    String timename = new SimpleDateFormat("yyyyMMddHHmm").format(cal.getTime());

    File file = new File("Receta" + timename + ".pdf");
    FileOutputStream fileout = new FileOutputStream(file);
    Document document = new Document();
    PdfWriter writer;//from   ww  w.j a  v a  2s  . com
    writer = PdfWriter.getInstance(document, fileout);

    Font fuente = new Font();
    Font fuente2 = new Font();

    // fuente.setColor(BaseColor.BLUE);
    fuente.setStyle(Font.BOLD | Font.UNDERLINE);
    fuente2.setStyle(Font.BOLD);
    fuente2.setSize(20);

    document.open();
    document.add(new Paragraph("\n \n \n \n \n"));
    document.add(new Paragraph("Clinica Mdica INFTEL", fuente2));

    String imageUrl = "src/Imagen/logo.png";

    Image image = Image.getInstance(imageUrl);
    image.setAbsolutePosition(300, 750);
    image.scalePercent(80f);
    document.add(image);

    document.add(new Paragraph(" "));
    document.add(new Paragraph("---------------------"));

    document.add(new Paragraph("DATOS DEL PACIENTE", fuente));
    document.add(new Paragraph(" "));
    document.add(
            new Paragraph("Apellidos y Nombre : " + paciente.getApellidos() + ", " + paciente.getNombre()));
    document.add(new Paragraph("NIF : " + paciente.getNif()));
    document.add(new Paragraph("NSS : " + paciente.getNumSS()));
    document.add(new Paragraph("Direccion : " + paciente.getDireccion()));
    document.add(new Paragraph("Telefono : " + paciente.getTelefono()));
    document.add(new Paragraph("Email : " + paciente.getEmail()));
    document.add(new Paragraph("ID Paciente : " + idPaciente));

    document.add(new Paragraph(" "));
    document.add(new Paragraph("---------------------"));
    document.add(new Paragraph(" "));

    document.add(new Paragraph("DATOS CL?NICOS", fuente));
    document.add(new Paragraph(" "));

    document.add(new Paragraph("Diagnstico : "));
    document.add(new Paragraph(Indicaciones));
    document.add(new Paragraph(" "));

    document.add(new Paragraph("Tratamiento : "));
    document.add(new Paragraph(Medicamentos));
    document.add(new Paragraph(" "));

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

    absText(writer, time, 450, 50);

    document.close();
}

From source file:mvjce.PDF.java

public static void create(int sino) {// sino = SI.No
    // TODO code application logic here
    try {//from  www.  j  ava 2s .c  o m
        //Create Document instance.
        Document document = new Document();

        //Create OutputStream instance.
        OutputStream outputStream = new FileOutputStream(
                new File("/home/narein/NetBeansProjects/" + sem + cl + "/" + usn + ".pdf"));

        //Create PDFWriter instance.
        PdfWriter.getInstance(document, outputStream);

        //Open the document.
        document.open();
        //image position
        Image imageCenter = Image.getInstance("/home/narein/Downloads/mvj.png");
        //imageCenter.setAlignment(Image.MIDDLE);
        imageCenter.setAbsolutePosition(235, 780);
        imageCenter.scaleAbsolute(146f, 53f);
        //Permanently affiliated para
        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.addCell(getCell(
                "\n\n\nPermanently affiliated to VTU, Govt. of Karnataka\nApproved by AICTE, New Delhi\nNear ITPB, Bengaluru- 560067\n\n"
                        + hod_name + ", HOD - " + dep,
                PdfPCell.ALIGN_LEFT));
        table.addCell(getCell("\n\n\n\nPh: 080-42991000\nFax: 080-28452443\nWebsite: www.mvjce.edu.in\nEmail: "
                + hod_email + "\n\n", PdfPCell.ALIGN_RIGHT));
        //line across pdf
        final LineSeparator lineSeparator = new LineSeparator();
        Chunk linebreak = new Chunk(lineSeparator);
        Phrase p = new Phrase("\nPROGRESS REPORT\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD));
        Paragraph para = new Paragraph(p);
        para.setAlignment(Element.ALIGN_CENTER);
        Chunk glue = new Chunk(new VerticalPositionMark());
        Paragraph p1 = new Paragraph("\nRef:", new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        p1.add(new Chunk(glue));
        //get current date
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yyyy");
        LocalDate localDate = LocalDate.now();
        //add date to pdf
        p1.add(new Phrase("Date: " + dtf.format(localDate) + "\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
        Phrase dear_prnts = new Phrase("Dear Parents,\n", new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        Phrase The_acad = new Phrase(
                "                  The academic performance of your ward Mr/Ms " + name + " of Semester " + sem
                        + " bearing the USN " + usn + " is as follows,\n\n",
                new Font(FontFamily.TIMES_ROMAN, 9));
        Phrase Rem = new Phrase("Remarks\n", new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD));
        Phrase your_ward = new Phrase(
                "\nYour ward's overall performance is Good / Satisfactory / Poor / Very Poor\n",
                new Font(FontFamily.TIMES_ROMAN, 9));
        Phrase you_are = new Phrase("\nYou are requested to:\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        Phrase req = new Phrase("");
        Paragraph para2 = new Paragraph(
                "1) Advice your ward to attend classes regularly\n2) Note that he/she may likely be detainedfrom appearing for examinations\n"
                        + "3) Advice your ward to improve in Test/Exam performance particularly in subject\n4) Meet the Head of the Department\n5) Meet the principal\n",
                new Font(FontFamily.TIMES_ROMAN, 9));
        Chunk glue1 = new Chunk(new VerticalPositionMark());
        Paragraph p3 = new Paragraph("\nSIGNATURE:\n\nNAME OF PROCTOR:\n\nCONTACT NUMBER:",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        p3.add(new Chunk(glue1));
        p3.add(new Phrase(
                "SIGNATURE OF HOD\n\n            Kindly attend the Parent Teacher Meeting to be held on the date informed to your ward.\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
        Phrase Note = new Phrase("\nNOTE:", new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD));
        Paragraph p4 = new Paragraph();
        p4.add(Note);
        p4.add(new Phrase(
                "  Parents are requested to contact the proctor (By Email/Letter/Phone) and confirm receipt of this feedback. Parents are also"
                        + "welcome to interact with proctors/subject faculty/ HOD for any discussion/clarification.\n",
                new Font(FontFamily.TIMES_ROMAN, 9)));
        //Add content to the document.
        document.add(imageCenter);
        document.add(table);
        document.add(linebreak);
        document.add(para);
        document.add(p1);
        document.add(dear_prnts);
        document.add(The_acad);
        document.add(createinternalsTable());
        if (internal.equals("1")) {
            document.add(new Phrase("\nPREVIOUS SEMESTER VTU RESULT\n\n",
                    new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD)));
            document.add(createexternalTable());
        }
        document.add(Rem);
        document.add(your_ward);
        document.add(you_are);
        document.add(para2);
        document.add(p3);
        document.add(p4);
        //document.add(paragraph);document.add(paragraph1);

        //Close document and outputStream.
        document.close();
        outputStream.close();

        System.out.println("Pdf created successfully.");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Operaciones.ResponsablesOP.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);/*from   www. j av  a  2 s.c  o m*/

    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        Orden ord = (Orden) session.get(Orden.class, Integer.parseInt(t_orden.getText()));
        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        Date fecha = new Date();
        Date fecha1 = new Date();
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
        String valor = dateFormat.format(fecha);

        File folder = new File("reportes/" + ord.getIdOrden());
        folder.mkdirs();
        PdfReader reader = new PdfReader("imagenes/PlantillaHojaAsignacion.pdf");
        PdfStamper stamp = new PdfStamper(reader,
                new FileOutputStream("reportes/" + ord.getIdOrden() + "/" + valor + "-HojaAsignacion.pdf"));
        PdfContentByte cb = stamp.getUnderContent(1);
        AcroFields fdfDoc = stamp.getAcroFields();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);

        cb.beginText();
        fdfDoc.setField("orden", String.valueOf(ord.getIdOrden()));

        if (ord.getCompania() != null)
            fdfDoc.setField("compania", ord.getCompania().getNombre());
        else
            fdfDoc.setField("compania", "");

        if (ord.getSiniestro() != null)
            fdfDoc.setField("siniestro", ord.getSiniestro());
        else
            fdfDoc.setField("siniestro", "");

        if (ord.getPoliza() != null)
            fdfDoc.setField("poliza", ord.getPoliza());
        else
            fdfDoc.setField("poliza", "");
        if (ord.getFecha() != null)
            fdfDoc.setField("apertura", ord.getFecha().toString());
        else
            fdfDoc.setField("apertura", "");
        if (ord.getFechaSiniestro() != null)
            fdfDoc.setField("f_siniestro", ord.getFechaSiniestro().toString());
        else
            fdfDoc.setField("f_siniestro", "");
        if (ord.getInciso() != null)
            fdfDoc.setField("inciso", ord.getInciso());
        else
            fdfDoc.setField("inciso", "");

        if (ord.getTipo() != null)
            fdfDoc.setField("unidad", ord.getTipo().getTipoNombre());
        else
            fdfDoc.setField("unidad", "");
        if (ord.getModelo() != null)
            fdfDoc.setField("modelo", ord.getModelo().toString());
        else
            fdfDoc.setField("modelo", "");
        if (ord.getMarca() != null)
            fdfDoc.setField("marca", ord.getMarca().getMarcaNombre());
        else
            fdfDoc.setField("marca", "");
        if (ord.getNoEconomico() != null)
            fdfDoc.setField("economico", ord.getNoEconomico());
        else
            fdfDoc.setField("economico", "");
        if (ord.getNoMotor() != null)
            fdfDoc.setField("no_motor", ord.getNoMotor());
        else
            fdfDoc.setField("no_motor", "");
        if (ord.getNoSerie() != null)
            fdfDoc.setField("no_serie", ord.getNoSerie());
        else
            fdfDoc.setField("no_serie", "");

        //tabla 
        if (ord.getEmpleadoByRHojalateria() != null)
            fdfDoc.setField("HOJALATERIA", ord.getEmpleadoByRHojalateria().getIdEmpleado().toString());
        else
            fdfDoc.setField("HOJALATERIA", "");
        if (ord.getEmpleadoByRHojalateria() != null)
            fdfDoc.setField("R_H", ord.getEmpleadoByRHojalateria().getNombre().toString());
        else
            fdfDoc.setField("R_H", "");

        if (ord.getEmpleadoByRMecanica() != null)
            fdfDoc.setField("MECANICA", ord.getEmpleadoByRMecanica().getIdEmpleado().toString());
        else
            fdfDoc.setField("MECANICA", "");
        if (ord.getEmpleadoByRMecanica() != null)
            fdfDoc.setField("R_M", ord.getEmpleadoByRMecanica().getNombre().toString());
        else
            fdfDoc.setField("R_M", "");

        if (ord.getEmpleadoByRSuspension() != null)
            fdfDoc.setField("SUSPENSIN", ord.getEmpleadoByRSuspension().getIdEmpleado().toString());
        else
            fdfDoc.setField("SUSPENSIN", "");
        if (ord.getEmpleadoByRSuspension() != null)
            fdfDoc.setField("R_S", ord.getEmpleadoByRSuspension().getNombre().toString());
        else
            fdfDoc.setField("R_S", "");

        if (ord.getEmpleadoByRElectrico() != null)
            fdfDoc.setField("ELECTRICO", ord.getEmpleadoByRElectrico().getIdEmpleado().toString());
        else
            fdfDoc.setField("ELECTRICO", "");

        if (ord.getEmpleadoByRElectrico() != null)
            fdfDoc.setField("R_E", ord.getEmpleadoByRElectrico().getNombre().toString());
        else
            fdfDoc.setField("R_E", "");

        if (ord.getEmpleadoByRPintura() != null)
            fdfDoc.setField("PINTURA", ord.getEmpleadoByRPintura().getIdEmpleado().toString());
        else
            fdfDoc.setField("PINTURA", "");
        if (ord.getEmpleadoByRPintura() != null)
            fdfDoc.setField("R_P", ord.getEmpleadoByRPintura().getNombre().toString());
        else
            fdfDoc.setField("R_P", "");

        //FECHAS
        String valor1 = "";
        if (ord.getRHojalateriaFecha() != null) {
            fecha1 = ord.getRHojalateriaFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_H", valor1);
        } else {
            fdfDoc.setField("F_H", valor1);
        }
        if (ord.getRMecanicaFecha() != null) {
            fecha1 = ord.getRMecanicaFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_M", valor1);
        } else {
            fdfDoc.setField("F_M", valor1);
        }
        if (ord.getRSuspensionFecha() != null) {
            fecha1 = ord.getRSuspensionFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_S", valor1);
        } else {
            fdfDoc.setField("F_S", valor1);
        }
        if (ord.getRElectricoFecha() != null) {
            fecha1 = ord.getRElectricoFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_E", valor1);
        } else {
            fdfDoc.setField("F_E", valor1);
        }
        if (ord.getRPinturaFecha() != null) {
            fecha1 = ord.getRPinturaFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_P", valor1);
        } else {
            fdfDoc.setField("F_P", valor1);
        }
        //ASIGNO OPERARIO
        if (ord.getUsuarioByRHojalateriaAsigno() != null)
            fdfDoc.setField("A_H", ord.getUsuarioByRHojalateriaAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_H", "");

        if (ord.getUsuarioByRMecanicaAsigno() != null)
            fdfDoc.setField("A_M", ord.getUsuarioByRMecanicaAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_M", "");
        if (ord.getUsuarioByRSuspensionAsigno() != null)
            fdfDoc.setField("A_S", ord.getUsuarioByRSuspensionAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_S", "");
        if (ord.getUsuarioByRElectricoAsigno() != null)
            fdfDoc.setField("A_E", ord.getUsuarioByRElectricoAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_E", "");

        if (ord.getUsuarioByRPinturaAsigno() != null)
            fdfDoc.setField("A_P", ord.getUsuarioByRPinturaAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_P", "");
        //LIMITE
        if (ord.getHojalateriaLimite() != null) {
            fecha1 = ord.getHojalateriaLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_H_L", valor1);
        } else {
            fdfDoc.setField("F_H_L", "");
        }
        if (ord.getMecanicaLimite() != null) {
            fecha1 = ord.getMecanicaLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_M_L", valor1);
        } else {
            fdfDoc.setField("F_M_L", "");
        }
        if (ord.getSuspensionLimite() != null) {
            fecha1 = ord.getSuspensionLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_S_L", valor1);
        } else {
            fdfDoc.setField("F_S_L", "");
        }
        if (ord.getElectricoLimite() != null) {
            fecha1 = ord.getElectricoLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_E_L", valor1);
        } else {
            fdfDoc.setField("F_E_L", "");
        }
        if (ord.getPinturaLimite() != null) {
            fecha1 = ord.getPinturaLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_P_L", valor1);
        } else {
            fdfDoc.setField("F_P_L", "");
        }

        Foto[] fotos = (Foto[]) ord.getFotos().toArray(new Foto[0]);
        for (int k = 0; k < fotos.length - 1; k++) {
            for (int f = 0; f < (fotos.length - 1) - k; f++) {
                if (fotos[f].getFecha().after(fotos[f + 1].getFecha()) == true) {
                    Foto aux;
                    aux = fotos[f];
                    fotos[f] = fotos[f + 1];
                    fotos[f + 1] = aux;
                }
            }
        }
        if (fotos.length > 0) {
            try {
                Image img;
                img = Image
                        .getInstance("ordenes/" + ord.getIdOrden() + "/miniatura/" + fotos[0].getDescripcion());
                img.setAbsolutePosition(30, 495);
                img.scaleAbsoluteWidth(124);
                img.scaleAbsoluteHeight(80);
                cb.addImage(img, true);
            } catch (Exception e) {
                //e.printStackTrace();
            }
        } else {
        }

        cb.endText();
        stamp.close();

        PDF reporte = new PDF();
        reporte.cerrar();
        reporte.visualizar("reportes/" + ord.getIdOrden() + "/" + valor + "-HojaAsignacion.pdf");
    } catch (Exception e) {
        System.out.println(e);
        JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto");
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}

From source file:org.alfresco.extension.pdftoolkit.repo.action.executer.PDFWatermarkActionExecuter.java

License:Apache License

/**
 * Applies an image watermark// ww w.ja va 2  s  .co m
 * 
 * @param reader
 * @param writer
 * @param options
 * @throws Exception
 */
private void imageAction(Action ruleAction, NodeRef actionedUponNodeRef, NodeRef watermarkNodeRef,
        ContentReader actionedUponContentReader, ContentReader watermarkContentReader,
        Map<String, Object> options) {

    PdfStamper stamp = null;
    File tempDir = null;
    ContentWriter writer = null;

    try {
        // get a temp file to stash the watermarked PDF in before moving to
        // repo
        File alfTempDir = TempFileProvider.getTempDir();
        tempDir = new File(alfTempDir.getPath() + File.separatorChar + actionedUponNodeRef.getId());
        tempDir.mkdir();
        File file = new File(tempDir,
                serviceRegistry.getFileFolderService().getFileInfo(actionedUponNodeRef).getName());

        // get the PDF input stream and create a reader for iText
        PdfReader reader = new PdfReader(actionedUponContentReader.getContentInputStream());
        stamp = new PdfStamper(reader, new FileOutputStream(file));
        PdfContentByte pcb;

        // get a com.itextpdf.text.Image object via java.imageio.ImageIO
        Image img = Image.getInstance(ImageIO.read(watermarkContentReader.getContentInputStream()), null);

        // get the PDF pages and position
        String pages = (String) options.get(PARAM_PAGE);
        String position = (String) options.get(PARAM_POSITION);
        String depth = (String) options.get(PARAM_WATERMARK_DEPTH);

        // image requires absolute positioning or an exception will be
        // thrown
        // set image position according to parameter. Use
        // PdfReader.getPageSizeWithRotation
        // to get the canvas size for alignment.
        img.setAbsolutePosition(100f, 100f);

        // stamp each page
        int numpages = reader.getNumberOfPages();
        for (int i = 1; i <= numpages; i++) {
            Rectangle r = reader.getPageSizeWithRotation(i);
            // set stamp position
            if (position.equals(POSITION_BOTTOMLEFT)) {
                img.setAbsolutePosition(0, 0);
            } else if (position.equals(POSITION_BOTTOMRIGHT)) {
                img.setAbsolutePosition(r.getWidth() - img.getWidth(), 0);
            } else if (position.equals(POSITION_TOPLEFT)) {
                img.setAbsolutePosition(0, r.getHeight() - img.getHeight());
            } else if (position.equals(POSITION_TOPRIGHT)) {
                img.setAbsolutePosition(r.getWidth() - img.getWidth(), r.getHeight() - img.getHeight());
            } else if (position.equals(POSITION_CENTER)) {
                img.setAbsolutePosition(getCenterX(r, img), getCenterY(r, img));
            }

            // if this is an under-text stamp, use getUnderContent.
            // if this is an over-text stamp, usse getOverContent.
            if (depth.equals(DEPTH_OVER)) {
                pcb = stamp.getOverContent(i);
            } else {
                pcb = stamp.getUnderContent(i);
            }

            // only apply stamp to requested pages
            if (checkPage(pages, i, numpages)) {
                pcb.addImage(img);
            }
        }

        stamp.close();

        // Get a writer and prep it for putting it back into the repo
        //can't use BasePDFActionExecuter.getWriter here need the nodeRef of the destination
        NodeRef destinationNode = createDestinationNode(file.getName(),
                (NodeRef) ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER), actionedUponNodeRef);
        writer = serviceRegistry.getContentService().getWriter(destinationNode, ContentModel.PROP_CONTENT,
                true);

        writer.setEncoding(actionedUponContentReader.getEncoding());
        writer.setMimetype(FILE_MIMETYPE);

        // Put it in the repo
        writer.putContent(file);

        // delete the temp file
        file.delete();
    } catch (IOException e) {
        throw new AlfrescoRuntimeException(e.getMessage(), e);
    } catch (DocumentException e) {
        throw new AlfrescoRuntimeException(e.getMessage(), e);
    } finally {
        if (tempDir != null) {
            try {
                tempDir.delete();
            } catch (Exception ex) {
                throw new AlfrescoRuntimeException(ex.getMessage(), ex);
            }
        }

        if (stamp != null) {
            try {
                stamp.close();
            } catch (Exception ex) {
                throw new AlfrescoRuntimeException(ex.getMessage(), ex);
            }
        }
    }
}

From source file:org.dspace.disseminate.CitationDocument.java

/**
 * Attempts to add a Logo to the document from the given resource. Returns
 * true on success and false on failure.
 *
 * @param doc The document to add the logo to. (Added to the top right
 * corner of the first page.//from  w  w w .j av a  2s .  co m
 * @param writer The writer associated with the given Document.
 * @param res The resource/path to the logo file. This file can be any of
 * the following formats:
 *  GIF, PNG, JPEG, PDF
 *
 * @return Succesfully added logo to document.
 */
private boolean addLogoToDocument(Document doc, PdfWriter writer, String res) {
    boolean ret = false;
    try {
        //First we try to get the logo as if it is a Java Resource
        URL logoURL = this.getClass().getResource(res);
        log.debug(res + " -> " + logoURL.toString());
        if (logoURL == null) {
            logoURL = new URL(res);
        }

        if (logoURL != null) {
            String mtype = URLConnection.guessContentTypeFromStream(logoURL.openStream());
            if (mtype == null) {
                mtype = URLConnection.guessContentTypeFromName(res);
            }
            log.debug("Determined MIMETYPE of logo: " + mtype);
            if (PDF_MIMES.contains(mtype)) {
                //Handle pdf logos.
                PdfReader reader = new PdfReader(logoURL);
                PdfImportedPage logoPage = writer.getImportedPage(reader, 1);
                Image logo = Image.getInstance(logoPage);
                float x = doc.getPageSize().getWidth() - doc.rightMargin() - logo.getScaledWidth();
                float y = doc.getPageSize().getHeight() - doc.topMargin() - logo.getScaledHeight();
                logo.setAbsolutePosition(x, y);
                doc.add(logo);
                ret = true;
            } else if (RASTER_MIMES.contains(mtype)) {
                //Use iText's Image class
                Image logo = Image.getInstance(logoURL);

                //Determine the position of the logo (upper-right corner) and
                //place it there.
                float x = doc.getPageSize().getWidth() - doc.rightMargin() - logo.getScaledWidth();
                float y = doc.getPageSize().getHeight() - doc.topMargin() - logo.getScaledHeight();
                logo.setAbsolutePosition(x, y);
                writer.getDirectContent().addImage(logo);
                ret = true;
            } else if (SVG_MIMES.contains(mtype)) {
                //Handle SVG Logos
                log.error("SVG Logos are not supported yet.");
            } else {
                //Cannot use other mimetypes
                log.debug("Logo MIMETYPE is not supported.");
            }
        } else {
            log.debug("Could not create URL to Logo resource: " + res);
        }
    } catch (Exception e) {
        log.error("Could not add logo (" + res + ") to cited document: " + e.getMessage());
        ret = false;
    }
    return ret;
}

From source file:org.durel.mydooble.ImageItem.java

License:Open Source License

@Override
public void toPDF(PDF out, int i) {
    super.toPDF(out, i);

    try {/*w  w w  . jav a 2 s. c o m*/
        Image img = Image.getInstance(image);
        img.setDpi(288, 288);
        img.setInterpolation(true);
        float ih = (float) (img.getHeight());
        float iw = (float) (img.getWidth());
        if (ih > h || iw > w) {
            float xratio = iw / w;
            float yratio = ih / h;
            float ratio = Math.max(xratio, yratio);
            log.info("ih: " + ih + " - iw: " + iw + " - xratio: " + xratio + " - yratio: " + yratio
                    + " - ratio: " + ratio + " --> " + (int) (iw / ratio) + "x" + (int) (ih / ratio));
            img.scalePercent(100 / ratio);
        }

        PdfContentByte cb = out.writer.getDirectContent();
        float x = bx + (c * (w + m)) + m;
        float y = by + (r * (h + m)) + m;
        img.setAbsolutePosition(x, y);
        cb.addImage(img);
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.jaqpot.core.service.data.ReportService.java

public void report2PDF(Report report, OutputStream os) {

    Document document = new Document();
    document.setPageSize(PageSize.A4);//from   ww w.j  av  a  2  s.c om
    document.setMargins(50, 45, 80, 40);
    document.setMarginMirroring(false);

    try {
        PdfWriter writer = PdfWriter.getInstance(document, os);
        TableHeader event = new TableHeader();
        writer.setPageEvent(event);

    } catch (DocumentException ex) {
        throw new InternalServerErrorException(ex);
    }

    document.open();

    /** setup fonts for pdf */
    Font ffont = new Font(Font.FontFamily.UNDEFINED, 9, Font.ITALIC);
    Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC);
    Font paragraphFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    Font tableFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);

    /** print link to jaqpot*/
    Chunk chunk = new Chunk(
            "This report has been automatically created by the JaqpotQuatro report service. Click here to navigate to our official webpage",
            ffont);
    chunk.setAnchor("http://www.jaqpot.org");

    Paragraph paragraph = new Paragraph(chunk);
    paragraph.add(Chunk.NEWLINE);

    Chapter chapter = new Chapter(paragraph, 1);
    chapter.setNumberDepth(0);

    /** get title */
    String title = null;
    if (report.getMeta() != null && report.getMeta().getTitles() != null
            && !report.getMeta().getTitles().isEmpty())
        title = report.getMeta().getTitles().iterator().next();

    /** print title aligned centered in page */
    if (title == null)
        title = "Report";
    chunk = new Chunk(title, chapterFont);
    paragraph = new Paragraph(chunk);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.add(Chunk.NEWLINE);
    paragraph.add(Chunk.NEWLINE);

    chapter.add(paragraph);

    /** report Description */
    if (report.getMeta() != null && report.getMeta().getDescriptions() != null
            && !report.getMeta().getDescriptions().isEmpty()
            && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) {
        paragraph = new Paragraph();
        paragraph.add(new Chunk("Description: ", paragraphFontBold));
        paragraph.add(new Chunk(report.getMeta().getDescriptions().toString().replaceAll(":http", ": http"),
                paragraphFont));
        chapter.add(paragraph);
        chapter.add(Chunk.NEWLINE);
    }

    /** report model, algorithm and/or dataset id */
    if (report.getMeta() != null && report.getMeta().getHasSources() != null
            && !report.getMeta().getHasSources().isEmpty() && !report.getMeta().getDescriptions().isEmpty()
            && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) {
        Iterator<String> sources = report.getMeta().getHasSources().iterator();
        sources.forEachRemaining(o -> {
            if (o != null) {
                String[] source = o.split("/");
                if (source[source.length - 2].trim().equals("model")
                        || source[source.length - 2].trim().equals("algorithm")
                        || source[source.length - 2].trim().equals("dataset")) {
                    Paragraph paragraph1 = new Paragraph();
                    paragraph1.add(new Chunk(source[source.length - 2].substring(0, 1).toUpperCase()
                            + source[source.length - 2].substring(1) + ": ", paragraphFontBold));
                    paragraph1.add(new Chunk(source[source.length - 1], paragraphFont));
                    chapter.add(paragraph1);
                    chapter.add(Chunk.NEWLINE);
                }
            }
        });
    }

    /** report single calculations */
    report.getSingleCalculations().forEach((key, value) -> {
        Paragraph paragraph1 = new Paragraph();
        paragraph1 = new Paragraph();
        paragraph1.add(new Chunk(key + ": ", paragraphFontBold));
        paragraph1.add(new Chunk(value.toString().trim().replaceAll(" +", " "), paragraphFont));
        chapter.add(paragraph1);
        chapter.add(Chunk.NEWLINE);
    });

    /** report date of completion */
    if (report.getMeta() != null && report.getMeta().getDate() != null) {
        Paragraph paragraph1 = new Paragraph();
        paragraph1.add(new Chunk("Procedure completed on: ", paragraphFontBold));
        paragraph1.add(new Chunk(report.getMeta().getDate().toString(), paragraphFont));
        chapter.add(paragraph1);
        chapter.add(Chunk.NEWLINE);
    }

    try {
        document.add(chapter);
    } catch (DocumentException ex) {
        throw new InternalServerErrorException(ex);
    }

    Integer chapterNumber = 0;

    /** report all_data */
    for (Entry<String, ArrayCalculation> entry : report.getArrayCalculations().entrySet()) {
        String label = entry.getKey();
        ArrayCalculation ac = entry.getValue();
        PdfPTable table = new PdfPTable(ac.getColNames().size() + 1);
        for (Entry<String, List<Object>> row : ac.getValues().entrySet()) {

            try {
                XMLWorkerHelper.getInstance().parseXHtml(w -> {
                    if (w instanceof WritableElement) {
                        List<Element> elements = ((WritableElement) w).elements();
                        for (Element element : elements) {
                            PdfPCell pdfCell = new PdfPCell();
                            pdfCell.addElement(element);
                            table.addCell(pdfCell);
                        }
                    }
                }, new StringReader(row.getKey()));
            } catch (IOException e) {
                e.printStackTrace();
            }

            for (Object o : row.getValue()) {
                table.addCell(o.toString());
            }
            table.completeRow();
        }
        try {
            Chunk tableChunk = new Chunk(label, tableFont);
            Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber);
            tableChapter.add(Chunk.NEWLINE);
            tableChapter.add(table);
            document.newPage();
            document.add(tableChapter);
        } catch (DocumentException ex) {
            throw new InternalServerErrorException(ex);
        }
    }

    /** report plots */
    for (Entry<String, String> entry : report.getFigures().entrySet()) {
        try {
            byte[] valueDecoded = Base64.decodeBase64(entry.getValue());
            Image l = Image.getInstance(valueDecoded);
            document.newPage();
            //image starts at the half's half of pdf page
            l.setAbsolutePosition(0, (document.getPageSize().getHeight() / 2 / 2));
            l.scaleToFit(document.getPageSize());

            Chunk tableChunk = new Chunk(entry.getKey(), tableFont);
            Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber);
            tableChapter.add(l);
            document.add(tableChapter);
        } catch (IOException | DocumentException e) {
            e.printStackTrace();
        }
    }
    document.close();
}