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

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

Introduction

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

Prototype

String CP1252

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

Click Source Link

Document

A possible encoding.

Usage

From source file:jasperSoft.MergePDF.java

/**
 * /*from  w ww  . j ava  2 s .  c om*/
 * @param streamOfPDFFiles
 * @param outputStream
 * @param paginate 
 */
public static void concatPDFs(List<InputStream> streamOfPDFFiles, OutputStream outputStream, boolean paginate) {

    Document document = new Document();
    try {
        List<InputStream> pdfs = streamOfPDFFiles;
        List<PdfReader> readers = new ArrayList<PdfReader>();
        int totalPages = 0;
        Iterator<InputStream> iteratorPDFs = pdfs.iterator();

        // Create Readers for the pdfs.
        while (iteratorPDFs.hasNext()) {
            InputStream pdf = iteratorPDFs.next();
            PdfReader pdfReader = new PdfReader(pdf);
            readers.add(pdfReader);
            totalPages += pdfReader.getNumberOfPages();
        }
        // Create a writer for the outputstream
        PdfWriter writer = PdfWriter.getInstance(document, outputStream);

        document.open();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        PdfContentByte cb = writer.getDirectContent(); // Holds the PDF
        // data

        PdfImportedPage page;
        int currentPageNumber = 0;
        int pageOfCurrentReaderPDF = 0;
        Iterator<PdfReader> iteratorPDFReader = readers.iterator();

        // Loop through the PDF files and add to the output.
        while (iteratorPDFReader.hasNext()) {
            PdfReader pdfReader = iteratorPDFReader.next();

            // Create a new page in the target for each source page.
            while (pageOfCurrentReaderPDF < pdfReader.getNumberOfPages()) {
                document.newPage();
                pageOfCurrentReaderPDF++;
                currentPageNumber++;
                page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF);
                cb.addTemplate(page, 0, 0);

                // Code for pagination.
                if (paginate) {
                    cb.beginText();
                    cb.setFontAndSize(bf, 9);
                    cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
                            "" + currentPageNumber + " of " + totalPages, 520, 5, 0);
                    cb.endText();
                }
            }
            pageOfCurrentReaderPDF = 0;
        }
        outputStream.flush();
        document.close();
        outputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (document.isOpen()) {
            document.close();
        }
        try {
            if (outputStream != null) {
                outputStream.close();
            }
        } catch (IOException ioe) {
            ioe.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   ww w .j a  va2  s. c om*/

    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.fossa.rolp.util.PdfStreamSource.java

License:Open Source License

public PdfStreamSource(FossaApplication app, LebData lebData, LebCreator lebCreator)
        throws DocumentException, IOException, PdfFormatierungsException {
    this.lebData = lebData;
    this.lebCreator = lebCreator;
    BaseFont fontNormal = BaseFont.createFont(
            app.getContext().getBaseDirectory() + Config.getRelativeNormalFontPath(), BaseFont.CP1252,
            BaseFont.EMBEDDED);//from  w w w .  jav a2 s .  c om
    BaseFont fontBold = BaseFont.createFont(
            app.getContext().getBaseDirectory() + Config.getRelativeBoldFontPath(), BaseFont.CP1252,
            BaseFont.EMBEDDED);
    BaseFont fontThin = BaseFont.createFont(
            app.getContext().getBaseDirectory() + Config.getRelativeThinFontPath(), BaseFont.CP1252,
            BaseFont.EMBEDDED);

    lernentwicklungsberichtUeberschriftFont = new Font(fontThin, 22, Font.NORMAL);
    standardTextFont = new Font(fontNormal, KlassenstufenUtils.getLebFontSize(lebData.getKlassenname()),
            Font.NORMAL);
    standardTextBoldFont = new Font(fontBold, KlassenstufenUtils.getLebFontSize(lebData.getKlassenname()),
            Font.NORMAL);
    headerFont = new Font(fontNormal, 12, Font.NORMAL);
    footerFont = new Font(fontNormal, 10, Font.NORMAL);
    fusszeilenFont = new Font(fontNormal, 8, Font.NORMAL);
    zeilenabstandsfaktor = KlassenstufenUtils.getLebZeilenabstandAsFactor(lebData.getKlassenname());
    document = null;
    try {
        document = new Document(PageSize.A4, 100, 90, topMargin, bottomMargin);
        PdfWriter writer = PdfWriter.getInstance(document, outputStream);
        LebPageHelper event = new LebPageHelper(lebData,
                Image.getInstance(app.getContext().getBaseDirectory() + Config.getRelativeLogoPath()),
                fusszeilenFont);
        writer.setPageEvent(event);
        document.open();
        addContent(writer);
        addFooter(lebData, writer);
    } finally {
        if (document != null) {
            document.close();
        }
    }
}

From source file:org.javad.pdf.fonts.FontRegistry.java

License:Apache License

/**
 * This method will attempt to find the named font with the specified size and style
 * using a naming roll-off technique based on some of the naming conventions observed.
 * <ul><li>//ww  w.  j a v  a 2  s. co m
 * If the style is bold and italic, a font with the name <code>"[name]-bolditalic"</code>
 * will attempted. </li>
 * <li>If the style is both a name like <code>"[name] bold"</code> will be
 * attempted.</li>
 * <li>If the font is italic, the names <code>"[name] italic"</code> and then
 * <code>"[name]-italic"</code> will be tried.</li>
 * <li> Finally if none of these styled fonts can be located, the <code>"[name]"</code> will be tried.</li>
 * </ul>
 * 
 * @param name
 * @param bean
 * @return
 */
Font findFont(String name, PdfFontBean bean) {
    String form = (bean.isI18N()) ? BaseFont.IDENTITY_H : BaseFont.CP1252;
    Font f = null;
    if (bean.isBold() && bean.isItalic()) {
        f = FontFactory.getFont(name + "-bolditalic", form, bean.getSize(), bean.getStyle());
    }
    if (isFontInvalid(f) && bean.isBold()) {
        f = FontFactory.getFont(name + " bold", form, bean.getSize(), bean.getStyle());
    }
    if (isFontInvalid(f) && bean.isItalic()) {
        f = FontFactory.getFont(name + " italic", form, bean.getSize(), bean.getStyle());
        if (isFontInvalid(f)) {
            f = FontFactory.getFont(name + "-italic", form, bean.getSize(), bean.getStyle());
        }
    }
    if (isFontInvalid(f)) {
        f = FontFactory.getFont(name, form, bean.getSize(), bean.getStyle());
    }
    if (logger.isLoggable(Level.FINER)) {
        @SuppressWarnings("null")
        BaseFont bf = f.getBaseFont();
        if (bf != null) {
            String[][] fullName = bf.getFullFontName();
            if (fullName != null && fullName.length >= 1 && fullName[0].length >= 4) {
                logger.log(Level.FINER, "The calculated font name is \"{0}\"", fullName[0][3]);
            } else {
                logger.finer("The base font full name was not parseable.");
            }
        } else {
            logger.log(Level.FINER, "The base font was null for \"{0}\" with style {1}",
                    new Object[] { name, bean.getStyle() });
        }
    }
    return f;
}

From source file:org.oscarehr.fax.util.PdfCoverPageCreator.java

License:Open Source License

public byte[] createCoverPage() {

    Document document = new Document();
    ByteArrayOutputStream os = new ByteArrayOutputStream();

    try {/*from ww  w .  j  a v a2s.  c om*/

        PdfWriter pdfWriter = PdfWriter.getInstance(document, os);
        document.open();

        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(95);

        PdfPCell cell = new PdfPCell(table);
        cell.setBorder(0);
        cell.setPadding(3);
        cell.setColspan(1);
        table.addCell(cell);

        ClinicDAO clinicDao = SpringUtils.getBean(ClinicDAO.class);
        Clinic clinic = clinicDao.getClinic();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        Font headerFont = new Font(bf, 28, Font.BOLD);
        Font infoFont = new Font(bf, 12, Font.NORMAL);

        if (clinic != null) {

            cell = new PdfPCell(new Phrase(
                    String.format("%s\n %s, %s, %s %s", clinic.getClinicName(), clinic.getClinicAddress(),
                            clinic.getClinicCity(), clinic.getClinicProvince(), clinic.getClinicPostal()),
                    headerFont));
        } else {

            cell = new PdfPCell(new Phrase("OSCAR", headerFont));

        }

        cell.setPaddingTop(100);
        cell.setPaddingLeft(25);
        cell.setPaddingBottom(25);
        cell.setBorderWidthBottom(1);
        table.addCell(cell);

        PdfPTable infoTable = new PdfPTable(1);
        cell = new PdfPCell(new Phrase(note, infoFont));
        cell.setPaddingTop(25);
        cell.setPaddingLeft(25);
        infoTable.addCell(cell);
        table.addCell(infoTable);

        document.add(table);

    } catch (DocumentException e) {

        MiscUtils.getLogger().error("PDF COVER PAGE ERROR", e);
        return new byte[] {};

    } catch (IOException e) {

        MiscUtils.getLogger().error("PDF COVER PAGE ERROR", e);
        return new byte[] {};

    } finally {
        document.close();
    }

    return os.toByteArray();
}

From source file:org.primaresearch.pdf.PageToPdfConverter.java

License:Apache License

/**
 * Creates the font that is to be used for the hidden text layer in the PDF.
 *///from www  . j a v a  2 s  .  co  m
private void createFont() throws DocumentException, IOException {

    //TODO Even with the 'NOT_EMBEDDED' settings it seems to embed the font!

    if (ttfFontFilePath == null)
        font = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    else {
        font = FontFactory.getFont(ttfFontFilePath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED).getBaseFont();
        //PDTrueTypeFont.loadTTF(document, ttfFontFilePath);
        //Encoding enc = font.getFontEncoding();
        //Map<Integer, String> map = enc.getCodeToNameMap();
        //System.out.println("Font encoding map size: " + map.size());
    }
}

From source file:printInv.GenerateInvoice.java

public void initializeFonts() {

    try {/*from w  w  w  .  j a v a2  s.c o  m*/
        bfBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Report.ItextReport.java

public static void absText(PdfWriter writer, String text, int x, int y) {
    try {/*from   www .ja  va2s  . co m*/
        PdfContentByte cb = writer.getDirectContent();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.saveState();
        cb.beginText();
        cb.moveText(x, y);
        cb.setFontAndSize(bf, 12);
        cb.showText(text);
        cb.endText();
        cb.restoreState();
    } catch (DocumentException | IOException e) {
        e.getMessage();
    }
}

From source file:ryerson.daspub.artifact.PublishQRTagSheetTask.java

License:Open Source License

/**
 * Draw a text label on the current page.
 * @param Writer PDF writer/* w  ww. j  a v  a  2 s.c om*/
 * @param Text
 * @param x
 * @param y
 * @param alignment
 * @throws DocumentException
 * @throws IOException 
 */
private void drawLabel(PdfWriter Writer, String Text, int x, int y, int alignment)
        throws DocumentException, IOException {
    PdfContentByte cb = Writer.getDirectContent();
    BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    cb.saveState();
    cb.beginText();
    cb.setFontAndSize(bf, 9);
    cb.showTextAligned(alignment, Text, x, y, 0);
    cb.endText();
    cb.restoreState();
}

From source file:Servicios.formatos.java

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

    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        Orden ord = (Orden) session.get(Orden.class, Integer.parseInt(orden));
        Date fecha = 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/Plantillaunidad.pdf");
        PdfStamper stamp = new PdfStamper(reader,
                new FileOutputStream("reportes/" + ord.getIdOrden() + "/" + valor + "-unidad.pdf"));
        PdfContentByte cb = stamp.getUnderContent(1);
        AcroFields fdfDoc = stamp.getAcroFields();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        Image img;
        //IMAGEN
        cb.beginText();
        try {
            img = Image.getInstance(ord.getCompania().getFoto());
            img.setAbsolutePosition(35, 648);
            img.scaleAbsoluteWidth(265);
            img.scaleAbsoluteHeight(100);
            cb.addImage(img, true);
        } catch (Exception e) {
            e.printStackTrace();
        }

        //ORDEN 
        try {
            fdfDoc.setField("Orden", String.valueOf(ord.getIdOrden()));
        } catch (Exception e) {
            fdfDoc.setField("Orden", " ");
        }
        //ASEGURADO
        try {
            fdfDoc.setField("Asegurado", ord.getClientes().getNombre());
        } catch (Exception e) {
            fdfDoc.setField("Asegurado", " ");
        }
        //PLACAS
        try {
            fdfDoc.setField("Placas", ord.getNoPlacas());
        } catch (Exception e) {
            fdfDoc.setField("Placas", " ");
        }
        //MARCA
        try {
            fdfDoc.setField("Marca", ord.getMarca().getMarcaNombre());
        } catch (Exception e) {
            fdfDoc.setField("Marca", " ");
        }
        //TIPO
        try {
            fdfDoc.setField("Tipo", ord.getTipo().getTipoNombre());
        } catch (Exception e) {
            fdfDoc.setField("Tipo", " ");
        }
        //HOJALATERIA
        try {
            fdfDoc.setField("Hojalateria", ord.getEmpleadoByRHojalateria().getNombre());
        } catch (Exception e) {
            fdfDoc.setField("Hojalateria", " ");
        }
        //MECANICA
        try {
            fdfDoc.setField("Mecanica", ord.getEmpleadoByRMecanica().getNombre());
        } catch (Exception e) {
            fdfDoc.setField("Mecanica", " ");
        }
        //SUSPENCION
        try {
            fdfDoc.setField("Suspencion", ord.getEmpleadoByRSuspension().getNombre());
        } catch (Exception e) {
            fdfDoc.setField("Suspencion", " ");
        }
        //ELECTRICO
        try {
            fdfDoc.setField("Electrico", ord.getEmpleadoByRElectrico().getNombre());
        } catch (Exception e) {
            fdfDoc.setField("Electrico", " ");
        }
        //INGRESO
        try {
            fdfDoc.setField("Ingreso", ord.getFecha().toString());
        } catch (Exception e) {
            fdfDoc.setField("Ingreso", " ");
        }
        //ENTREGA
        try {
            fdfDoc.setField("Entrega", ord.getFechaTaller().toString());
        } catch (Exception e) {
            fdfDoc.setField("Entrega", " ");
        }
        cb.endText();

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