Example usage for com.itextpdf.text PageSize A4

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

Introduction

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

Prototype

Rectangle A4

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

Click Source Link

Document

This is the a4 format

Usage

From source file:Capa_Modelo.Reportes.java

public void generarReporteInventario() {
    Connection con;/*from w w w  .  j  a  va2 s. c  o  m*/
    ResultSet res;
    Statement sentencia;
    Document documento = new Document(PageSize.A4);
    con = ConexionDB.GetConnection();
    try {
        sentencia = con.createStatement();
        res = sentencia.executeQuery(
                "SELECT Cantidad, Cantidadmin,  Cantidadmax, Medicamento.Nombre, Medicamento.FechaElaboracion, Medicamento.Composicion, Medicamento.FechaVencimiento, Medicamento.Laboratorio FROM Inventario inner join Medicamento on Inventario.ID_Medicamento = Medicamento.ID_Medicamento ");
        PdfWriter.getInstance(documento, new FileOutputStream(
                "reportes/reporte_de_inventario " + fechaActual() + " " + horaActual() + ".pdf"));
        documento.open();
        float[] columnWidths = { 2, 2, 2, 2, 2, 2, 2, 2 };
        PdfPTable table = new PdfPTable(columnWidths);
        table.setWidthPercentage(100);
        table.getDefaultCell().setUseAscender(true);
        table.getDefaultCell().setUseDescender(true);
        Font f = new Font(Font.FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.GRAYWHITE);
        PdfPCell cell = new PdfPCell(new Phrase("Reporte de Medicamentos", f));
        cell.setBackgroundColor(GrayColor.GRAYBLACK);
        cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        cell.setColspan(8);
        table.addCell(cell);
        table.getDefaultCell().setBackgroundColor(new GrayColor(0.75f));
        for (int i = 0; i < 2; i++) {
            table.addCell("Medicamento");
            table.addCell("Composicion");
            table.addCell("Laboratorio");
            table.addCell("Fecha de Elaboracion");
            table.addCell("Fecha de Vencimiento");
            table.addCell("Cantidad minima");
            table.addCell("Cantidad actual");
            table.addCell("Cantidad maxima");
        }
        table.setHeaderRows(3);
        table.setFooterRows(1);
        table.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE);
        table.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        while (res.next()) {
            table.addCell(res.getString("Nombre"));
            table.addCell(res.getString("Composicion"));
            table.addCell(res.getString("Laboratorio"));
            table.addCell(res.getString("FechaElaboracion"));
            table.addCell(res.getString("FechaVencimiento"));
            table.addCell(res.getString("Cantidadmin"));
            table.addCell(res.getString("Cantidad"));
            table.addCell(res.getString("Cantidadmax"));
        }
        documento.add(table);
        documento.close();
        JOptionPane.showMessageDialog(null, "Reporte de Inventario generado correctamente");
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, "Error al conectar con la base de datos");
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar la ruta del archivo");
    } catch (DocumentException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar el archivo");
    }

}

From source file:Capa_Modelo.Reportes.java

public void generarReporteVencimiento() {
    Connection con;//from w  w  w .j  av  a 2s  . c  o m
    ResultSet res;
    Statement sentencia;
    Document documento = new Document(PageSize.A4);
    con = ConexionDB.GetConnection();
    try {
        sentencia = con.createStatement();
        res = sentencia.executeQuery(
                "SELECT Cantidad, Cantidadmin, Cantidadmax, Medicamento.Nombre, Medicamento.FechaElaboracion, Medicamento.FechaVencimiento, Medicamento.Laboratorio FROM Inventario inner join Medicamento on Inventario.ID_Medicamento = Medicamento.ID_Medicamento ");
        PdfWriter.getInstance(documento, new FileOutputStream(
                "reportes/reporte_de_vencimiento " + fechaActual() + " " + horaActual() + ".pdf"));
        documento.open();
        float[] columnWidths = { 2, 2, 2, 2 };
        PdfPTable table = new PdfPTable(columnWidths);
        table.setWidthPercentage(100);
        table.getDefaultCell().setUseAscender(true);
        table.getDefaultCell().setUseDescender(true);
        Font f = new Font(Font.FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.GRAYWHITE);
        PdfPCell cell = new PdfPCell(new Phrase("Reporte de Vencimiento", f));
        cell.setBackgroundColor(GrayColor.GRAYBLACK);
        cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        cell.setColspan(4);
        table.addCell(cell);
        table.getDefaultCell().setBackgroundColor(new GrayColor(0.75f));
        for (int i = 0; i < 2; i++) {
            table.addCell("Medicamento");
            table.addCell("Laboratorio");
            table.addCell("Fecha de Vencimiento");
            table.addCell("Cantidad actual");
        }
        table.setHeaderRows(3);
        table.setFooterRows(1);
        table.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE);
        table.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        while (res.next()) {
            if (vencido(res.getDate("FechaVencimiento"))) {
                table.addCell(res.getString("Nombre"));
                table.addCell(res.getString("Laboratorio"));
                table.addCell(res.getString("FechaVencimiento"));
                table.addCell(res.getString("Cantidad"));
            }
        }
        documento.add(table);
        documento.close();
        JOptionPane.showMessageDialog(null, "Reporte de Vencimiento generado correctamente");
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, "Error en conectar con base de datos");
    } catch (DocumentException ex) {
        Logger.getLogger(Reportes.class.getName()).log(Level.SEVERE, null, "El documento no se pudo generar");
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Reportes.class.getName()).log(Level.SEVERE, null, "EL archivo no se abri");
    }
}

From source file:Capa_Modelo.Reportes.java

public void generarReporteConsumoMedicamentos() {
    DecimalFormat df = new DecimalFormat("####0.00");
    Connection con;/* www . ja  va  2s  .c  om*/
    ResultSet res;
    Statement sentencia;
    Document documento = new Document(PageSize.A4);
    double consumo, cantidad;
    double porcentaje;
    consumo = cantidad = 0;
    con = ConexionDB.GetConnection();
    try {
        sentencia = con.createStatement();
        res = sentencia.executeQuery(
                "SELECT Medicamento.Nombre, Medicamento.Composicion, Medicamento.Laboratorio, Inventario.Cantidad, SUM(MedicinaPaciente.Cantidad) as Consumo FROM MedicinaPaciente INNER JOIN Medicamento ON MedicinaPaciente.ID_Medicamento = Medicamento.ID_Medicamento INNER JOIN Inventario ON MedicinaPaciente.ID_Medicamento = Inventario.ID_Medicamento  GROUP BY Medicamento.Nombre, Medicamento.Composicion , Medicamento.Laboratorio, Inventario.Cantidad ORDER BY Consumo");
        PdfWriter.getInstance(documento, new FileOutputStream(
                "reportes/reporte_de_consumo_medicamentos " + fechaActual() + " " + horaActual() + ".pdf"));
        documento.open();
        float[] columnWidths = { 2, 2, 2, 2, 2, 2 };
        PdfPTable table = new PdfPTable(columnWidths);
        table.setWidthPercentage(100);
        table.getDefaultCell().setUseAscender(true);
        table.getDefaultCell().setUseDescender(true);
        Font f = new Font(Font.FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.GRAYWHITE);
        PdfPCell cell = new PdfPCell(new Phrase("Reporte de Consumo Medicamentos", f));
        cell.setBackgroundColor(GrayColor.GRAYBLACK);
        cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        cell.setColspan(8);
        table.addCell(cell);
        table.getDefaultCell().setBackgroundColor(new GrayColor(0.75f));
        for (int i = 0; i < 2; i++) {
            table.addCell("Medicamento");
            table.addCell("Composicion");
            table.addCell("Laboratorio");
            table.addCell("Cantidad");
            table.addCell("Unidades consumidas");
            table.addCell("Porcentaje de consumo");
        }
        table.setHeaderRows(3);
        table.setFooterRows(1);
        table.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE);
        table.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        while (res.next()) {
            consumo = res.getInt("Consumo");
            cantidad = res.getInt("Cantidad");
            porcentaje = consumo / cantidad * 100;
            System.out.println("consumo: " + consumo + " cantidad: " + cantidad + " porcentaje: " + porcentaje);
            table.addCell(res.getString("Nombre"));
            table.addCell(res.getString("Composicion"));
            table.addCell(res.getString("Laboratorio"));
            table.addCell(res.getString("Cantidad"));
            table.addCell(res.getString("Consumo"));
            table.addCell(((df.format(porcentaje))) + "%");

        }
        documento.add(table);
        documento.close();
        JOptionPane.showMessageDialog(null, "Reporte de Consumo de Medicamentos generado correctamente");
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, "Error al conectar con la base de datos");
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar la ruta del archivo");
    } catch (DocumentException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar el archivo");
    }
}

From source file:Capa_Modelo.Reportes.java

public void generarReporteESMedicamentos() {
    Connection con;/*from w  ww  . j  a  va2  s.c  o  m*/
    ResultSet res, res2;
    Statement sentencia;
    Document documento = new Document(PageSize.A4);
    con = ConexionDB.GetConnection();
    try {
        sentencia = con.createStatement();
        res = sentencia.executeQuery(
                "SELECT Medicamento.Nombre, Medicamento.Composicion, Medicamento.Laboratorio, Medicamento.FechaLlegada, Inventario.Cantidad FROM Medicamento INNER JOIN Inventario ON Medicamento.ID_Medicamento = Inventario.ID_Medicamento ORDER BY Inventario.Cantidad, Medicamento.Nombre desc");
        PdfWriter.getInstance(documento, new FileOutputStream("reportes/reporte_de_entrada-salida_medicamentos "
                + fechaActual() + " " + horaActual() + ".pdf"));
        documento.open();
        float[] columnWidths = { 2, 2, 2, 2, 2 };
        PdfPTable table = new PdfPTable(columnWidths);
        table.setWidthPercentage(100);
        table.getDefaultCell().setUseAscender(true);
        table.getDefaultCell().setUseDescender(true);
        Font f = new Font(Font.FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.GRAYWHITE);
        PdfPCell cell = new PdfPCell(new Phrase("Reporte de Entrada de Medicamentos", f));
        cell.setBackgroundColor(GrayColor.GRAYBLACK);
        cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        cell.setColspan(8);
        table.addCell(cell);
        table.getDefaultCell().setBackgroundColor(new GrayColor(0.75f));
        for (int i = 0; i < 2; i++) {
            table.addCell("Medicamento");
            table.addCell("Composicion");
            table.addCell("Laboratorio");
            table.addCell("Fecha de Entrada");
            table.addCell("Cantidad");
        }
        table.setHeaderRows(3);
        table.setFooterRows(1);
        table.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE);
        table.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        while (res.next()) {
            table.addCell(res.getString("Nombre"));
            table.addCell(res.getString("Composicion"));
            table.addCell(res.getString("Laboratorio"));
            table.addCell(res.getString("FechaLlegada"));
            table.addCell(res.getString("Cantidad"));
        }
        documento.add(table);
        documento.newPage();
        res2 = sentencia.executeQuery(
                "SELECT Medicamento.Nombre, Medicamento.Composicion, Medicamento.Laboratorio, MedicinaPaciente.FechaEntrega, SUM(MedicinaPaciente.Cantidad) AS Entregados FROM Medicamento INNER JOIN MedicinaPaciente ON Medicamento.ID_Medicamento = MedicinaPaciente.ID_Medicamento  group by Medicamento.Nombre, Medicamento.Composicion, Medicamento.Laboratorio,MedicinaPaciente.FechaEntrega ORDER BY Entregados");
        float[] columnWidths2 = { 2, 2, 2, 2, 2 };
        PdfPTable table2 = new PdfPTable(columnWidths);
        table2.setWidthPercentage(100);
        table2.getDefaultCell().setUseAscender(true);
        table2.getDefaultCell().setUseDescender(true);
        PdfPCell cell2 = new PdfPCell(new Phrase("Reporte de Salida de Medicamentos", f));
        cell2.setBackgroundColor(GrayColor.GRAYBLACK);
        cell2.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        cell2.setColspan(8);
        table2.addCell(cell2);
        table2.getDefaultCell().setBackgroundColor(new GrayColor(0.75f));
        for (int i = 0; i < 2; i++) {
            table2.addCell("Medicamento");
            table2.addCell("Composicion");
            table2.addCell("Laboratorio");
            table2.addCell("Fecha de Salida");
            table2.addCell("Cantidad");
        }
        table2.setHeaderRows(3);
        table2.setFooterRows(1);
        table2.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE);
        table2.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        while (res2.next()) {
            table2.addCell(res2.getString("Nombre"));
            table2.addCell(res2.getString("Composicion"));
            table2.addCell(res2.getString("Laboratorio"));
            table2.addCell(res2.getString("FechaEntrega"));
            table2.addCell(res2.getString("Entregados"));
        }
        documento.add(table2);
        documento.close();
        JOptionPane.showMessageDialog(null,
                "Reporte de Entrada y Salida de Medicamentos generado correctamente");
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, "Error al conectar con la base de datos");
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar la ruta del archivo");
    } catch (DocumentException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar el archivo");
    }
}

From source file:ci_eletronico.FXMLMainController.java

@FXML
private void handleBtnImprimirCI(ActionEvent event) throws IOException {
    if (null == TbViewGeral.getSelectionModel().getSelectedItem()) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Erro");
        alert.setHeaderText("CI no foi selecionada.");
        alert.setContentText("Favor selecionar uma CI da tabela");
        alert.showAndWait();//from  w w w  .jav a 2s.c o  m
    } else {

        File outfile = null; // variavel para abrir documento pdf aps sua criao

        String strFileName = this.lblNumeroSequencialCI.getText();
        String strUserHome = System.getProperty("user.home") + "\\Downloads\\" + strFileName + ".pdf";
        final Document document = new Document();
        try {
            document.setPageSize(PageSize.A4);
            document.setMargins(10f, 10f, 70f, 40f);
            String strCIAssinatura = TbViewGeral.getSelectionModel().getSelectedItem().getStrp_CoinAssinatura();

            //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:/Temp/teste.pdf"));
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(strUserHome));

            MyFooter evento = new MyFooter(strCIAssinatura);
            writer.setPageEvent(evento);

        } catch (IOException | DocumentException e) {
            System.out.println(e.toString());
            System.out.println(e.getMessage());
        }
        document.open();

        //String htmlString = htmlEditorCI.getHtmlText();
        String strlCITitulo = "";
        strlCITitulo = "<br /><p align=\"center\"><b>" + strFileName + "</b></p>";
        String htmlString = TbViewGeral.getSelectionModel().getSelectedItem().getStrp_Conteudo();
        //String strCIAssinatura = TbViewGeral.getSelectionModel().getSelectedItem().getStrp_CoinAssinatura();

        //            htmlString = htmlString.replace("<br>", "\n");
        //            htmlString = htmlString.replace("<br/>", "\n");
        //            htmlString = htmlString.replace("<br />", "\n");

        htmlString = htmlString.replace("<br>", "<br />");

        //            htmlString = htmlString.replace("<hr>", "<p></p>");
        //            htmlString = htmlString.replace("<hr/>", "<p></p>");
        //            htmlString = htmlString.replace("<hr />", "<p></p>");

        htmlString = htmlString.replace("<hr>", "<hr />");

        htmlString = strlCITitulo.concat(htmlString);

        StringReader in = new StringReader(htmlString);

        try {
            final Paragraph test = new Paragraph();
            XMLWorkerHelper.getInstance().parseXHtml(new ElementHandler() {
                @Override
                public void add(final Writable w) {
                    if (w instanceof WritableElement) {
                        List<Element> elements = ((WritableElement) w).elements();
                        for (Element e : elements) {
                            test.add(e);
                        }
                    }
                }
            }, in);

            document.add(test);
        } catch (IOException | DocumentException e) {
            System.out.println(e.toString());
            System.out.println(e.getMessage());
        }

        document.close();

        outfile = new File(strUserHome);

        //            Alert alert = new Alert(Alert.AlertType.INFORMATION);
        //            alert.setTitle("Informao");
        //            alert.setHeaderText("Imprimir CI: " + strFileName );
        //            alert.setContentText("Arquivo pdf criado com sucesso na pasta Downloads");
        //            alert.showAndWait();

        openArquivo(outfile); // Abrimos o pdf criado para ser visualizado
    }
}

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

License:Open Source License

public void createRankingPDF(String competitionName, CompetitionType compType) {
    doTheRanking(compType);/*from w  w w  . ja v 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:cn.afterturn.easypoi.pdf.styler.PdfExportStylerDefaultImpl.java

License:Apache License

@Override
public Document getDocument() {
    return new Document(PageSize.A4, 36, 36, 24, 36);
}

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;/*from  w ww .  ja va  2  s  .  c  o  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("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:com.algoboss.erp.util.report.PDFExporter.java

License:Apache License

public void export(FacesContext context, DataTable table, String filename, String encodingType)
        throws IOException {
    try {// w  ww  . j a v a2  s .  co m
        Document document = new Document(PageSize.A4, 25f, 25f, 25f, 25f);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);

        if (!document.isOpen()) {
            document.open();
        }
        document.addAuthor("Algo Boss");
        document.addCreator("Real's HowTo");
        document.addSubject("Thanks for your support");
        document.addCreationDate();
        document.addTitle(filename);
        //document.setMargins(1f, 1f, 1f, 1f);
        //document.setPageSize(PageSize.A4);
        document.add(exportPDFTable(context, table, false, false, false, encodingType));
        //document.setMargins(1f, 1f, 1f, 1f);
        //document.setPageSize(PageSize.A4);

        document.close();

        //writePDFToResponse(context.getExternalContext(), baos, filename);
        writePDFToResponseNew(context.getExternalContext(), baos, filename);

    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:com.algoboss.erp.util.report.PDFExporter2.java

License:Apache License

public void export(FacesContext context, DataTable table, String filename, String encodingType)
        throws IOException {
    try {//from ww w  . j  a v a 2 s  .  c  o m
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);

        if (!document.isOpen()) {
            document.open();
        }
        document.setMargins(1f, 1f, 1f, 1f);
        document.setPageSize(PageSize.A4);
        document.add(exportPDFTable(context, table, false, false, true, encodingType));
        document.setMargins(1f, 1f, 1f, 1f);
        document.setPageSize(PageSize.A4);

        document.close();

        //writePDFToResponse(context.getExternalContext(), baos, filename);
        writePDFToResponseNew(context.getExternalContext(), baos, filename);

    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
}