Example usage for com.itextpdf.kernel.pdf PdfWriter PdfWriter

List of usage examples for com.itextpdf.kernel.pdf PdfWriter PdfWriter

Introduction

In this page you can find the example usage for com.itextpdf.kernel.pdf PdfWriter PdfWriter.

Prototype

public PdfWriter(String filename) throws FileNotFoundException 

Source Link

Document

Create a PdfWriter writing to the passed filename and with default writer properties.

Usage

From source file:com.tcay.slalom.UI.PDF.PDF_Results.java

License:Open Source License

public void doit(String title, ArrayList<RaceRun> runs, boolean breakOnClassChange) {
    Document doc = null;/*  w w  w. j a v a2s  .c o  m*/
    Table table = null;

    try {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        // new PDF_Results().manipulatePdf(DEST);

        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(DEST));
        //Document
        doc = new Document(pdfDoc);

        table = new Table(9); // # of columns
        // for (int i = 0; i < 16; i++) {
        //     table.addCell("hi");
        // }

    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
    }

    String lastBoatClass = null;
    for (RaceRun r : runs) {

        float totalTime;

        if (breakOnClassChange) {
            if (lastBoatClass != null) {
                if (lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0)
                    ;
                //   log.info("---");
            }
            lastBoatClass = r.getBoat().getBoatClass();
        }
        totalTime = (float) r.getTotalPenalties();
        totalTime += r.getElapsed();
    }

    try {

        ArrayList<Result> sorted = Race.getInstance().getTempResults();
        for (Result r : sorted) {
            if (true || breakOnClassChange) { //Fixme  constant true
                if (lastBoatClass != null) {
                    if (lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0)
                        ;
                    //                            output.newLine();
                }
                if (lastBoatClass == null || lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0) {
                    //                        output.write(r.getBoat().getBoatClass());
                    //                        output.newLine();
                }
                lastBoatClass = r.getBoat().getBoatClass();
            }
            String s1;

            //                Cell cell23 = new Cell(1, 6).add("a Class ???multi 1,3 and 1,4");
            //                table.addCell(cell23);
            //                table.startNewRow();

            s1 = String.format("%1$3s", r.getBoat().getRacer().getBibNumber());
            table.addCell(s1);

            String s = r.getBoat().getRacer().getShortName();
            s1 = String.format("%1$-15s", s);
            table.addCell(s1);

            s1 = r.getRun1().getResultString();
            table.addCell(s1);

            s1 = r.getRun1().getPenaltyString();
            table.addCell(s1);

            s1 = r.getRun1().getTotalTimeString();
            table.addCell(s1);

            if (r.getRun2() != null) {
                table.startNewRow();

                table.addCell(".");
                table.addCell("..");
                s1 = r.getRun2().getResultString();
                table.addCell(s1);

                s1 = r.getRun2().getPenaltyString();
                table.addCell(s1);

                s1 = r.getRun2().getTotalTimeString();
                table.addCell(s1);

            }
            //                else {
            //    table.addCell("")//;

            //}

            table.startNewRow();

            /// todo must integrate TH results before sort  - DONE VERIFY 10/11/2013
            //                output.write("   best=");
            //                s1 = r.getBestRun() != null ? r.getBestRun().formatTimeTotalOnly() : RaceRun.TIME_ONLY_FILL;
            //                output.write(s1);

            //                if (r.getBestRun().getPhotoCellRaceRun() != null) {    /// todo must integrate TH results before sort
            //                    output.write(ResultsTable.TIMINGMODE_AUTOMATIC);
            //                }
            //                output.newLine();
        }

        PdfFont f = PdfFontFactory.createFont(FontConstants.HELVETICA);
        Cell cell = new Cell(1, 3);

        cell.add(new Paragraph("Class K1 ... or whateever")).setFont(f).setFontSize(13)
                .setFontColor(DeviceGray.WHITE).setBackgroundColor(DeviceGray.BLACK);
        //  .setTextAlignment(TextAlignment.CENTER);

        table.addHeaderCell(cell);

        /*            for (int i = 0; i < 2; i++) {
        Cell[] headerFooter = new Cell[] {
                new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("#"),
                new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("Key"),
                new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("Value")
        };
        for (Cell hfCell : headerFooter) {
            if (i == 0) {
                table.addHeaderCell(hfCell);
            } else {
                table.addFooterCell(hfCell);
            }
        }
                    }
                    for (int counter = 1; counter < 20; counter++) {
        table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add(String.valueOf(counter)));
        table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add("key " + counter));
        table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add("value " + counter));
                    }
                
        */

        doc.add(table);

        doc.close();

    } catch (Exception e) {
        System.out.println(e);
        System.out.println(e.getStackTrace());
        e.printStackTrace();

        //           log.write(e);
    } finally {
        try {
            //                output.close();
        } catch (Exception ex) {
            System.out.println(ex);
            System.out.println(ex.getStackTrace());

            ex.printStackTrace();

        }
    }

}

From source file:controller.PasesDeCortesiaController.java

public void exportPDF() throws RemoteException, NotBoundException, FileNotFoundException, IOException {
    Registry reg = LocateRegistry.getRegistry(host, 27019);
    oasiscrud.oasisrimbd inter = (oasiscrud.oasisrimbd) reg.lookup("OasisSev");
    FileChooser file = new FileChooser();
    file.getExtensionFilters().add(new FileChooser.ExtensionFilter("Documento PDF", " *.pdf"));
    File f = file.showSaveDialog(null);
    PdfWriter writer = new PdfWriter(f.getAbsolutePath());
    PdfDocument pdf = new PdfDocument(writer);
    pdf.setDefaultPageSize(PageSize.LETTER);
    Document document = new Document(pdf);
    com.itextpdf.layout.element.Image img = new com.itextpdf.layout.element.Image(
            ImageDataFactory.create(getClass().getResource("/images/pdf-logo.png")));
    img.setHorizontalAlignment(HorizontalAlignment.CENTER);
    document.add(img);/*  w  w w.j a v  a  2s  .  co  m*/
    generaTitulo(document, "Lista de Pases de Cortesia");
    document.add(new Paragraph("\n"));
    Table t = generaCabezera(Arrays.asList("Nombre", "Cedula", "Telefono", "Codigo", "Invitados", "Fecha"));
    document.add(t);
    for (int i = 0; i < tabla.getItems().size(); i++) {
        generaPaseCortesia(document, tabla.getItems().get(i));
        white *= -1;
    }

    document.close();
}

From source file:controller.ReporteDiarioController.java

public void generaPDF(ActionEvent evt)
        throws FileNotFoundException, MalformedURLException, IOException, RemoteException, NotBoundException {

    Registry reg = LocateRegistry.getRegistry(host, 27019);
    oasiscrud.oasisrimbd inter = (oasiscrud.oasisrimbd) reg.lookup("OasisSev");

    FileChooser file = new FileChooser();
    file.getExtensionFilters().add(new FileChooser.ExtensionFilter("Documento PDF", " *.PDF"));
    File f = file.showSaveDialog(null);
    PdfWriter writer = new PdfWriter(f.getAbsolutePath());

    PdfDocument pdf = new PdfDocument(writer);
    pdf.setDefaultPageSize(PageSize.LETTER.rotate());

    Document document = new Document(pdf);

    Cell c;//from w  ww . j  a va  2 s.c om
    Table tc;
    Paragraph p = new Paragraph();
    Image img = new Image(ImageDataFactory.create(getClass().getResource("/images/pdf-logo.png")));
    img.setHorizontalAlignment(HorizontalAlignment.CENTER);
    document.add(img);

    document.add(new Paragraph("\n"));

    tc = new Table(1);
    tc.addCell(generaCabezera("Reporte del dia "
            + date.getValue().getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault()) + " "
            + date.getValue().format(DateTimeFormatter.ISO_LOCAL_DATE)));
    document.add(tc);

    generaTitulo(document, "Detalles de asistencias General");
    generaTablaAsistencia(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de Aperturas de mesas");
    generaTablaAperturaMesas(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de Pases generados");
    generaTablaPases(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de Autorizaciones");
    generaTablaAutorizaciones(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de accesos al sistema");
    generaTablaAcceso(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de busquedas en el sistema");
    generaTablaBusqueda(document);

    document.close();
    System.out.println(f.getAbsolutePath());
    close(evt);
}

From source file:controller.ReporteFechaController.java

public void generaPDF(ActionEvent evt)
        throws FileNotFoundException, MalformedURLException, IOException, RemoteException, NotBoundException {

    Registry reg = LocateRegistry.getRegistry(host, 27019);
    oasiscrud.oasisrimbd inter = (oasiscrud.oasisrimbd) reg.lookup("OasisSev");

    FileChooser file = new FileChooser();
    file.getExtensionFilters().add(new FileChooser.ExtensionFilter("Documento PDF", " *.PDF"));
    File f = file.showSaveDialog(null);
    PdfWriter writer = new PdfWriter(f.getAbsolutePath());

    PdfDocument pdf = new PdfDocument(writer);
    pdf.setDefaultPageSize(PageSize.LETTER.rotate());

    Document document = new Document(pdf);

    Cell c;// ww  w .j ava  2s . c o m
    Table tc;
    Paragraph p = new Paragraph();
    Image img = new Image(ImageDataFactory.create(getClass().getResource("/images/pdf-logo.png")));
    img.setHorizontalAlignment(HorizontalAlignment.CENTER);
    document.add(img);

    document.add(new Paragraph("\n"));

    tc = new Table(1);
    tc.addCell(generaCabezera("Reporte desde el dia "
            + from.getValue().getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault()) + " "
            + from.getValue().format(DateTimeFormatter.ISO_LOCAL_DATE) + " hasta el dia "
            + to.getValue().getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault()) + " "
            + to.getValue().format(DateTimeFormatter.ISO_LOCAL_DATE)));
    document.add(tc);

    generaTitulo(document, "Detalles de asistencias General");
    generaTablaAsistencia(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de Aperturas de mesas");
    generaTablaAperturaMesas(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de Pases generados");
    generaTablaPases(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de Autorizaciones");
    generaTablaAutorizaciones(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de accesos al sistema");
    generaTablaAcceso(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de busquedas en el sistema");
    generaTablaBusqueda(document);

    document.close();
    System.out.println(f.getAbsolutePath());
    close(evt);
}

From source file:controller.ReporteMesController.java

public void generaPDF(ActionEvent evt)
        throws FileNotFoundException, MalformedURLException, IOException, RemoteException, NotBoundException {

    Registry reg = LocateRegistry.getRegistry(host, 27019);
    oasiscrud.oasisrimbd inter = (oasiscrud.oasisrimbd) reg.lookup("OasisSev");

    FileChooser file = new FileChooser();
    file.getExtensionFilters().add(new FileChooser.ExtensionFilter("Documento PDF", " *.PDF"));
    File f = file.showSaveDialog(null);
    PdfWriter writer = new PdfWriter(f.getAbsolutePath());

    PdfDocument pdf = new PdfDocument(writer);
    pdf.setDefaultPageSize(PageSize.LETTER.rotate());

    Document document = new Document(pdf);

    Cell c;/*from w w w.jav a 2s  .c  o m*/
    Table tc;
    Paragraph p = new Paragraph();
    Image img = new Image(ImageDataFactory.create(getClass().getResource("/images/pdf-logo.png")));
    img.setHorizontalAlignment(HorizontalAlignment.CENTER);
    document.add(img);

    document.add(new Paragraph("\n"));

    tc = new Table(1);
    tc.addCell(generaCabezera("Reporte del mes " + cbmes.getSelectionModel().getSelectedItem() + " del ao "
            + cbano.getSelectionModel().getSelectedItem()));
    document.add(tc);

    generaTitulo(document, "Detalles de asistencias General");
    generaTablaAsistencia(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de Aperturas de mesas");
    generaTablaAperturaMesas(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de Pases generados");
    generaTablaPases(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de Autorizaciones");
    generaTablaAutorizaciones(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de accesos al sistema");
    generaTablaAcceso(document);
    pdf.addNewPage();
    document.add(new AreaBreak());
    generaTitulo(document, "Detalles de busquedas en el sistema");
    generaTablaBusqueda(document);
    document.close();
    System.out.println(f.getAbsolutePath());
    close(evt);
}

From source file:controller.ReservaController.java

public void exportPDF() throws RemoteException, NotBoundException, FileNotFoundException, IOException {
    Registry reg = LocateRegistry.getRegistry(host, 27019);
    oasiscrud.oasisrimbd inter = (oasiscrud.oasisrimbd) reg.lookup("OasisSev");
    FileChooser file = new FileChooser();
    file.getExtensionFilters().add(new FileChooser.ExtensionFilter("Documento PDF", " *.pdf"));
    File f = file.showSaveDialog(null);
    PdfWriter writer = new PdfWriter(f.getAbsolutePath());
    PdfDocument pdf = new PdfDocument(writer);
    pdf.setDefaultPageSize(PageSize.LETTER);
    Document document = new Document(pdf);
    com.itextpdf.layout.element.Image img = new com.itextpdf.layout.element.Image(
            ImageDataFactory.create(getClass().getResource("/images/pdf-logo.png")));
    img.setHorizontalAlignment(HorizontalAlignment.CENTER);
    document.add(img);//from   ww  w . ja v a  2 s.co  m
    generaTitulo(document, "Lista de reservaciones");
    document.add(new Paragraph("\n"));
    Table t = generaCabezera(
            Arrays.asList("Titular", "Cedula", "Telefono", "Plan", "Invitados", "Fecha", "Observaciones"));
    document.add(t);
    for (int i = 0; i < table.getItems().size(); i++) {
        generaReservas(document, (Reserva) table.getItems().get(i));
        white *= -1;
    }

    document.close();
}

From source file:controller.VisitasController.java

public void generaPDF(ActionEvent evt)
        throws FileNotFoundException, MalformedURLException, IOException, RemoteException, NotBoundException {

    Registry reg = LocateRegistry.getRegistry(host, 27019);
    oasiscrud.oasisrimbd inter = (oasiscrud.oasisrimbd) reg.lookup("OasisSev");

    FileChooser file = new FileChooser();
    file.getExtensionFilters().add(new FileChooser.ExtensionFilter("Documento PDF", " *.PDF"));
    File f = file.showSaveDialog(null);
    PdfWriter writer = new PdfWriter(f.getAbsolutePath());

    PdfDocument pdf = new PdfDocument(writer);
    pdf.setDefaultPageSize(PageSize.LETTER.rotate());

    Document document = new Document(pdf);

    com.itextpdf.layout.element.Cell c;/*from  w ww .  ja v a  2s  .c om*/
    Table tc;
    Paragraph p = new Paragraph();
    Image img = new Image(ImageDataFactory.create(getClass().getResource("/images/pdf-logo.png")));
    img.setHorizontalAlignment(com.itextpdf.layout.property.HorizontalAlignment.CENTER);
    document.add(img);

    document.add(new Paragraph("\n"));

    generaTitulo(document, "Detalles de asistencias General");
    generaTablaAsistencia(document);
    pdf.addNewPage();
    document.add(new AreaBreak());

    document.close();
    System.out.println(f.getAbsolutePath());
}

From source file:dbchubreast_web.controller.download.DownloadFichesPatientsPdf.java

License:Open Source License

/** ====================================================================================== */

private void generatePdf(HttpServletResponse response, List<String> listIdPatients) throws IOException {

    String fileName = fileService.generateFileName("PROBREAST_fiches_patients", "pdf");

    response.setHeader("Content-disposition", "attachment; filename=" + fileName);
    response.setContentType("application/pdf");

    PdfWriter writer = new PdfWriter(response.getOutputStream());
    PdfDocument pdfDoc = new PdfDocument(writer);
    Document document = new Document(pdfDoc);

    pdfService.createHeaderFooter(pdfDoc, document);
    pdfService.createPdf(listIdPatients, document, null, "confidentielle");

    document.close();// ww  w .  java2 s  . c  o m
    response.flushBuffer();
}

From source file:dbchubreast_web.controller.PdfController.java

License:Open Source License

/** ====================================================================================== */

@RequestMapping(value = "/pdf/patient/{idPatient}", method = RequestMethod.GET)
public void downloadPdf(Model model, @PathVariable String idPatient, HttpServletRequest request,
        HttpServletResponse response) throws IOException {

    String fileName = "fiche_patient_" + idPatient + ".pdf";
    response.setHeader("Content-disposition", "attachment; filename=" + fileName);
    response.setContentType("application/pdf");

    PdfWriter writer = new PdfWriter(response.getOutputStream());
    PdfDocument pdfDoc = new PdfDocument(writer);
    Document document = new Document(pdfDoc);

    pdfService.createHeaderFooter(pdfDoc, document);

    List<String> listIdPatients = new ArrayList<String>();
    listIdPatients.add(idPatient);/* w  ww .j  a  v a2 s. co m*/

    List<ChuPatient> listPatients = patientService.findAsList(idPatient);

    consistencyService.clearMessages();
    consistencyService.checkConsistency(listPatients);

    pdfService.createPdf(listIdPatients, document, consistencyService.getMapMessages(), "confidentielle");
    // pdfService.createPdf(listIdPatients, document, "publique");
    document.close();
    response.flushBuffer();

}

From source file:machinetoolstore.core.util.PdfGenerator.java

public static boolean getGeneratedPdfByArtifact(ThreeRollMill artifact, String fileName) throws Exception {
    PdfWriter writer = new PdfWriter(GENERATED_FILES_PATH + fileName);
    PdfDocument pdfDocument = new PdfDocument(writer);
    Document document = new Document(pdfDocument, PageSize.A4);

    document.setMargins(15, 15, 15, 40);
    PdfFont mainFont = PdfFontFactory.createFont(FONTS_PATH + "calibril.ttf", "cp1251", false);

    //Header/*from w  w w  .ja  v  a 2  s.c o m*/
    Paragraph headerParagraph = new Paragraph(artifact.getBrand() + " " + artifact.getModel());
    headerParagraph.setItalic();
    headerParagraph.setTextAlignment(TextAlignment.CENTER);
    headerParagraph.setFont(mainFont);
    headerParagraph.setFontSize(20);
    document.add(headerParagraph);

    //Image block witch characteristic
    Table table = new Table(3);
    table.setWidthPercent(100);

    //Image cell
    Cell imageCell = new Cell();
    imageCell.setBorder(Border.NO_BORDER);
    Image machineImage = new Image(ImageDataFactory.create(IMAGE_PATH + artifact.getMainPhoto()));
    machineImage.setWidth(100);
    machineImage.setHeight(100);
    imageCell.add(machineImage);

    //Main characteristic cell
    Cell mainCharacteristicCell = new Cell();
    List mainCharacteristicList = new List().setSymbolIndent(5).setListSymbol("\uFFFF").setFont(mainFont)
            .setFontSize(12);
    mainCharacteristicList.add("ID:").add(":").add(" ?:")
            .add("?:").add("??:").add(", $:");
    mainCharacteristicCell.add(mainCharacteristicList);

    Cell valuesCell = new Cell();
    List valuesList = new List().setSymbolIndent(5).setListSymbol("\uFFFF").setFont(mainFont).setFontSize(12);
    valuesList.add(artifact.getId().toString()).add(artifact.getManufacturer())
            .add(artifact.getYearOfIssue().toString()).add(artifact.getLocation())
            .add(artifact.getMachineState()).add(artifact.getMachinePrice().toString());
    valuesCell.add(valuesList);

    table.addCell(imageCell);
    table.addCell(mainCharacteristicCell);
    table.addCell(valuesCell);

    //Paragraph
    Paragraph contentParagraph = new Paragraph("? ?");
    contentParagraph.setItalic();
    contentParagraph.setTextAlignment(TextAlignment.CENTER);
    contentParagraph.setFont(mainFont);
    contentParagraph.setFontSize(14);
    contentParagraph.setFixedPosition(1, 635, 600);
    document.add(contentParagraph);

    //Main table
    Table mainTable = new Table(2);
    mainTable.setFont(mainFont);
    mainTable.setFontSize(10);
    mainTable.setMarginTop(35);
    mainTable.addCell(" ?").addCell(artifact.getType());
    mainTable.addCell(" , ")
            .addCell(artifact.getMaterialThickness().toString());
    mainTable.addCell(" , ").addCell(artifact.getMaterialWidth().toString());
    mainTable.addCell("? , /").addCell(artifact.getBendingSpeed().toString());
    mainTable.addCell("Min   max ?, ")
            .addCell(artifact.getMinDiameterMaxBend().toString());
    mainTable.addCell("  , ")
            .addCell(artifact.getTopRollDiameter().toString());
    mainTable.addCell(" ? , ")
            .addCell(artifact.getMiddleRollDiameter().toString());
    mainTable.addCell("???   ? , ")
            .addCell(artifact.getDistanceOfBottomTwoRolls().toString());
    mainTable.addCell(
            "?  ? ?  ?, ")
            .addCell(artifact.getMaterialProofStress().toString());
    mainTable.addCell("?  ?, ")
            .addCell(artifact.getMainEnginePower().toString());
    mainTable.addCell(" , ").addCell(artifact.getMachineDimensions());
    mainTable.addCell("? ?, ").addCell(artifact.getMachineWeight().toString());
    mainTable.addCell("?").addCell(artifact.getDescription());

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

    return true;
}