Example usage for com.itextpdf.text Document addTitle

List of usage examples for com.itextpdf.text Document addTitle

Introduction

In this page you can find the example usage for com.itextpdf.text Document addTitle.

Prototype


public boolean addTitle(String title) 

Source Link

Document

Adds the title to a Document.

Usage

From source file:tourma.views.report.HTMLtoPDF.java

public static void exportToPDF(FileOutputStream output, String source, String title, Rectangle size,
        boolean excludeCutTable) {
    try {/*www .  j a v a 2 s.  c o  m*/
        Document document = new Document(size);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, output);
        document.open();
        document.addAuthor(Tournament.getTournament().getParams().getTournamentOrga());
        document.addCreator("TourMa");
        document.addSubject(Tournament.getTournament().getParams().getTournamentName());
        document.addCreationDate();
        document.addTitle(title);
        XMLWorkerHelper worker = XMLWorkerHelper.getInstance();

        worker.parseXHtml(pdfWriter, document, new StringReader(source));

        document.close();
    } catch (DocumentException | IOException e) {
        e.printStackTrace();
    }
}

From source file:transactions.downloadStatServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   www . ja va2s.co  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (OutputStream os = response.getOutputStream()) {

        int custID = Integer.valueOf(request.getParameter("custID").toString());

        Account account = getAccountDetails(custID);

        int accountNumber = account.getAccountNumber();//Integer.valueOf(request.getSession().getAttribute("AccountNumber").toString());
        String accountStatus = account.getAccountStatus();
        String accountType = account.getAccountType();
        Double accountBalance = account.getAccountBalance();

        SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        Date date = new Date();
        // System.out.println(format.format(date)); //2014/08/06 15:59:48

        String firstName = request.getSession().getAttribute("FirstName").toString();
        String lastName = request.getSession().getAttribute("LastName").toString();

        List<Transactions> transactionList = getTransactions(accountNumber);

        try {
            /*Initialize PDF documents - logical objects */
            Document pdf_stat = new Document();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PdfWriter.getInstance(pdf_stat, baos);
            pdf_stat.open();

            pdf_stat.addTitle("Statement for Account");
            // pdf_stat.add(new Paragraph("Statment of Account", Font.getFamily("BOLD")));
            pdf_stat.add(new Paragraph(String.format(
                    "                                                             Statement Of Account ")));
            pdf_stat.add(new Paragraph(String.format(" ")));
            pdf_stat.add(new Paragraph(String.format(" ")));
            pdf_stat.add(new Paragraph(String.format(" ")));
            pdf_stat.add(new Paragraph(String.format("Customer ID: %s", custID)));
            pdf_stat.add(new Paragraph(String.format("Name: %s %s", firstName, lastName)));
            pdf_stat.add(new Paragraph(String.format("Account Number: %s", accountNumber)));
            pdf_stat.add(new Paragraph(String.format("Account Type: %s", accountType)));
            pdf_stat.add(new Paragraph(String.format("Account Status: %s", accountStatus)));
            pdf_stat.add(new Paragraph(
                    String.format("Account Balance as on %s : %s", format.format(date), accountBalance)));
            pdf_stat.add(new Paragraph(String.format(" ")));

            //we have ** columns in our table
            PdfPTable pdf_Table = new PdfPTable(4);
            //create a cell object
            PdfPCell table_cell;

            table_cell = new PdfPCell(new Phrase("TransactionID"));
            pdf_Table.addCell(table_cell);
            // table_cell = new PdfPCell(new Phrase("AccountNumber"));
            //  pdf_Table.addCell(table_cell);
            table_cell = new PdfPCell(new Phrase("TransactionType"));
            pdf_Table.addCell(table_cell);
            table_cell = new PdfPCell(new Phrase("TimeStamp"));
            pdf_Table.addCell(table_cell);
            table_cell = new PdfPCell(new Phrase("Trans Amount"));
            pdf_Table.addCell(table_cell);

            for (Transactions trans : transactionList) {
                table_cell = new PdfPCell(new Phrase(String.valueOf(trans.getTransactionID())));
                pdf_Table.addCell(table_cell);
                // table_cell = new PdfPCell(new Phrase(String.valueOf(accountNumber)));
                //  pdf_Table.addCell(table_cell);
                table_cell = new PdfPCell(new Phrase(trans.getTransactionType()));
                pdf_Table.addCell(table_cell);
                table_cell = new PdfPCell(new Phrase(trans.getDateTime().toString()));
                pdf_Table.addCell(table_cell);
                table_cell = new PdfPCell(new Phrase(trans.getTransactionAmount().toString()));
                pdf_Table.addCell(table_cell);

            }
            //pdf_stat.add(new Paragraph(String.format("Account Balance: %s", accountNumber)));

            pdf_stat.add(new Paragraph(String.format("Statement: ")));
            pdf_stat.add(new Paragraph(String.format(" ")));
            /* Attach report table to PDF */
            pdf_stat.add(pdf_Table);
            //pdf_stat.open();
            pdf_stat.close();

            // setting some response headers
            response.setHeader("Expires", "0");
            response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
            response.setHeader("Pragma", "public");
            // setting the content type
            response.setContentType("application/pdf");
            // the contentlength
            response.setContentLength(baos.size());
            // write ByteArrayOutputStream to the ServletOutputStream
            //OutputStream os = response.getOutputStream();
            baos.writeTo(os);
            os.flush();
            os.close();

            //  response.sendRedirect("statement.pdf");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

From source file:uk.ac.openmf.utils.OpenMFPDFGenerator.java

public static void addMetaData(Document document, String title, String subject) {
    document.addTitle(title);
    document.addSubject(subject);//from   w ww  .  ja  v a  2s .c om
}

From source file:Utility.PDFDemo.java

public void cretePDF(String name, String rpor) throws FileNotFoundException {

    try {/*from   ww  w  .  j a  va2s  .  co m*/

        //Create document for pdf
        Document doc = new Document();

        //PDF writer to write into document
        PdfWriter docwriter = null;

        DecimalFormat df = new DecimalFormat("0.00");

        try {
            // //file path
            //String path = "docs/" + name;
            docwriter = PdfWriter.getInstance(doc, new FileOutputStream(rpor + ".pdf"));
        } catch (DocumentException ex) {
            Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
        }

        //document header attributes
        doc.addAuthor("CHED CU");
        doc.addCreationDate();
        doc.addProducer();
        doc.addCreator("Grant Monitor");
        doc.addTitle(rpor);
        doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape
        //doc.setPageSize(PageSize.A4);
        doc.setMargins(30f, 30f, 20f, 20f);

        //open document
        doc.open();

        //Creating a paragraphs and chunks
        Paragraph pp = new Paragraph("Cocoa Health And Extension", forTitle);
        pp.setAlignment(Element.ALIGN_CENTER);

        Paragraph palaglapgh = new Paragraph("(Cocobod)", bfBold12);
        palaglapgh.setAlignment(Element.ALIGN_CENTER);

        Chunk chk = new Chunk("From GIS Office, Accra", bfBold12);
        chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position
        Paragraph underText = new Paragraph(chk);
        underText.setAlignment(Element.ALIGN_CENTER);

        Chunk chuk1 = new Chunk("Lot No:", bfBold12);
        chuk1.setUnderline(.1f, -2f);
        Chunk chuk2 = new Chunk(name, bfBold12);

        Paragraph regionText = new Paragraph(rpor, bfBold12);
        regionText.setAlignment(Element.ALIGN_CENTER);
        String rporx = "";
        //            ResultSet dir = manager.PDFdemos(name);
        //            try {
        //                if (dir.next()) {
        //                    rporx = dir.getString(12);
        //
        //                }
        //            } catch (SQLException ex) {
        //                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
        //            }

        Paragraph regionTexts = new Paragraph(rporx, bfBold12);
        regionText.setAlignment(Element.ALIGN_CENTER);
        //add the PDF table to the paragraph
        //palaglapgh.add(table);
        //Table Generation block
        regionText.add(reports());

        //SECTION TO ADD ELEMENTS TO PDF
        // add the paragraph to the document
        doc.add(pp);
        //doc.add(Chunk.NEWLINE);       //Adds a new blank line
        doc.add(palaglapgh);
        doc.add(underText);

        doc.add(chuk1);
        doc.add(chuk2);

        //Current Date and time insertion
        Paragraph newDate = new Paragraph(new Date().toString(), bf12);
        newDate.setAlignment(Element.ALIGN_RIGHT);
        doc.add(newDate);
        doc.add(regionTexts);
        doc.add(regionText);

        //close the document
        doc.close();

        //close the writer
        docwriter.close();

    } catch (DocumentException ex) {
        Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:uy.gub.imm.sae.web.mbean.reserva.PasoFinalMBean.java

License:Open Source License

public String imprimirTicket() {
    try {/*w ww . j  a  v a2  s .  c o m*/

        BaseColor colorBlack = new BaseColor(0, 0, 0);

        BaseFont times = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        BaseFont helveticaBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252,
                BaseFont.NOT_EMBEDDED);
        BaseFont symbol = BaseFont.createFont(BaseFont.SYMBOL, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

        SimpleDateFormat sdfHr = new SimpleDateFormat("HH:mm");
        SimpleDateFormat sdfFecha = new SimpleDateFormat("dd/MM/yyyy");

        Rectangle pageSize = new Rectangle(210, 210);

        Document document = new Document(pageSize);
        document.addTitle(getI18N().getText("etiqueta.reserva.title"));

        ByteArrayOutputStream os = new ByteArrayOutputStream();

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

        PdfContentByte pdfContent = pdfWriter.getDirectContent();

        InputStream is = PasoFinalMBean.class.getResourceAsStream(SAEProfile.getInstance().getProperties()
                .getProperty(SAEProfile.PROFILE_UI_TEMPLATES_IMAGES_LOGO_TICKET_KEY));

        byte[] arrImage = new byte[4096];
        is.read(arrImage);

        Image img = Image.getInstance(arrImage);

        img.scaleAbsolute(100, 30);
        img.setAbsolutePosition(55, 170);
        document.add(img);

        //Dibujo primer lnea
        LineSeparator line = new LineSeparator();
        line.setAlignment(LineSeparator.ALIGN_CENTER);
        line.setLineColor(colorBlack);
        line.setLineWidth(0.5f);

        line.drawLine(pdfContent, 10, 200, 170);

        //Etiqueta RESERVA
        pdfContent.beginText();
        pdfContent.setFontAndSize(helveticaBold, 15);
        pdfContent.setTextMatrix(45, 150);
        pdfContent.showText(getI18N().getText("etiqueta.reserva.showText"));
        pdfContent.endText();

        //Fecha de la reserva
        String fecha_reserva = sdfFecha.format(sesionMBean.getDisponibilidad().getHoraInicio());

        pdfContent.beginText();
        pdfContent.setFontAndSize(symbol, 16);
        pdfContent.setTextMatrix(130, 150);
        pdfContent.showText(fecha_reserva);
        pdfContent.endText();

        //Dibujo segunda lnea
        line.drawLine(pdfWriter.getDirectContent(), 10, 200, 140);

        int etiqHoraTamanio = 25;
        int etiqHoraX = 15;
        int etiqHoraY = 85;

        int valorHoraTamanio = 40;
        int valorHoraX = 105;
        int valorHoraY = 80;

        String serie = sesionMBean.getRecurso().getSerie();
        boolean conSerie = (serie != null) && (serie.length() >= 1);

        if (sesionMBean.getRecurso().getMostrarNumeroEnTicket()) {

            if (!conSerie) {
                //Ajusto valor y etiqueta hora
                etiqHoraTamanio = 20;
                etiqHoraX = 15;
                etiqHoraY = 110;

                valorHoraTamanio = 30;
                valorHoraX = 120;
                valorHoraY = 107;

                //Etiqueta NUMERO
                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(15, 65);
                pdfContent.showText(getI18N().getText("etiqueta.numero.numero"));
                pdfContent.endText();

                //Numero de la reserva
                String nro = sesionMBean.getReservaConfirmada().getNumero().toString();
                int nro_pos = 135;

                if (nro.length() == 1) {
                    nro_pos = 135;
                } else if (nro.length() == 2) {
                    nro_pos = 125;
                } else {
                    nro_pos = 105;
                }

                pdfContent.beginText();
                pdfContent.setFontAndSize(symbol, 60);
                pdfContent.setTextMatrix(nro_pos, 55);
                pdfContent.showText(nro);
                pdfContent.endText();
            } else {
                //<<<<<< Agregado >>>>>>
                //Ajusto valor y etiqueta hora
                etiqHoraTamanio = 20;
                etiqHoraX = 15;
                etiqHoraY = 123;

                valorHoraTamanio = 20;
                valorHoraX = 120;
                valorHoraY = 122;

                //Etiqueta SERIE
                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(15, 87);
                pdfContent.showText(getI18N().getText("etiqueta.numero.serie"));
                pdfContent.endText();

                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(120, 87);
                pdfContent.showText(serie);
                pdfContent.endText();

                //Etiqueta NUMERO
                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(15, 50);
                pdfContent.showText(getI18N().getText("etiqueta.numero.numero"));
                pdfContent.endText();

                //Numero de la reserva
                String nro = sesionMBean.getReservaConfirmada().getNumero().toString();
                int nro_pos = 135;

                if (nro.length() == 1) {
                    nro_pos = 135;
                } else if (nro.length() == 2) {
                    nro_pos = 125;
                } else {
                    nro_pos = 105;
                }

                pdfContent.beginText();
                pdfContent.setFontAndSize(symbol, 40);
                pdfContent.setTextMatrix(nro_pos, 47);
                pdfContent.showText(nro);
                pdfContent.endText();
            }
        }

        //Etiqueta HORA
        pdfContent.beginText();
        pdfContent.setFontAndSize(helveticaBold, etiqHoraTamanio);
        pdfContent.setTextMatrix(etiqHoraX, etiqHoraY);
        pdfContent.showText(getI18N().getText("etiqueta.hora.hora"));
        pdfContent.endText();

        //Hora de la reserva
        pdfContent.beginText();
        pdfContent.setFontAndSize(symbol, valorHoraTamanio);
        pdfContent.setTextMatrix(valorHoraX, valorHoraY);
        pdfContent.showText(sdfHr.format(sesionMBean.getDisponibilidad().getHoraInicio()));
        pdfContent.endText();

        //Dibujo tercer lnea
        line.drawLine(pdfWriter.getDirectContent(), 10, 200, 45);

        String ticketEtiqUno = sesionMBean.getRecurso().getTextoRecurso().getTicketEtiquetaUno();
        String ticketEtiqDos = sesionMBean.getRecurso().getTextoRecurso().getTicketEtiquetaDos();
        int largoEtiqUno = 0;
        int largoEtiqDos = 0;
        int xValores = 0;

        if (ticketEtiqUno != null) {
            largoEtiqUno = ticketEtiqUno.length();
        }

        if (ticketEtiqDos != null) {
            largoEtiqDos = ticketEtiqDos.length();
        }

        if (largoEtiqUno > largoEtiqDos) {
            xValores = 8 * (largoEtiqUno + 1);
        } else {
            xValores = 8 * (largoEtiqDos + 1);
        }

        //Etiqueta uno
        if (ticketEtiqUno != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(helveticaBold, 10);
            pdfContent.setTextMatrix(10, 30);
            pdfContent.showText(ticketEtiqUno + ":");
            pdfContent.endText();
        }

        //Valor etiqueta uno
        String valorEtiqUno = sesionMBean.getRecurso().getTextoRecurso().getValorEtiquetaUno();
        if (valorEtiqUno != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(times, 10);
            pdfContent.setTextMatrix(xValores, 30);
            pdfContent.showText(valorEtiqUno);
            pdfContent.endText();
        }

        //Etiqueta dos

        if (ticketEtiqDos != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(helveticaBold, 10);
            pdfContent.setTextMatrix(10, 15);
            pdfContent.showText(ticketEtiqDos + ":");
            pdfContent.endText();
        }

        //Valor etiqueta dos
        String valorEtiqDos = sesionMBean.getRecurso().getTextoRecurso().getValorEtiquetaDos();
        if (valorEtiqDos != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(times, 10);
            pdfContent.setTextMatrix(xValores, 15);
            pdfContent.showText(valorEtiqDos);
            pdfContent.endText();
        }

        pdfWriter.addJavaScript("this.print({bUI: true, bSilent: true, bShrinkToFit: true});", false);
        pdfWriter.addJavaScript("this.closeDoc(true);");

        document.close();

        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
        response.setContentType("application/pdf");

        os.writeTo(response.getOutputStream());

        response.getOutputStream().flush();
        response.getOutputStream().close();
        facesContext.responseComplete();

    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

From source file:uy.gub.imm.sae.web.mbean.reserva.PasoFinalMBean.java

License:Open Source License

public String guardarTicket() {
    try {//  ww  w.  ja  v a  2  s.c om

        BaseColor colorBlack = new BaseColor(0, 0, 0);

        BaseFont times = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        BaseFont helveticaBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252,
                BaseFont.NOT_EMBEDDED);
        BaseFont symbol = BaseFont.createFont(BaseFont.SYMBOL, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

        SimpleDateFormat sdfHr = new SimpleDateFormat("HH:mm");
        SimpleDateFormat sdfFecha = new SimpleDateFormat("dd/MM/yyyy");

        Rectangle pageSize = new Rectangle(210, 210);

        Document document = new Document(pageSize);
        document.addTitle(getI18N().getText("etiqueta.reserva.title"));

        ByteArrayOutputStream os = new ByteArrayOutputStream();

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

        PdfContentByte pdfContent = pdfWriter.getDirectContent();

        InputStream is = PasoFinalMBean.class.getResourceAsStream(SAEProfile.getInstance().getProperties()
                .getProperty(SAEProfile.PROFILE_UI_TEMPLATES_IMAGES_LOGO_TICKET_KEY));

        byte[] arrImage = new byte[4096];
        is.read(arrImage);

        Image img = Image.getInstance(arrImage);

        img.scaleAbsolute(100, 30);
        img.setAbsolutePosition(55, 170);
        document.add(img);

        //Dibujo primer lnea
        LineSeparator line = new LineSeparator();
        line.setAlignment(LineSeparator.ALIGN_CENTER);
        line.setLineColor(colorBlack);
        line.setLineWidth(0.5f);

        line.drawLine(pdfContent, 10, 200, 170);

        //Etiqueta RESERVA
        pdfContent.beginText();
        pdfContent.setFontAndSize(helveticaBold, 15);
        pdfContent.setTextMatrix(45, 150);
        pdfContent.showText(getI18N().getText("etiqueta.reserva.showText"));
        pdfContent.endText();

        //Fecha de la reserva
        String fecha_reserva = sdfFecha.format(sesionMBean.getDisponibilidad().getHoraInicio());

        pdfContent.beginText();
        pdfContent.setFontAndSize(symbol, 16);
        pdfContent.setTextMatrix(130, 150);
        pdfContent.showText(fecha_reserva);
        pdfContent.endText();

        //Dibujo segunda lnea
        line.drawLine(pdfWriter.getDirectContent(), 10, 200, 140);

        int etiqHoraTamanio = 25;
        int etiqHoraX = 15;
        int etiqHoraY = 85;

        int valorHoraTamanio = 40;
        int valorHoraX = 105;
        int valorHoraY = 80;

        String serie = sesionMBean.getRecurso().getSerie();
        boolean conSerie = (serie != null) && (serie.length() >= 1);

        if (sesionMBean.getRecurso().getMostrarNumeroEnTicket()) {

            if (!conSerie) {
                //Ajusto valor y etiqueta hora
                etiqHoraTamanio = 20;
                etiqHoraX = 15;
                etiqHoraY = 110;

                valorHoraTamanio = 30;
                valorHoraX = 120;
                valorHoraY = 107;

                //Etiqueta NUMERO
                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(15, 65);
                pdfContent.showText(getI18N().getText("etiqueta.numero.numero"));
                pdfContent.endText();

                //Numero de la reserva
                String nro = sesionMBean.getReservaConfirmada().getNumero().toString();
                int nro_pos = 135;

                if (nro.length() == 1) {
                    nro_pos = 135;
                } else if (nro.length() == 2) {
                    nro_pos = 125;
                } else {
                    nro_pos = 105;
                }

                pdfContent.beginText();
                pdfContent.setFontAndSize(symbol, 60);
                pdfContent.setTextMatrix(nro_pos, 55);
                pdfContent.showText(nro);
                pdfContent.endText();
            } else {

                //Ajusto valor y etiqueta hora
                etiqHoraTamanio = 20;
                etiqHoraX = 15;
                etiqHoraY = 123;

                valorHoraTamanio = 20;
                valorHoraX = 120;
                valorHoraY = 122;

                //Etiqueta SERIE
                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(15, 87);
                pdfContent.showText(getI18N().getText("etiqueta.numero.serie"));
                pdfContent.endText();

                pdfContent.beginText();
                pdfContent.setFontAndSize(symbol, 20);
                pdfContent.setTextMatrix(120, 87);
                pdfContent.showText(serie);
                pdfContent.endText();

                //Etiqueta NUMERO
                pdfContent.beginText();
                pdfContent.setFontAndSize(helveticaBold, 20);
                pdfContent.setTextMatrix(15, 50);
                pdfContent.showText(getI18N().getText("etiqueta.numero.numero"));
                pdfContent.endText();

                //Numero de la reserva
                String nro = sesionMBean.getReservaConfirmada().getNumero().toString();
                int nro_pos = 135;

                if (nro.length() == 1) {
                    nro_pos = 135;
                } else if (nro.length() == 2) {
                    nro_pos = 125;
                } else {
                    nro_pos = 105;
                }

                pdfContent.beginText();
                pdfContent.setFontAndSize(symbol, 40);
                pdfContent.setTextMatrix(nro_pos, 47);
                pdfContent.showText(nro);
                pdfContent.endText();
            }
        }

        //Etiqueta HORA
        pdfContent.beginText();
        pdfContent.setFontAndSize(helveticaBold, etiqHoraTamanio);
        pdfContent.setTextMatrix(etiqHoraX, etiqHoraY);
        pdfContent.showText(getI18N().getText("etiqueta.hora.hora"));
        pdfContent.endText();

        //Hora de la reserva
        pdfContent.beginText();
        pdfContent.setFontAndSize(symbol, valorHoraTamanio);
        pdfContent.setTextMatrix(valorHoraX, valorHoraY);
        pdfContent.showText(sdfHr.format(sesionMBean.getDisponibilidad().getHoraInicio()));
        pdfContent.endText();

        //Dibujo tercer lnea
        line.drawLine(pdfWriter.getDirectContent(), 10, 200, 45);

        String ticketEtiqUno = sesionMBean.getRecurso().getTextoRecurso().getTicketEtiquetaUno();
        String ticketEtiqDos = sesionMBean.getRecurso().getTextoRecurso().getTicketEtiquetaDos();
        int largoEtiqUno = 0;
        int largoEtiqDos = 0;
        int xValores = 0;

        if (ticketEtiqUno != null) {
            largoEtiqUno = ticketEtiqUno.length();
        }

        if (ticketEtiqDos != null) {
            largoEtiqDos = ticketEtiqDos.length();
        }

        if (largoEtiqUno > largoEtiqDos) {
            xValores = 8 * (largoEtiqUno + 1);
        } else {
            xValores = 8 * (largoEtiqDos + 1);
        }

        //Etiqueta uno
        if (ticketEtiqUno != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(helveticaBold, 10);
            pdfContent.setTextMatrix(10, 30);
            pdfContent.showText(ticketEtiqUno + ":");
            pdfContent.endText();
        }

        //Valor etiqueta uno
        String valorEtiqUno = sesionMBean.getRecurso().getTextoRecurso().getValorEtiquetaUno();
        if (valorEtiqUno != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(times, 10);
            pdfContent.setTextMatrix(xValores, 30);
            pdfContent.showText(valorEtiqUno);
            pdfContent.endText();
        }

        //Etiqueta dos
        if (ticketEtiqDos != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(helveticaBold, 10);
            pdfContent.setTextMatrix(10, 15);
            pdfContent.showText(ticketEtiqDos + ":");
            pdfContent.endText();
        }

        //Valor etiqueta dos
        String valorEtiqDos = sesionMBean.getRecurso().getTextoRecurso().getValorEtiquetaDos();
        if (valorEtiqDos != null) {
            pdfContent.beginText();
            pdfContent.setFontAndSize(times, 10);
            pdfContent.setTextMatrix(xValores, 15);
            pdfContent.showText(valorEtiqDos);
            pdfContent.endText();
        }

        document.close();

        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
        response.setContentType("application/pdf");
        response.setHeader("Content-disposition", "attachment; filename=" + "Ticket de confirmacin.pdf");

        os.writeTo(response.getOutputStream());

        response.getOutputStream().flush();
        response.getOutputStream().close();
        facesContext.responseComplete();

    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

From source file:vemo.controller.ReportController.java

@RequestMapping(value = "report/RentalsPDF", produces = "application/pdf")
@ResponseBody/*from  ww  w . ja v  a 2 s .co m*/
public String RentalsPDF(ModelMap model, HttpServletResponse response, HttpServletRequest request,
        Integer maxResults, @RequestParam(value = "first", required = false) String first,
        @RequestParam(value = "last", required = false) String last) throws DocumentException, IOException {
    Document document = new Document();
    PdfWriter.getInstance(document, response.getOutputStream());
    document.open();

    document.addTitle("Report Of Rentals");
    document.addSubject("Report");
    document.addKeywords("Report Of Rentals");
    document.addAuthor("Sandy Andryanto");
    document.addCreator("Sandy Andryanto");

    document.add(new Paragraph(" "));
    document.add(new Paragraph(" "));
    document.add(new Paragraph(" REPORT OF RENTALS "));
    document.add(new Paragraph(" "));
    document.add(new Paragraph(" "));

    PdfPTable table = new PdfPTable(6);
    table.addCell("No");
    table.addCell("Date");
    table.addCell("Account Count");
    table.addCell("Movie Count");
    table.addCell("Total Loan");
    table.addCell("Total Returned");

    List<CustomersRentals> list = ReportDao.list(0, maxResults, first, last);
    for (int i = 0; i < list.size(); i++) {
        table.addCell("" + (i + 1));
        table.addCell("" + list.get(i).getDate());
        table.addCell("" + ReportDao.GetReportRentals("" + list.get(i).getDate(), "account_id"));
        table.addCell("" + ReportDao.GetReportRentals("" + list.get(i).getDate(), "movie_id"));
        table.addCell("" + ReportDao.GetReportRentals2("" + list.get(i).getDate(), "loan"));
        table.addCell("" + ReportDao.GetReportRentals2("" + list.get(i).getDate(), "return"));
    }

    document.add(table);
    document.close();

    return "RentalsPDF";
}

From source file:vemo.controller.ReportController.java

@RequestMapping(value = "report/FinancialsPDF", produces = "application/pdf")
@ResponseBody// w  ww. j  av a 2s . c  om
public String FinancialsPDF(ModelMap model, HttpServletResponse response, HttpServletRequest request,
        Integer maxResults, @RequestParam(value = "first", required = false) String first,
        @RequestParam(value = "last", required = false) String last) throws DocumentException, IOException {
    Document document = new Document();
    PdfWriter.getInstance(document, response.getOutputStream());
    document.open();

    document.addTitle("Report Of Financials");
    document.addSubject("Report");
    document.addKeywords("Report Of Financials");
    document.addAuthor("Sandy Andryanto");
    document.addCreator("Sandy Andryanto");

    document.add(new Paragraph(" "));
    document.add(new Paragraph(" "));
    document.add(new Paragraph(" REPORT OF FINANCIALS "));
    document.add(new Paragraph(" "));
    document.add(new Paragraph(" "));

    PdfPTable table = new PdfPTable(5);
    table.addCell("No");
    table.addCell("Date");
    table.addCell("Customer Name");
    table.addCell("Movie Title");
    table.addCell("Amount");

    int SUM = 0;
    List<CustomersRentals> list = ReportDao.list(0, maxResults, first, last);
    for (int i = 0; i < list.size(); i++) {
        table.addCell("" + (i + 1));
        table.addCell("" + list.get(i).getDate());
        table.addCell("" + list.get(i).getRentals().getCustomers().getFullName());
        table.addCell("" + list.get(i).getRentals().getMovies().getTitle());
        table.addCell("" + list.get(i).getAmount());
        SUM += list.get(i).getAmount();
    }

    table.addCell("");
    table.addCell("");
    table.addCell("TOTAL");
    table.addCell("");
    table.addCell("$ " + SUM);

    document.add(table);
    document.close();

    return "RentalsPDF";
}

From source file:Ventas.GeneradorFormato.java

public static void main(String[] args) {
    try {/*from w w w.j  a  v a  2s. c o m*/

        Document document = new Document(PageSize.LETTER, 50, 50, 85, 50);
        document.addAuthor("Ventas");
        document.addTitle("Ventas");

        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        writer.setInitialLeading(16);
        Rectangle rct = new Rectangle(80, 104, 500, 688);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

        document.open();
        //            Paragraph parrafo2 = new Paragraph("De aqui en ", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED));
        //            parrafo2.setAlignment(0);
        document.add(Chunk.NEWLINE);
        document.add(new Paragraph("Fecha:"));
        Paragraph id_Venta = new Paragraph("ID_Venta:");
        id_Venta.setAlignment(0);
        document.add(id_Venta);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        //            document.add(parrafo2);
        document.add(new Paragraph("Nombre del cliente:"));
        //            document.add(Chunk.NEWLINE);
        //            document.add(Chunk.NEWLINE);
        document.add(new Paragraph("Apellido Paterno:"));
        //            document.add(Chunk.NEWLINE);
        document.add(new Paragraph("Apellido Materno:"));
        document.add(new Paragraph("Domicilio:"));
        document.add(new Paragraph("Calle:"));
        document.add(new Paragraph("Numero:"));
        document.add(new Paragraph(""));

        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.close();
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
}

From source file:wtw.ui.GeneratingPdfAction.java

private static void addMetaData(Document document) {
    document.addTitle("My first PDF");
    document.addSubject("Using iText");
    document.addKeywords("Java, PDF, iText");
    document.addAuthor("Konda Reddy. Lingamdinne");
    document.addCreator("Konda Reddy. Lingamdinne");
}