Example usage for com.itextpdf.text PageSize LETTER

List of usage examples for com.itextpdf.text PageSize LETTER

Introduction

In this page you can find the example usage for com.itextpdf.text PageSize LETTER.

Prototype

Rectangle LETTER

To view the source code for com.itextpdf.text PageSize LETTER.

Click Source Link

Document

This is the letter format

Usage

From source file:Modelo.RelatoriosBEAN.java

public static void relatorioVendaJogoPeriodo(String s, String dI, String dF)
        throws FileNotFoundException, DocumentException {
    String path = System.getProperty("user.home") + FRMEmitirRelatorios.local + ".pdf";
    Document document = new Document(PageSize.LETTER);
    PdfWriter.getInstance(document, new FileOutputStream(path));
    document.open();/*from  w w  w  .  j a  v a 2  s .c om*/
    document.addAuthor("TechSales");
    document.addCreator("TechSales");
    document.addSubject("TechSales - Sistema de gerenciamento de locadoras");
    document.addCreationDate();
    document.addTitle("TechSales");

    HTMLWorker htmlWorker = new HTMLWorker(document);

    String frase;
    try {
        frase = "<html>" + "<head> <meta charset=\"utf-8\"> </head>" + "<body>"
                + "<h1 align=center>Relatrio de Jogos vendidos</h1>" + "<br/>"
                + "<h3 align=center>Perodo de " + dI + " a " + dF + "</h3>" + "<br/><br/>"
                + "<table BORDER RULES=rows border=0 style=\"  width:100%; \">\n" + "<tr> "
                + "<th align=center><strong>Cdigo do jogo</strong></th> "
                + "<th align=center><strong>Nome do jogo</strong></th> "
                + "<th align=center><strong>Nmero de vendas</strong></th> "
                + "<th align=center><strong>Valor total das vendas</strong></th> " + "</tr> ";
        for (JogoBEAN j : jDAO.vendaPorPeriodo(s)) {
            frase += "<tr align=center><td>" + j.getJoCodigo() + "</td><td>" + j.getJoNome() + "</td><td>"
                    + j.getJoQtd() + "</td><td>" + j.getJoPrecoPadrao() + "</td></tr>";
        }
        frase += "</table>";
        frase += "</body></html>";
        htmlWorker.parse(new StringReader(frase));
        document.close();
        if (Desktop.isDesktopSupported()) {
            try {
                Desktop.getDesktop().open(new File(path));
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Modelo.RelatoriosBEAN.java

public static void relatorioAluguelJogoPeriodo(String s, String dI, String dF)
        throws FileNotFoundException, DocumentException {
    String path = System.getProperty("user.home") + FRMEmitirRelatorios.local + ".pdf";
    Document document = new Document(PageSize.LETTER);
    PdfWriter.getInstance(document, new FileOutputStream(path));
    document.open();/*from  w  ww .  java 2 s .c  o  m*/
    document.addAuthor("TechSales");
    document.addCreator("TechSales");
    document.addSubject("TechSales - Sistema de gerenciamento de locadoras");
    document.addCreationDate();
    document.addTitle("TechSales");

    HTMLWorker htmlWorker = new HTMLWorker(document);

    String frase;
    try {
        frase = "<html>" + "<head> <meta charset=\"utf-8\"> </head>" + "<body>" + "<br/>"
                + "<h1 align=center>Relatrio de Jogos alugados</h1>" + "<h3 align=center>Perodo de " + dI
                + " a " + dF + "</h3>" + "<br/><br/>"
                + "<table BORDER RULES=rows border=0 style=\"  width:100%; \">\n" + "<tr> "
                + "<th align=center><strong>Cdigo do jogo</strong></th> "
                + "<th align=center><strong>Nome do jogo</strong></th> "
                + "<th align=center><strong>Nmero de alugueis</strong></th> "
                + "<th align=center><strong>Valor total dos alugueis</strong></th> " + "</tr> ";
        for (JogoBEAN j : jDAO.aluguelPorPeriodo(s)) {
            frase += "<tr align=center><td>" + j.getJoCodigo() + "</td><td>" + j.getJoNome() + "</td><td>"
                    + j.getJoQtd() + "</td><td>" + j.getJoPrecoPadrao() + "</td></tr>";
        }
        frase += "</table>";
        frase += "</body></html>";
        htmlWorker.parse(new StringReader(frase));
        document.close();
        if (Desktop.isDesktopSupported()) {
            try {
                Desktop.getDesktop().open(new File(path));
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Modelo.RelatoriosBEAN.java

public static void notaDaVenda(VendaBEAN v) throws FileNotFoundException, DocumentException {
    String path = System.getProperty("user.home") + FRMEmitirRelatorios.local + ".pdf";
    Document document = new Document(PageSize.LETTER);
    PdfWriter.getInstance(document, new FileOutputStream(path));
    document.open();//  w  w  w .  j ava 2 s  .c  o  m
    document.addAuthor("TechSales");
    document.addCreator("TechSales");
    document.addSubject("TechSales - Sistema de gerenciamento de locadoras");
    document.addCreationDate();
    document.addTitle("TechSales");

    HTMLWorker htmlWorker = new HTMLWorker(document);

    String frase;
    try {
        frase = "<html>" + "<head> <meta charset=\"utf-8\"> </head>" + "<body>"
                + "<h1 align=center>Nota de Compra</h1>" + "<br/><br/>"
                + "<table BORDER RULES=rows border=0 style=\"  width:100%; \">\n" + "<tr> "
                + "<th align=center><strong>Cdigo</strong></th> "
                + "<th align=center><strong>Cliente</strong></th> "
                + "<th align=center><strong>Data</strong></th> "
                + "<th align=center><strong>Total</strong></th> "
                + "<th align=center><strong>Entrada</strong></th> "
                + "<th align=center><strong>Parcelas</strong></th> "
                + "<th align=center><strong>Vendedor</strong></th> " + "</tr> ";

        frase += "<tr align=center><td>" + v.getVendaCodigo() + "</td><td>" + v.getCliente().getCliCodigo()
                + "</td><td>" + v.getVendaData() + "</td><td>" + "</td><td>" + v.getVendaValorTotal()
                + "</td><td>" + "</td><td>" + v.getVendaEntrada() + "</td><td>" + "</td><td>"
                + v.getVendaNparcelas() + "</td><td>" + "</td><td>" + v.getVendedor().getVendedorCodigo()
                + "</td></tr>" + "</table>";

        frase += "<table BORDER RULES=rows border=0 style=\"  width:100%; \">\n" + "<br/><br/>" + "<tr> "
                + "<th align=center><strong>Parcela</strong></th> "
                + "<th align=center><strong>Data</strong></th> "
                + "<th align=center><strong>Valor</strong></th> "
                + "<th align=center><strong>Situao</strong></th> " + "</tr> ";

        for (VendaAPrazoBEAN vap : cVap.listarALL()) {
            if (vap.getVenda().getVendaCodigo() == v.getVendaCodigo()) {
                frase += "<tr align=center><td>" + vap.getVapNumParcela() + "</td><td>" + vap.getVapData()
                        + "</td><td>" + vap.getVapValorParcela() + "</td><td>" + vap.getVapSituacao()
                        + "</td></tr>";
            }
        }
        frase += "</table>";
        frase += "</body></html>";
        htmlWorker.parse(new StringReader(frase));
        document.close();
        if (Desktop.isDesktopSupported()) {
            try {
                Desktop.getDesktop().open(new File(path));
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Modelo.RelatoriosBEAN.java

public static void notaDeConta(ContaBEAN v) throws FileNotFoundException, DocumentException {
    String path = System.getProperty("user.home") + FRMEmitirRelatorios.local + ".pdf";
    Document document = new Document(PageSize.LETTER);
    PdfWriter.getInstance(document, new FileOutputStream(path));
    document.open();/*from  w w  w . j av  a  2 s.  c o m*/
    document.addAuthor("TechSales");
    document.addCreator("TechSales");
    document.addSubject("TechSales - Sistema de gerenciamento de locadoras");
    document.addCreationDate();
    document.addTitle("TechSales");

    HTMLWorker htmlWorker = new HTMLWorker(document);

    String frase;
    try {
        frase = "<html>" + "<head> <meta charset=\"utf-8\"> </head>" + "<body>"
                + "<h1 align=center>Nota de Conta</h1>" + "<br/><br/>"
                + "<table BORDER RULES=rows border=0 style=\"  width:100%; \">\n" + "<tr> "
                + "<th align=center><strong>Cdigo</strong></th> "
                + "<th align=center><strong>Fornecedor</strong></th> "
                + "<th align=center><strong>Data</strong></th> "
                + "<th align=center><strong>Total</strong></th> "
                + "<th align=center><strong>Entrada</strong></th> "
                + "<th align=center><strong>Parcelas</strong></th> " + "</tr> ";

        frase += "<tr align=center><td>" + v.getConCodigo() + "</td><td>"
                + v.getFornecedor().getForNomeEmpresa() + "</td><td>" + v.getConData() + "</td><td>"
                + v.getConValorTotal() + "</td><td>" + v.getConEntrada() + "</td><td>" + v.getConNparcelas()
                + "</td></tr>" + "</table>";

        frase += "<table BORDER RULES=rows border=0 style=\"  width:100%; \">\n" + "<br/><br/>" + "<tr> "
                + "<th align=center><strong>Parcela</strong></th> "
                + "<th align=center><strong>Data</strong></th> "
                + "<th align=center><strong>Valor</strong></th> "
                + "<th align=center><strong>Situao</strong></th> " + "</tr> ";

        for (ContaAPrazoBEAN vap : cCap.listarALL()) {
            if (vap.getConta().getConCodigo() == v.getConCodigo()) {
                frase += "<tr align=center><td>" + vap.getCapNumParcela() + "</td><td>" + vap.getCapData()
                        + "</td><td>" + vap.getCapValorParcela() + "</td><td>" + vap.getCapSituacao()
                        + "</td></tr>";
            }
        }
        frase += "</table>";
        frase += "</body></html>";
        htmlWorker.parse(new StringReader(frase));
        document.close();
        if (Desktop.isDesktopSupported()) {
            try {
                Desktop.getDesktop().open(new File(path));
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:mom.trd.opentheso.SelectedBeans.BaseDeDonnesBean.java

/**
* permet de generer une document pour pouvoir le telecharger
* le format c'est pdf//from   www  .j ava 2 s  . c om
* @return
* @throws SQLException
* @throws Exception 
*/
public StreamedContent pdf() throws SQLException, Exception {
    Thesaurus thesaurus = new Thesaurus();
    ExportStatistiques expo = new ExportStatistiques();
    expo.recuperatefils(connect.getPoolConnexion(), theso.getThesaurus().getId_thesaurus(),
            theso.getThesaurus().getLanguage(), 2);
    Document pdf = new Document(PageSize.LETTER);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer;
    Paragraph para = new Paragraph(expo.getDocument());
    writer = PdfWriter.getInstance(pdf, baos);
    if (!pdf.isOpen()) {
        pdf.open();
    }
    pdf.addTitle("theso");
    pdf.add(para);
    //Adding content to pdf
    pdf.close();
    InputStream stream = new ByteArrayInputStream(baos.toByteArray());
    fileDownload = new DefaultStreamedContent(stream, "application/pdf",
            "Thsaurus" + thesaurus.getId_thesaurus() + ".pdf");

    return fileDownload;
}

From source file:net.atomique.ksar.export.FilePDF.java

License:Open Source License

public void run() {
    total_pages += mysar.get_page_to_print();

    switch (Config.getPDFPageFormat()) {

    case "A4":
        document = new Document(PageSize.A4.rotate());
        break;/*  ww w .  j av a 2 s . com*/

    case "LEGAL":
        document = new Document(PageSize.LEGAL.rotate());
        break;

    case "LETTER":
        document = new Document(PageSize.LETTER.rotate());
        break;

    default:
        document = new Document(PageSize.A4.rotate());
        break;
    }

    pdfheight = document.getPageSize().getHeight();
    pdfwidth = document.getPageSize().getWidth();
    pageheight = pdfheight - (2 * pdfmargins);
    pagewidth = pdfwidth - (2 * pdfmargins);

    try {
        writer = PdfWriter.getInstance(document, new FileOutputStream(pdffilename));
    } catch (DocumentException | FileNotFoundException ex) {
        log.error("Parser Exception", ex);
    }
    writer.setPageEvent(this);
    writer.setCompressionLevel(0);

    // document parameter before open
    document.addTitle("kSar Grapher");
    //document.addSubject("SAR Statistics of " + mysar.hostName);
    //document.addKeywords("https://github.com/vlsi/ksar");
    //document.addKeywords(mysar.hostName);
    //document.addKeywords(mysar.myOS.sarStartDate);
    //document.addKeywords(mysar.myOS.sarEndDate);
    document.addCreator("kSar Version:" + VersionNumber.getVersionString());
    document.addAuthor("https://github.com/vlsi/ksar");

    // open the doc
    document.open();
    pdfcb = writer.getDirectContent();
    PdfOutline root = pdfcb.getRootOutline();

    IndexPage(document);

    export_treenode(mysar.graphtree, root);

    document.close();

    if (dialog != null) {
        dialog.dispose();
    }

}

From source file:net.FilterLogic.imaging.ToPDF.java

License:Apache License

private void writeMultiPagePDF(String fileName) throws Exception {
    float STD_WIDTH = 620;
    float STD_HEIGHT = 775;
    float newWidth = 0;
    float newHeight = 0;
    float xPos = 0;
    float yPos = 0;

    boolean scaleImage = true;
    boolean pdfAutoOrientation = true;
    boolean autoCenter = false;
    boolean portrait = true;

    BufferedImage img = null;//from   w  w w  . ja  v a 2 s. c o  m
    Document pdf;

    PdfWriter writer;

    try {
        // scale image
        String si = this.documentProperties.getProperty(KEY_SCALE_TO_FIT, KEY_SCALE_TO_FIT_DEFAULT);
        scaleImage = Boolean.parseBoolean(si);

        // auto-orientation
        String ao = this.documentProperties.getProperty(KEY_AUTO_ORIENTATION, KEY_AUTO_ORIENTATION_DEFAULT);
        pdfAutoOrientation = Boolean.parseBoolean(ao);

        // auto-center
        String ac = this.documentProperties.getProperty(KEY_AUTO_CENTER, KEY_AUTO_CENTER_DEFAULT);
        autoCenter = Boolean.parseBoolean(ac);

        if (document.size() > 0)
            img = document.get(0);

        if (img != null) {

            // if dpi set, calculate new width/height
            if (horizontalDPI > 0 && verticalDPI > 0) {
                float xd = (float) horizontalDPI / 100;
                float yd = (float) verticalDPI / 100;

                newWidth = img.getWidth() / xd;
                newHeight = img.getHeight() / yd;
            } else {
                newWidth = img.getWidth();
                newHeight = img.getHeight();
            }

            // if image width or height changed, scale
            if (newWidth != img.getWidth() || newHeight != img.getHeight())
                scaleImage = true;

            // if auto orientation, set portrait or landscape 
            if (pdfAutoOrientation) {
                if (newWidth >= newHeight) {
                    pdf = new Document(PageSize.LETTER.rotate());
                    portrait = false;
                } else {
                    pdf = new Document(PageSize.LETTER);
                    portrait = true;
                }
            } else {
                // else, always portrait
                pdf = new Document(PageSize.LETTER);
                portrait = true;
            }

            writer = PdfWriter.getInstance(pdf, new FileOutputStream(fileName));

            writer.setFullCompression();

            pdf.open();

            // set document props
            setDocumentProperties(pdf);

            int t = 0;

            float pdfPageWidth = pdf.getPageSize().getWidth();
            float pdfPageHeight = pdf.getPageSize().getHeight();

            // if new image larger than standard size, override and enable image scaling
            if (newWidth > pdfPageWidth || newHeight > pdfPageHeight) {
                scaleImage = true;

                if (newWidth > pdfPageWidth)
                    newWidth = pdfPageWidth;

                if (newHeight > pdfPageHeight)
                    newHeight = pdfPageHeight;
            }

            // break out each page to single file
            while (t < totalPages) {
                PdfContentByte cb = writer.getDirectContent();
                com.itextpdf.text.Image pdfImage;

                if (img != null) {
                    pdfImage = com.itextpdf.text.Image.getInstance(img, null);

                    // calculate center
                    if (autoCenter) {
                        if (portrait) {
                            xPos = (pdfPageWidth - newWidth) / 2;
                            yPos = (pdfPageHeight - newHeight) / 2;
                        } else {
                            //xPos = ((pdfPageHeight * (float)1.60) - newWidth) / 2;
                            xPos = (pdfPageHeight - newWidth) / 2;
                            yPos = (pdfPageWidth - newHeight) / 2;
                        }
                    } else {
                        // if not scaling, set image to top left
                        if (!scaleImage) {
                            xPos = 0;
                            // calculate top left corner
                            yPos = pdfPageWidth - newHeight;
                        } else {
                            xPos = 0;
                            yPos = 0;
                        }
                    }

                    // check if x and y pos >=0
                    if (xPos < 0)
                        xPos = 0;
                    if (yPos < 0)
                        yPos = 0;

                    if (scaleImage) {

                        if (!portrait) {
                            pdfImage.scaleToFit(newHeight, newWidth);
                        } else {
                            pdfImage.scaleToFit(newWidth, newHeight);
                        }

                        // check is scaled height/width match new width/height
                        // if not, recalculate center if autcenter enabled.
                        if (newWidth != pdfImage.getScaledWidth() || newHeight != pdfImage.getScaledHeight()) {
                            newWidth = pdfImage.getScaledWidth();
                            newHeight = pdfImage.getScaledHeight();

                            // calculate center
                            if (autoCenter) {
                                xPos = (pdfPageWidth - newWidth) / 2;
                                yPos = (pdfPageHeight - newHeight) / 2;

                                // check if x and y pos >=0
                                if (xPos < 0)
                                    xPos = 0;
                                if (yPos < 0)
                                    yPos = 0;
                            }
                        }

                        pdfImage.setAbsolutePosition(xPos, yPos);
                    } else {
                        pdfImage.setAbsolutePosition(xPos, yPos);
                    }

                    cb.addImage(pdfImage);

                    // inc counter
                    ++t;

                    if (t < totalPages) {
                        img = document.get(t);

                        // if dpi set, calculate new width/height
                        if (horizontalDPI > 0 && verticalDPI > 0) {
                            float xd = (float) horizontalDPI / 100;
                            float yd = (float) verticalDPI / 100;

                            newWidth = img.getWidth() / xd;
                            newHeight = img.getHeight() / yd;
                        } else {
                            newWidth = img.getWidth();
                            newHeight = img.getHeight();
                        }

                        // if auto orientation, set portrait or landscape 
                        if (pdfAutoOrientation) {
                            if (newWidth >= newHeight) {
                                pdf.setPageSize(PageSize.LETTER.rotate());
                                portrait = false;
                            } else {
                                pdf.setPageSize(PageSize.LETTER);
                                portrait = true;
                            }
                        } else {
                            // else, always portrait
                            pdf.setPageSize(PageSize.LETTER);
                            portrait = true;
                        }

                        // create new page.  must happen after setting page orientation
                        pdf.newPage();
                        writer.newPage();

                        // get new pages width/height
                        pdfPageWidth = pdf.getPageSize().getWidth();
                        pdfPageHeight = pdf.getPageSize().getHeight();

                        // set width/height to something normal
                        if (newWidth > pdfPageWidth)
                            newWidth = pdfPageWidth;

                        if (newHeight > pdfPageHeight)
                            newHeight = pdfPageHeight;
                    }
                }

            }

            pdf.close();

            // add file name to list
            fileNames = new ArrayList<String>();
            fileNames.add(fileName);
        }
    } catch (Exception e) {
        throw new Exception(e);
    }
}

From source file:Operaciones.Destajo.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);/* w w w.j  a  v  a 2s.com*/
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        session.beginTransaction().begin();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
        //Orden ord=buscaApertura();
        PDF reporte = new PDF();
        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);
        folder.mkdirs();
        reporte.Abrir(PageSize.LETTER.rotate(), "Valuacin", "reportes/" + ord + "/" + valor + "-destajo.pdf");
        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;
        int izquierda = Element.ALIGN_LEFT;
        int derecha = Element.ALIGN_RIGHT;
        float tam[] = new float[] { 150, 50, 100, 300 };
        PdfPTable tabla = reporte.crearTabla(4, tam, 100, Element.ALIGN_LEFT);

        DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
        formatoPorcentaje.setMinimumFractionDigits(2);

        cabecera(reporte, bf, tabla);

        session.beginTransaction().begin();
        Orden dato = (Orden) session.get(Orden.class, Integer.parseInt(this.ord));
        List cuentas = null;
        for (int x = 0; x < t_datos.getRowCount(); x++) {
            tabla.addCell(reporte.celda(t_datos.getValueAt(x, 1).toString(), font, contenido, izquierda, 0, 1,
                    Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda(formatoPorcentaje.format((Double) t_datos.getValueAt(x, 2)), font,
                    contenido, derecha, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda(formatoPorcentaje.format((Double) t_datos.getValueAt(x, 3)), font,
                    contenido, derecha, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda(t_datos.getValueAt(x, 4).toString(), font, contenido, izquierda, 0, 1,
                    Rectangle.RECTANGLE));
        }
        session.beginTransaction().rollback();

        tabla.setHeaderRows(1);
        reporte.agregaObjeto(tabla);
        reporte.cerrar();
        reporte.visualizar("reportes/" + ord + "/" + valor + "-destajo.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.flush();
            session.clear();
            session.close();
        }
}

From source file:Operaciones.Destajo.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);//from w w w  . j a  va2  s  .  c o  m
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        session.beginTransaction().begin();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
        //Orden ord=buscaApertura();
        PDF reporte = new PDF();
        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);
        folder.mkdirs();
        reporte.Abrir(PageSize.LETTER.rotate(), "Valuacin", "reportes/" + ord + "/" + valor + "-destajo.pdf");
        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;
        int izquierda = Element.ALIGN_LEFT;
        int derecha = Element.ALIGN_RIGHT;
        float tam[] = new float[] { 150, 50, 100, 300 };
        PdfPTable tabla = reporte.crearTabla(4, tam, 100, Element.ALIGN_LEFT);

        cabecera(reporte, bf, tabla);

        session.beginTransaction().begin();
        Orden dato = (Orden) session.get(Orden.class, Integer.parseInt(this.ord));
        List cuentas = null;
        for (int x = 0; x < 21; x++) {
            tabla.addCell(reporte.celda(" \n ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda(" \n ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda(" \n ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda(" \n ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
        }
        session.beginTransaction().rollback();

        tabla.setHeaderRows(1);
        reporte.agregaObjeto(tabla);
        reporte.cerrar();
        reporte.visualizar("reportes/" + ord + "/" + valor + "-destajo.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.flush();
            session.clear();
            session.close();
        }
}

From source file:org.apli.jbs.utilidades.DocsPDFJB.java

public String creaDocInfoIngreso(String sNombrePac, int nHab, int nEpi) throws Exception {
    String nombrePDF = "";
    if (sNombrePac.equals("") || nHab == 0 || nEpi == 0) {
        throw new Exception("Funcion.creaContratoIngresHosp: error de programacin, faltan datos");
    } else {/*from  ww w. ja va2s . c  o m*/
        nombrePDF = "docs/contratosCreadosPac/infoPacIngreHosp-" + nEpi + ".pdf";
        ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext();
        File folder = new File(extCont.getRealPath("//resources//"));
        String urlImg = extCont.getRealPath("//utilidades//");
        try {
            urlImg = urlImg.replace("\\utilidades", "\\");
            Document document = new Document(PageSize.LETTER, 70, 70, 30, 30);
            PdfWriter.getInstance(document, new FileOutputStream(
                    new File(folder, "docs/contratosCreadosPac/infoPacIngreHosp-" + nEpi + ".pdf")));
            document.open();
            Phrase phrase = new Phrase(90);
            HTMLWorker htmlWorker = new HTMLWorker(document);
            String str = "<p align='center'><img align=\"center\" src='" + urlImg + new PlantillaJB().getLogo()
                    + "' width=\"430\" height=\"70\"></p>\n" + "<div style=\" line-height:95%\">\n";
            File myhtml = new File(folder, "docs/contratos/infoPacIngreHosp.html");
            FileInputStream fileinput = null;
            BufferedInputStream mybuffer = null;
            DataInputStream datainput = null;
            fileinput = new FileInputStream(myhtml);
            mybuffer = new BufferedInputStream(fileinput);
            datainput = new DataInputStream(mybuffer);
            Calendar c1 = GregorianCalendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMMM-yyyy");
            int i = 0;
            while (datainput.available() != 0) {
                i++;
                String linea = datainput.readLine();

                if (linea.indexOf("NOMBREPAC") > 0) {
                    linea = linea.replace("NOMBREPAC", sNombrePac.toUpperCase());
                }
                if (linea.indexOf("<u>FECHA</u>") > 0) {
                    linea = linea.replace("<u>FECHA</u>", "<u>" + sdf.format(c1.getTime()) + "</u>");
                }
                if (linea.indexOf("NO-HAB") > 0) {
                    linea = linea.replace("NO-HAB", "" + nHab);
                }
                str += linea + " ";
            }
            str += "</div>";
            htmlWorker.parse(new StringReader(str));
            document.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        }

    }
    return nombrePDF;
}