Example usage for com.itextpdf.text Document addKeywords

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

Introduction

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

Prototype


public boolean addKeywords(String keywords) 

Source Link

Document

Adds the keywords to a Document.

Usage

From source file:PrefichaPDF.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*  w  ww  .j a  v a 2 s. c  om*/
        response.setContentType("application/pdf");

        String curp = new String(request.getParameter("curp").getBytes("ISO-8859-1"), "UTF-8");

        ConexionOracle conexionOracle = new ConexionOracle();

        String sql = "select * from PERSONALDATA_ASP_TAB where curp=" + "'" + curp + "'";
        System.out.println(sql);
        System.out.println("Esta es la curp: " + curp);

        conexionOracle.conectar();
        Connection conn = conexionOracle.getConnection();
        // driver@machineName:port:SID           ,  userid,  password
        Statement stmt = conn.createStatement();

        ResultSet rset = stmt.executeQuery(sql);

        while (rset.next()) {

            fichabd = rset.getString("id_aspirante");
            periodobd = rset.getString("periodo_solicitud");
            prefichabd = rset.getString("preficha");
            nombrebd = rset.getString("nombre");
            String appat = rset.getString("apellido_pat");
            String apmat = rset.getString("apellido_mat");
            apellidosbd = appat + " " + apmat;
            curpbd = rset.getString("curp");
            carrerabd = rset.getString("carrera");
            modalidadbd = rset.getString("modalidad");
        }

        try {

            Document preficha = new Document();
            PdfWriter writer = PdfWriter.getInstance(preficha, response.getOutputStream());
            preficha.open();
            //encabezado
            //encabezado
            //encabezado
            //encabezado

            //                documento.add(vacio);
            //                documento.add(vacio);
            //                documento.add(vacio);
            Paragraph depto = new Paragraph("Departamento de servicios escolares",
                    FontFactory.getFont("arial", 20, Font.BOLD));
            depto.setAlignment(Element.ALIGN_CENTER);

            preficha.add(depto);

            Paragraph vacio = new Paragraph("  ", FontFactory.getFont("arial", 10, Font.BOLD));
            vacio.setAlignment(Element.ALIGN_CENTER);
            preficha.add(vacio);
            preficha.add(vacio);
            //                preficha.add(vacio);
            //cuerpo
            //cuerpo
            //cuerpo
            //cuerpo
            //cuerpo

            Paragraph periodo_text = new Paragraph("Convocatoria de nuevo ingreso periodo: " + periodobd,
                    FontFactory.getFont("arial", 10, Font.BOLD));
            periodo_text.setAlignment(Element.ALIGN_CENTER);
            preficha.add(periodo_text);

            preficha.add(vacio);
            preficha.add(vacio);

            Paragraph fotografia = new Paragraph("Fotografa", FontFactory.getFont("arial", 10, Font.BOLD));
            fotografia.setAlignment(Element.ALIGN_CENTER);
            preficha.add(fotografia);

            PdfContentByte rectangulo_general = writer.getDirectContentUnder();
            rectangulo_general.rectangle(50, 48, 500, 710);
            rectangulo_general.fill();
            drawRectangleSC(rectangulo_general, 50, 48, 500, 710);

            PdfContentByte rectangulo_periodo = writer.getDirectContentUnder();
            rectangulo_periodo.rectangle(125, 725, 350, 20);
            rectangulo_periodo.fill();
            drawRectangleSC(rectangulo_periodo, 125, 725, 350, 20);

            String url_logo = "/Imagenes/itt_logo_opt.jpg";
            String absolute_url_logo = getServletContext().getRealPath(url_logo);
            Image itt_logo = Image.getInstance(absolute_url_logo);

            String url_logo_bnmx = "/Imagenes/bnmx_color_opt.jpg";
            String absolute_url_logo_bnmx = getServletContext().getRealPath(url_logo_bnmx);
            Image bnmx_logo = Image.getInstance(absolute_url_logo_bnmx);

            Image Logo_itt = Image.getInstance(itt_logo);
            Logo_itt.setAbsolutePosition(140f, 640f);
            preficha.add(Logo_itt);

            Image Logo_banco = Image.getInstance(bnmx_logo);
            Logo_banco.setAbsolutePosition(380f, 340f);
            preficha.add(Logo_banco);

            PdfContentByte espacio_imagen = writer.getDirectContentUnder();
            espacio_imagen.rectangle(255, 635, 85, 80);
            espacio_imagen.fill();
            drawRectangleSC(espacio_imagen, 255, 635, 85, 80);

            //                preficha.add(vacio);
            preficha.add(vacio);

            PdfContentByte fechaimpr = writer.getDirectContentUnder();
            fechaimpr.rectangle(416, 635, 100, 35);
            fechaimpr.fill();
            drawRectangleSC(fechaimpr, 416, 635, 100, 35);
            //            drawRectangle(fechaimpr, 85, 530, 430, 25);

            Paragraph fechapdf = new Paragraph("\tFecha de impresin                ",
                    FontFactory.getFont("arial", 10, com.itextpdf.text.Font.BOLD));
            fechapdf.setAlignment(Element.ALIGN_RIGHT);
            preficha.add(fechapdf);

            Paragraph fechapdf_fec = new Paragraph("\t" + fecha_hoy() + "                          ",
                    FontFactory.getFont("arial", 10, com.itextpdf.text.Font.BOLD));
            fechapdf_fec.setAlignment(Element.ALIGN_RIGHT);
            preficha.add(fechapdf_fec);

            preficha.add(vacio);

            Paragraph no_preficha = new Paragraph("Preficha N: " + prefichabd,
                    FontFactory.getFont("arial", 20, Font.BOLD));
            no_preficha.setAlignment(Element.ALIGN_CENTER);
            preficha.add(no_preficha);

            preficha.add(vacio);
            //                preficha.add(vacio);

            PdfContentByte rectangulo_preficha_no = writer.getDirectContentUnder();
            rectangulo_preficha_no.rectangle(85, 590, 430, 25);
            rectangulo_preficha_no.fill();
            drawRectangleSC(rectangulo_preficha_no, 85, 590, 430, 25);

            PdfContentByte rectangulo_datos = writer.getDirectContentUnder();
            rectangulo_datos.rectangle(85, 500, 430, 80);
            //                rectangulo_datos.rec
            rectangulo_datos.fill();
            drawRectangleSC(rectangulo_datos, 85, 500, 430, 80);

            //////////////////////////////
            Paragraph nombre = new Paragraph(
                    "                                                                              Nombre:   "
                            + nombrebd,
                    FontFactory.getFont("arial", 10, Font.BOLD));
            nombre.setAlignment(Element.ALIGN_LEFT);
            preficha.add(nombre);

            //                preficha.add(vacio);
            Paragraph apellidos = new Paragraph(
                    "                                                                                               "
                            + apellidosbd,
                    FontFactory.getFont("arial", 10, Font.BOLD));
            apellidos.setAlignment(Element.ALIGN_LEFT);
            preficha.add(apellidos);

            //                preficha.add(vacio);
            Paragraph CURP = new Paragraph(
                    "                                                                                 CURP:   "
                            + curpbd,
                    FontFactory.getFont("arial", 10, Font.BOLD));
            CURP.setAlignment(Element.ALIGN_LEFT);
            preficha.add(CURP);

            //                preficha.add(vacio);
            Paragraph carrera = new Paragraph(
                    "                                                            Carrera Solicitada:   "
                            + carrerabd,
                    FontFactory.getFont("arial", 10, Font.BOLD));
            carrera.setAlignment(Element.ALIGN_LEFT);
            preficha.add(carrera);

            //                preficha.add(vacio);
            Paragraph modalidad = new Paragraph(
                    "                                                                          Modalidad:   "
                            + modalidadbd,
                    FontFactory.getFont("arial", 10, Font.BOLD));
            modalidad.setAlignment(Element.ALIGN_LEFT);
            preficha.add(modalidad);

            preficha.add(vacio);
            //                preficha.add(vacio);

            Paragraph formatoBanamex = new Paragraph("FORMATO UNIVERSAL PARA DEPSITOS EN SUCURSALES BANAMEX",
                    FontFactory.getFont("arial", 10, Font.BOLD));
            formatoBanamex.setAlignment(Element.ALIGN_CENTER);
            preficha.add(formatoBanamex);

            PdfContentByte rectanguloDepositoB = writer.getDirectContentUnder();
            rectanguloDepositoB.rectangle(85, 470, 430, 20);
            rectanguloDepositoB.fill();
            drawRectangle(rectanguloDepositoB, 85, 470, 430, 20);

            PdfContentByte rectanguloPago = writer.getDirectContentUnder();
            rectanguloPago.rectangle(85, 280, 430, 190);
            rectanguloPago.fill();
            drawRectangleSC(rectanguloPago, 85, 280, 430, 190);

            preficha.add(vacio);

            PdfContentByte rectanguloConcepto = writer.getDirectContentUnder();
            rectanguloConcepto.rectangle(150, 425, 295, 35);
            //                rectangulo_datos.rec
            rectanguloConcepto.fill();
            drawRectangleSC(rectanguloConcepto, 150, 425, 295, 35);

            Paragraph formatoConceptoPre = new Paragraph("CONCEPTO: PAGO DE DERECHO A EXAMEN DE ADMISIN",
                    FontFactory.getFont("arial", 10, Font.BOLD));
            formatoConceptoPre.setAlignment(Element.ALIGN_CENTER);
            preficha.add(formatoConceptoPre);

            Paragraph fechaEmision = new Paragraph("FECHA DE EMISIN: 18/12/2014",
                    FontFactory.getFont("arial", 10, Font.BOLD));
            fechaEmision.setAlignment(Element.ALIGN_CENTER);
            preficha.add(fechaEmision);

            preficha.add(vacio);
            //                preficha.add(vacio);
            //                preficha.add(vacio);
            //                preficha.add(vacio);
            //                preficha.add(vacio);
            preficha.add(vacio);

            Paragraph importe = new Paragraph("IMPORTE A PAGAR: $1,500.",
                    FontFactory.getFont("arial", 15, Font.BOLD));
            importe.setAlignment(Element.ALIGN_CENTER);
            preficha.add(importe);

            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);
            //                preficha.add(vacio);
            //                preficha.add(vacio);

            String ref = "44353452342353464765634523434";

            Paragraph referencia = new Paragraph(
                    "                                                   REFERENCIA (B): " + ref,
                    FontFactory.getFont("arial", 10, Font.BOLD));
            referencia.setAlignment(Element.ALIGN_LEFT);
            preficha.add(referencia);

            preficha.add(vacio);

            //                Paragraph descrConcepto = new Paragraph("DESCRIPCIN DEL CONCEPTO: CUOTA POR CONCEPTO DE PREINCRIPCIN.", FontFactory.getFont("arial", 10, Font.BOLD));
            //                descrConcepto.setAlignment(Element.ALIGN_CENTER);
            //                preficha.add(descrConcepto);

            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);
            //                preficha.add(vacio);
            //                preficha.add(vacio);
            //                preficha.add(vacio);
            //                preficha.add(vacio);
            //                preficha.add(vacio);

            Paragraph atencion = new Paragraph("Atencin", FontFactory.getFont("arial", 15, Font.BOLD));
            atencion.setAlignment(Element.ALIGN_CENTER);
            preficha.add(atencion);

            PdfContentByte rectangulo_atencion = writer.getDirectContentUnder();
            rectangulo_atencion.rectangle(245, 229, 100, 25);
            rectangulo_atencion.fill();
            drawRectangle(rectangulo_atencion, 245, 229, 100, 25);

            PdfContentByte rectangulo_info = writer.getDirectContentUnder();
            rectangulo_info.rectangle(85, 94, 430, 100);
            rectangulo_info.fill();
            drawRectangle(rectangulo_info, 85, 94, 430, 120);

            preficha.add(vacio);
            preficha.add(vacio);

            Paragraph informacion = new Paragraph(
                    "                        Para continuar con el proceso de preinscripcin debers:\n"
                            + "                           - Realizar el pago para tu examen de admisin con la \"REFERENCIA\" que aparece\n"
                            + "                             en este documento en cualquier sucursal BANAMEX.\n"
                            + "                           - Recibir la notificacin en tu correo electrnico y estar al pendiente de \n"
                            + "                             las notificaciones que sern enviadas al mismo de que el pago ya fue procesado \n"
                            + "                             para completar tu proceso de preinscripcin.\n",
                    FontFactory.getFont("arial", 10, Font.BOLD));
            informacion.setAlignment(Element.ALIGN_LEFT);
            preficha.add(informacion);
            //  pie
            //  pie
            //  pie
            //  pie
            //  pie
            preficha.add(vacio);
            preficha.add(vacio);

            preficha.addTitle("Preficha");
            preficha.addSubject("Instituto Tecnolgico de Toluca");
            preficha.addKeywords("Instituto Tecnolgico de Toluca");
            preficha.addAuthor("Departamento de Servicios escolares");
            preficha.addCreator("Departamento de Servicios escolares");

            preficha.close();

            preficha.close();
        } catch (DocumentException de) {
            throw new IOException(de.getMessage());
        }
    } catch (SQLException ex) {
        Logger.getLogger(PrefichaPDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:PDFmaker.java

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

From source file:CrearPdf.java

private void addMetaData(Document document) {
    document.addTitle("Mi empresa");
    document.addSubject("mi direccion");
    document.addKeywords("Java, PDF, iText");
    document.addAuthor(autor);// w w  w.  ja  v  a2s  .c  om
    document.addCreator(fecha);
}

From source file:Servlet3.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*from w  w w.j  a v a 2s .com*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {
        System.out.println("inside servlet");
        String a = request.getParameter("countryf");
        String c = request.getParameter("submit");
        String b = request.getParameter("paramf");

        //code added by Murugappan

        String CurentUID = request.getParameter("UIDvalue2f");
        String URLRequest = request.getRequestURL().append('?').append(request.getQueryString()).toString();
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, 1);
        SimpleDateFormat format1 = new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy");
        String date1 = cal.getTime().toString();

        System.out.println("inside servlet");

        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:server");

        //iserting data to UserActivity table
        Statement sthistoryinsert3 = con.createStatement();
        String insertstring = "Insert into UserActivity values('" + CurentUID + "','" + date1
                + "','Future Data Forecast','" + a + "','" + b + "','" + URLRequest + "')";
        sthistoryinsert3.executeUpdate(insertstring);
        sthistoryinsert3.close();
        System.out.println("\n Step 1");
        Statement st = con.createStatement();
        //  Statement st2 = con.createStatement();
        XYSeriesCollection dataset = new XYSeriesCollection();
        XYSeries series = new XYSeries(b);

        String query = "SELECT [2000],[2012] FROM country where CountryName='" + a + "' AND SeriesName='" + b
                + "'";
        System.out.println(query);
        ResultSet rs = st.executeQuery(query);
        if (rs == null)
            System.out.println("\n no rows ");
        else
            System.out.println("Rows present ");
        rs.next();

        Double start = Double.parseDouble(rs.getString(1));
        Double end = Double.parseDouble(rs.getString(2));
        Double period = 13.0;
        Double growth = Math.pow((end / start), (1 / period)) - 1;
        System.out.println("growth percentage =" + growth);
        rs.close();
        String query2 = "select [2011],[2012] from country where CountryName='" + a + "' AND SeriesName='" + b
                + "'";
        rs = st.executeQuery(query2);
        rs.next();
        series.add(2011, Double.parseDouble(rs.getString(1)));
        Double second = Double.parseDouble(rs.getString(2));
        series.add(2012, second);

        Double growthvalue = second + (second * growth);

        series.add(2013, growthvalue);
        for (int i = 2014; i <= 2016; i++) {
            System.out.println("actual growth value = " + growthvalue);
            series.add((i++), (growthvalue + growthvalue * growth));
            growthvalue = growthvalue + growthvalue * growth;
        }
        rs.close();
        dataset.addSeries(series);
        DecimalFormat format_2Places = new DecimalFormat("0.00");
        growth = growth * 100;
        growth = Double.valueOf(format_2Places.format(growth));
        JFreeChart chart = ChartFactory.createXYLineChart(
                "Energy forecasting for " + a + " based on " + b + " with growth value estimated at " + growth
                        + "% ",
                "Year", "Energy consumed in millions", dataset, PlotOrientation.VERTICAL, true, true, false);
        // JFreeChart chart1=ChartFactory.createLineChart("World population Growth","Year","population in millions",dataSet1,PlotOrientation.VERTICAL,true,true,false);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        chart.setBackgroundPaint(Color.white);
        final XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.black);
        plot.setRangeGridlinePaint(Color.black);

        final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(2, false);
        renderer.setSeriesShapesVisible(2, false);
        plot.setRenderer(renderer);

        /* We have to insert this colored Pie Chart into the PDF file using iText now */

        if (c.equals("View Graph in Browser")) {
            ChartUtilities.writeChartAsPNG(bos, chart, 700, 500);
            response.setContentType("image/png");
            OutputStream out = new BufferedOutputStream(response.getOutputStream());
            out.write(bos.toByteArray());
            out.flush();
            out.close();
        }

        else {
            int width = 640; /* Width of our chart */
            int height = 480; /* Height of our chart */
            Document PieChart = new Document(new com.itextpdf.text.Rectangle(width, height));
            java.util.Date date = new java.util.Date();
            String chartname = "My_Colored_Chart" + date.getTime() + ".pdf";
            PdfWriter writer = PdfWriter.getInstance(PieChart, new FileOutputStream(chartname));
            PieChart.open();
            /* Add some Metadata to identify document later */
            PieChart.addTitle("How to color your Pie Chart and embed in a PDF file using iText");
            PieChart.addAuthor("Thinktibits");
            PieChart.addKeywords("iText,Color PieChart,JFreeChart,PDF,Example Tutorial");
            PdfContentByte Add_Chart_Content = writer.getDirectContent();
            PdfTemplate template_Chart_Holder = Add_Chart_Content.createTemplate(width, height);
            Graphics2D Graphics_Chart = template_Chart_Holder.createGraphics(width, height,
                    new DefaultFontMapper());
            Rectangle2D Chart_Region = new Rectangle2D.Double(0, 0, 540, 380);
            chart.draw(Graphics_Chart, Chart_Region);
            Graphics_Chart.dispose();
            Add_Chart_Content.addTemplate(template_Chart_Holder, 0, 0);
            PieChart.close();
            //PrintWriter out = response.getWriter();
            //out.println("<!DOCTYPE html> <html> <body> <a href =file:///C:/apache-tomcat-8.0.12/bin/"+chartname+" download=newFileName> Download your file here </a> </body></html>");
            PdfReader reader = new PdfReader(chartname);
            PdfStamper stamper = null;
            try {
                stamper = new PdfStamper(reader, bos);
            } catch (DocumentException e) {
                e.printStackTrace();
            }
            try {
                stamper.close();
            } catch (DocumentException e) {

                e.printStackTrace();
            }

            // set some response headers
            response.setHeader("Expires", "0");
            response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
            response.setHeader("Pragma", "public");
            response.setContentType("application/pdf");
            response.setContentLength(bos.size());

            OutputStream os = response.getOutputStream();
            bos.writeTo(os);
            os.flush();
            os.close();
        }
    }

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

}

From source file:bookshopautomationsoftware.GenerateReceipt.java

private static void addMetaData(Document document) {
    document.addTitle("RECEPIT ");
    document.addSubject("Using iText");
    document.addKeywords("Java, PDF, iText");
    document.addAuthor("Ramanth");
    document.addCreator("Ramanth");
}

From source file:climbingcompranking.model.ranking.RankingGenerator.java

License:Open Source License

public void createRankingPDF(String competitionName, CompetitionType compType) {
    doTheRanking(compType);//  w  w  w.  j av a  2  s  .c om
    try {
        Document document = new Document(PageSize.A4.rotate()); // Landscape
        Date date = new Date();
        String dateStr = "";
        if (Locale.getDefault().equals(Locale.FRANCE)) {
            dateStr = new SimpleDateFormat("dd-MM-yyyy").format(date);
        } else {
            dateStr = new SimpleDateFormat("yyyy-MM-dd").format(date);
        }
        PdfWriter.getInstance(document,
                new FileOutputStream("data/pdf/" + competitionName + '-' + dateStr + ".pdf"));

        document.open();
        // Meta data
        document.addTitle(competitionName);
        document.addSubject(competitionName + " ranking.");
        document.addKeywords(competitionName + ", ranking, climbingcompetition, climbcompranking");
        document.addAuthor("ClimbingCompRanking - https://github.com/Yaty/ClimbingCompRanking");
        document.addCreator("ClimbingCompRanking - https://github.com/Yaty/ClimbingCompRanking");
        document.addCreationDate();
        document.setMargins(0, 0, 0, 0);

        PdfPCell club = new PdfPCell(new Phrase(I18n.MODEL.getString("Club")));
        PdfPCell climberName = new PdfPCell(new Phrase(I18n.MODEL.getString("ClimberName")));
        PdfPCell ranking = new PdfPCell(new Phrase(I18n.MODEL.getString("Ranking")));

        for (Map.Entry<Category, ArrayList<Climber>> climbersCategory : climbersMap.entrySet()) {
            if (climbersCategory.getValue().isEmpty())
                continue;
            document.newPage();
            // Title
            Paragraph title = new Paragraph(
                    competitionName + " : " + climbersCategory.getKey().getCategoryName());
            title.setAlignment(Element.ALIGN_CENTER);
            title.setFont(new Font(Font.FontFamily.HELVETICA, 36));
            title.setSpacingAfter(20);

            // Table
            PdfPTable table = null;
            switch (compType) {
            case BOULDERING:
            case LEAD:
            case SPEED:
                table = new PdfPTable(3); // Club | Full name | Ranking
                table.addCell(club);
                table.addCell(climberName);
                table.addCell(ranking);
                for (Climber climber : climbersCategory.getValue()) {
                    table.addCell(new PdfPCell(new Phrase(climber.getClubName())));
                    table.addCell(new PdfPCell(new Phrase(climber.getFullName())));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank()))));
                }
                break;
            case LEAD_AND_BOULDERING:
                table = new PdfPTable(6); // Club | Full name | Ranking
                table.addCell(club);
                table.addCell(climberName);
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum"))));
                table.addCell(ranking);
                for (Climber climber : climbersCategory.getValue()) {
                    table.addCell(new PdfPCell(new Phrase(climber.getClubName())));
                    table.addCell(new PdfPCell(new Phrase(climber.getFullName())));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank()))));
                    table.addCell(
                            new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank()))));
                    table.addCell(new PdfPCell(
                            new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType)))));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank()))));
                }
                break;
            case SPEED_AND_BOULDERING:
                table = new PdfPTable(6); // Club | Full name | Ranking
                table.addCell(club);
                table.addCell(climberName);
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum"))));
                table.addCell(ranking);
                for (Climber climber : climbersCategory.getValue()) {
                    table.addCell(new PdfPCell(new Phrase(climber.getClubName())));
                    table.addCell(new PdfPCell(new Phrase(climber.getFullName())));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank()))));
                    table.addCell(
                            new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank()))));
                    table.addCell(new PdfPCell(
                            new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType)))));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank()))));
                }
                break;
            case SPEED_AND_LEAD:
                table = new PdfPTable(6); // Club | Full name | Ranking
                table.addCell(club);
                table.addCell(climberName);
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum"))));
                table.addCell(ranking);
                for (Climber climber : climbersCategory.getValue()) {
                    table.addCell(new PdfPCell(new Phrase(climber.getClubName())));
                    table.addCell(new PdfPCell(new Phrase(climber.getFullName())));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank()))));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank()))));
                    table.addCell(new PdfPCell(
                            new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType)))));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank()))));
                }
                break;
            case COMBINED:
                table = new PdfPTable(7); // Club | Full name | Ranking
                table.addCell(club);
                table.addCell(climberName);
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum"))));
                table.addCell(ranking);
                for (Climber climber : climbersCategory.getValue()) {
                    table.addCell(new PdfPCell(new Phrase(climber.getClubName())));
                    table.addCell(new PdfPCell(new Phrase(climber.getFullName())));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank()))));
                    table.addCell(
                            new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank()))));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank()))));
                    table.addCell(new PdfPCell(
                            new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType)))));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank()))));
                }
                break;
            }

            // Alignment
            for (PdfPRow row : table.getRows()) {
                PdfPCell[] cells = row.getCells();
                for (PdfPCell cellToAlign : cells) {
                    cellToAlign.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cellToAlign.setVerticalAlignment(Element.ALIGN_CENTER);
                }
            }

            table.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.setHeaderRows(1);

            document.add(title);
            document.add(table);
        }
        document.close();
    } catch (DocumentException | FileNotFoundException ex) {
        Logger.getLogger(RankingGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:co.ordinate.printer.NewJFrame.java

private void A4BTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_A4BTNActionPerformed

    new SwingWorker<Object, Object>() {
        String filename;// w  w  w  .  j  ava  2  s.c  om

        @Override
        protected void done() {

            ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. ");

        }

        @Override
        protected Object doInBackground() throws Exception {

            Document doc = new Document();
            try {
                PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("A4.pdf"));
                doc.open();
                doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : ");
                doc.addSubject("Confidential Report Eyes Only");
                doc.addKeywords("");
                doc.addAuthor("SOS");
                doc.addCreator("SOS");

                // A4 = 210mm x 297mm ~ 605points x 855points
                doc.setPageSize(PageSize.A4);
                doc.setMargins(10f, 10f, 10f, 10f);

                /////////////////////////////////////////////////////////////
                int pageno = 1;

                for (int i = 0; i == pageno; i++) {

                    //    doc.add(imageRight);
                }

                PdfContentByte cb = writer.getDirectContent();

                int i = 1;
                while (i <= pageno) {
                    doc.newPage();

                    i++;
                }
                BaseFont labelFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", true);
                float width = doc.getPageSize().getWidth();
                float height = doc.getPageSize().getHeight();
                for (float h = 0; h <= height; h++) {
                    for (float w = 0; w <= width; w++) {
                        cb.beginText();
                        // cb.setColorFill(TITLE_COLOR);
                        cb.setFontAndSize(labelFont, 2);
                        cb.setTextMatrix(w, h);

                        cb.showText(String.valueOf(h) + ":" + String.valueOf(w));
                        cb.endText();
                        w += 15;
                    }
                    h += 2;
                }
                cb.beginText();
                // cb.setColorFill(TITLE_COLOR);
                cb.setFontAndSize(labelFont, 4);
                cb.setTextMatrix(20f, 220f);
                cb.showText("abcd");
                cb.endText();

            } catch (Exception e) {
                System.err.println(e.getMessage());

                ConsoleMsg(e.getMessage());
            } finally {
                doc.close();
            }

            ConsoleMsg("PDF... GENERATED");

            return null;
            //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }.execute();

    // TODO add your handling code here:
}

From source file:co.ordinate.printer.NewJFrame.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    new SwingWorker<Object, Object>() {
        String filename;/*ww w  .  j av a2 s  .  co m*/

        @Override
        protected void done() {

            ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. ");

        }

        @Override
        protected Object doInBackground() throws Exception {

            Document doc = new Document();
            try {
                PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("letter.pdf"));
                doc.open();
                doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : ");
                doc.addSubject("Confidential Report Eyes Only");
                doc.addKeywords("");
                doc.addAuthor("SOS");
                doc.addCreator("SOS");

                // A4 = 210mm x 297mm ~ 605points x 855points
                doc.setPageSize(PageSize.LETTER);
                doc.setMargins(10f, 10f, 10f, 10f);

                /////////////////////////////////////////////////////////////
                int pageno = 1;

                for (int i = 0; i == pageno; i++) {

                    //    doc.add(imageRight);
                }

                PdfContentByte cb = writer.getDirectContent();

                int i = 1;
                while (i <= pageno) {
                    doc.newPage();

                    i++;
                }
                BaseFont labelFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", true);
                float width = doc.getPageSize().getWidth();
                float height = doc.getPageSize().getHeight();
                for (float h = 0; h <= height; h++) {
                    for (float w = 0; w <= width; w++) {
                        cb.beginText();
                        // cb.setColorFill(TITLE_COLOR);
                        cb.setFontAndSize(labelFont, 4);
                        cb.setTextMatrix(w, h);

                        cb.showText(String.valueOf(h) + ":" + String.valueOf(w));
                        cb.endText();
                        w += 25;
                    }
                    h += 5;
                }
                cb.beginText();
                // cb.setColorFill(TITLE_COLOR);
                cb.setFontAndSize(labelFont, 4);
                cb.setTextMatrix(20f, 220f);
                cb.showText("abcd");
                cb.endText();

            } catch (Exception e) {
                System.err.println(e.getMessage());

                ConsoleMsg(e.getMessage());
            } finally {
                doc.close();
            }

            ConsoleMsg("PDF... GENERATED");

            return null;
            //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }.execute();

    // TODO add your handling code here:
}

From source file:co.ordinate.printer.NewJFrame.java

private void printA6Sheet() {
    new SwingWorker<Object, Object>() {
        String filename;/*from  ww  w  .j  a va 2s.com*/

        @Override
        protected void done() {

            ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. ");
            System.err.println("Printing Done");
        }

        @Override
        protected Object doInBackground() throws Exception {

            Document doc = new Document();
            try {
                PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("A6.pdf"));
                doc.open();
                doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : ");
                doc.addSubject("Confidential Report Eyes Only");
                doc.addKeywords("");
                doc.addAuthor("SOS");
                doc.addCreator("SOS");

                // A4 = 210mm x 297mm ~ 605points x 855points
                doc.setPageSize(PageSize.A5);
                doc.setMargins(10f, 10f, 10f, 10f);

                /////////////////////////////////////////////////////////////
                int pageno = 1;

                for (int i = 0; i == pageno; i++) {

                    //    doc.add(imageRight);
                }

                PdfContentByte cb = writer.getDirectContent();

                int i = 1;
                while (i <= pageno) {
                    doc.newPage();

                    i++;
                }
                BaseFont labelFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", true);
                float width = doc.getPageSize().getWidth();
                float height = doc.getPageSize().getHeight();
                for (float h = 0; h <= height; h++) {
                    for (float w = 0; w <= width; w++) {
                        cb.beginText();
                        // cb.setColorFill(TITLE_COLOR);
                        cb.setFontAndSize(labelFont, 4);
                        cb.setTextMatrix(w, h);

                        cb.showText(String.valueOf(h) + ":" + String.valueOf(w));
                        cb.endText();
                        w += 30;
                    }
                    h += 8;
                }
                cb.beginText();
                // cb.setColorFill(TITLE_COLOR);
                cb.setFontAndSize(labelFont, 4);
                cb.setTextMatrix(20f, 220f);
                cb.showText("abcd");
                cb.endText();

            } catch (Exception e) {
                System.err.println(e.getMessage());

                ConsoleMsg(e.getMessage());
            } finally {
                doc.close();
            }

            ConsoleMsg("PDF... GENERATED");
            System.err.println("Printing Done");
            return null;
            //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }.execute(); // TODO add your handling code here:

}

From source file:co.unicauca.proyectobase.entidades.MetodosPDF.java

public void createPdf(String filename) throws IOException, DocumentException {
    // step 1: Crear el objeto
    Document document = new Document();
    // step 2: instanciar para escritura con el objeto creado 
    PdfWriter.getInstance(document, new FileOutputStream(filename));
    // step 3: agregar los metadatos
    document.addTitle("Hello World example");
    document.addAuthor("Bruno Lowagie");
    document.addSubject("This example shows how to add metadata");
    document.addKeywords("Metadata, iText, PDF");
    document.addCreator("My program using iText");
    document.open();/* w  ww.  ja  v  a  2 s.com*/
    // step 4: agregar el conteido, en este caso "Parrafo 1"
    document.add(new Paragraph("Parrafo 1"));
    // step 5: cerrar el archivo que se creo
    document.close();
}