Example usage for com.itextpdf.layout.element Image Image

List of usage examples for com.itextpdf.layout.element Image Image

Introduction

In this page you can find the example usage for com.itextpdf.layout.element Image Image.

Prototype

public Image(ImageData img) 

Source Link

Document

Creates an Image from an image resource, read in from a file with the iText I/O module.

Usage

From source file:cl.a2r.wsmicampov2.dao.TrasladoDAO.java

public static void addPageToGuia(Traslado traslado, List<String> listDiios, Document document,
        Integer cantAnimales) {/*from  w  ww  .j a  va  2 s.com*/

    try {

        Integer identificadorTraslado = traslado.getId();
        String fundoOrigen = traslado.getFundoOrigen();
        String fundoDestino = traslado.getFundoDestino();
        Date fecha = traslado.getFecha();
        String nombreChofer = traslado.getNombreChofer();
        String rutChofer = traslado.getRutChofer();
        String patenteCamion = traslado.getPatenteCamion();
        String patenteAcoplado = traslado.getAcopladoPatente();
        String nombreTransportista = traslado.getNombreTransportista();
        String rutTransportista = traslado.getRutTransportista();

        String imagePath = "/usr/share/MiCampoGuiasUpload/A2RLogo.png";
        //        String imagePath="Z:\\Chilterra\\MiCampoGuias\\A2RLogo.png";

        DateFormat df = new SimpleDateFormat("dd-MM-yyyy hh_mm_ss");
        DateFormat df2 = new SimpleDateFormat("dd-MM-yyyy");
        Date today = Calendar.getInstance().getTime();
        String reportDate = df.format(today);
        String reportDate2 = df2.format(today);

        PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD);

        Text fechaText = new Text("Fecha: " + reportDate2).setTextAlignment(TextAlignment.RIGHT);
        Paragraph paragraphFecha = new Paragraph().add(fechaText);
        paragraphFecha.setTextAlignment(TextAlignment.RIGHT);
        document.add(paragraphFecha);

        Text title = new Text("TRASLADO INTERNO DE ANIMALES No. " + identificadorTraslado).setFont(bold);
        title.setFontSize(12);

        Image a2R = new Image(ImageDataFactory.create(imagePath));
        Paragraph p = new Paragraph("").add(a2R).add(title);

        document.add(p);

        //Datos del traslado
        Table table = new Table(2);

        table.addCell(CellHelper.getCell("Fundo origen: ", fundoOrigen, TextAlignment.LEFT));
        table.addCell(CellHelper.getCell("Fundo destino: ", fundoDestino, TextAlignment.LEFT));

        table.addCell(CellHelper.getCell("Nombre Chofer: ", nombreChofer, TextAlignment.LEFT));
        table.addCell(CellHelper.getCell("Rut Chofer: ", nombreChofer, TextAlignment.LEFT));

        table.addCell(CellHelper.getCell("Patente camin: ", patenteCamion, TextAlignment.LEFT));
        table.addCell(CellHelper.getCell("Patente acoplado: ", patenteAcoplado, TextAlignment.LEFT));

        table.addCell(CellHelper.getCell("Nombre transportista: ", nombreTransportista, TextAlignment.LEFT));
        table.addCell(CellHelper.getCell("Rut transportista: ", rutTransportista, TextAlignment.LEFT));

        document.add(table);

        Paragraph totalAnimales = CellHelper.getBoldParagraph("Cantidad total de animales: ",
                cantAnimales.toString());

        document.add(totalAnimales);

        //Observaciones
        Paragraph observaciones = new Paragraph("Observaciones: ").setBold();
        document.add(observaciones);

        Table observTable = new Table(1);
        observTable.addCell(CellHelper.getCellObservaciones("", TextAlignment.LEFT));
        document.add(observTable);

        Paragraph space1 = new Paragraph("");
        document.add(space1);

        Paragraph space2 = new Paragraph("");
        document.add(space2);

        Paragraph space3 = new Paragraph("");
        document.add(space3);

        Paragraph space4 = new Paragraph("");
        document.add(space4);

    } catch (Exception ex) {

    }

}

From source file:com.js.quickestquail.ui.actions.io.ExportToPDFAction.java

private void writeAll(File outputFile) throws FileNotFoundException, IOException {

    // progress dialog
    JProgressDialog dialog = new JProgressDialog(UI.get(), false);
    dialog.setMaximum(DriveManager.get().getSelected().size());
    dialog.setTitle(java.util.ResourceBundle.getBundle("i18n/i18n").getString("export.pdf"));
    dialog.setVisible(true);/* w  w  w.j a v a 2 s  . c om*/

    // run this in a new Thread
    new Thread() {
        @Override
        public void run() {
            try {
                int nrOfMovies = 0;
                List<Entry<File, String>> entries = new ArrayList<>(
                        DriveManager.get().getSelected().entrySet());
                java.util.Collections.sort(entries, new Comparator<Entry<File, String>>() {
                    @Override
                    public int compare(Entry<File, String> o1, Entry<File, String> o2) {
                        Movie mov1 = CachedMovieProvider.get().getMovieByID(o1.getValue());
                        Movie mov2 = CachedMovieProvider.get().getMovieByID(o2.getValue());
                        return mov1.getTitle().compareTo(mov2.getTitle());
                    }
                });

                PdfWriter writer = new PdfWriter(new FileOutputStream(outputFile));
                PdfDocument pdf = new PdfDocument(writer);
                Document doc = new Document(pdf);

                for (Entry<File, String> en : entries) {
                    Movie mov = CachedMovieProvider.get().getMovieByID(en.getValue());

                    // update progress dialog
                    dialog.setText(mov.getTitle());
                    dialog.setProgress(nrOfMovies);

                    // add table
                    Table table = new Table(new float[] { 0.5f, 0.25f, 0.25f });
                    table.setWidthPercent(100);
                    table.setBorder(Border.NO_BORDER);

                    Cell cell;
                    cell = new Cell(5, 1);
                    cell.setBorder(Border.NO_BORDER);

                    try {
                        Image img = new Image(ImageDataFactory.create(new URL(mov.getPoster())));
                        cell.setNextRenderer(new ImageBackgroundCellRenderer(cell, img));
                    } catch (Exception ex) {
                    }

                    cell.setHeight(160);
                    cell.setWidth(100);

                    table.addCell(cell);

                    cell = new Cell(1, 1).add("Title").setBorder(Border.NO_BORDER);
                    table.addCell(cell);
                    cell = new Cell(1, 1).add(mov.getTitle()).setBorder(Border.NO_BORDER);
                    table.addCell(cell);

                    cell = new Cell(1, 1).add("Year").setBorder(Border.NO_BORDER);
                    table.addCell(cell);
                    cell = new Cell(1, 1).add(mov.getYear() + "").setBorder(Border.NO_BORDER);
                    table.addCell(cell);

                    cell = new Cell(1, 1).add("IMDB ID").setBorder(Border.NO_BORDER);
                    table.addCell(cell);
                    cell = new Cell(1, 1).add(mov.getImdbID()).setBorder(Border.NO_BORDER);
                    table.addCell(cell);

                    cell = new Cell(1, 1).add("IMDB Rating").setBorder(Border.NO_BORDER);
                    table.addCell(cell);
                    cell = new Cell(1, 1).add(mov.getImdbRating() + "").setBorder(Border.NO_BORDER);
                    table.addCell(cell);

                    cell = new Cell(1, 1).add("IMDB Votes").setBorder(Border.NO_BORDER);
                    table.addCell(cell);
                    cell = new Cell(1, 1).add(mov.getImdbVotes() + "").setBorder(Border.NO_BORDER);
                    table.addCell(cell);

                    doc.add(table);

                    nrOfMovies++;
                    if (nrOfMovies % 4 == 0) {
                        doc.add(new AreaBreak());
                    }

                    doc.add(new Paragraph(""));

                }

                // close IO
                doc.close();
                pdf.close();
                writer.close();

                // close dialog
                dialog.setVisible(false);

            } catch (Exception ex) {
            }
        }
    }.start();

}

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 w w .  j ava 2 s .  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 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;//from  w w w  .j  ava2s . 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  .  j a va 2 s .co 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.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   ww w .  ja va 2  s  . c o m
    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: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 ww  w  . j ava  2  s.  co  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;
}

From source file:output.InvoicePDF.java

/**
 *
 * @param dest/*from  w ww. j a  v  a2s  .  co m*/
 * @throws IOException
 */
public void generatePDF(String dest) throws FileNotFoundException, MalformedURLException, IOException {

    PdfWriter writer = new PdfWriter(dest);
    PdfDocument pdf = new PdfDocument(writer);
    Document document = new Document(pdf);
    Image image = new Image(ImageDataFactory.create(LOGO));
    image.setWidthPercent(50);
    image.setHorizontalAlignment(HorizontalAlignment.CENTER);
    document.add(image);
    document.add(clientInformation());
    document.add(quoteSection());
    document.add(new Paragraph(terms()));
    document.close();

}

From source file:ru.waytosky.itext.Main.java

public static void main(String[] args) throws FileNotFoundException, MalformedURLException {
    //        Document document = new Document(PageSize.A4, 20, 20, 20, 20);
    //        PdfWriter.getInstance(document, new FileOutputStream("C:/test.pdf"));
    //        document.open();
    //        Image image = Image.getInstance(getClass().getResource("/logo.png"));
    //        document.add(image);
    //        document.close();

    //Initialize PDF writer

    String dest = "hello.pdf";

    PdfWriter writer = new PdfWriter(dest);

    //Initialize PDF document
    PdfDocument pdf = new PdfDocument(writer);

    // Initialize document
    Document document = new Document(pdf);

    //Add paragraph to the document
    Image image = new Image(ImageDataFactory.create("darksouls.jpg"));
    //                Image.getInstance(getClass().getResource("/logo.png"));
    document.add(image);//from ww w  .j a va  2 s.c  o m

    //Close document
    document.close();
}

From source file:wbs.jsf1.pdf.LottoReceiptBean.java

private void getHeaderImage(Table table) {
    Image headerLogo;//from   w w  w  . j  av a2 s.  co m

    try {
        headerLogo = new Image(ImageDataFactory.create(imagePath)).setAutoScale(true)
                .setBorder(Border.NO_BORDER);
        table.addCell(new Cell().add(headerLogo).setBorder(Border.NO_BORDER));
    } catch (Exception e) {
        LOG.log(Level.WARNING, "cannot find the image file for the pdf");
        table.addCell(new Cell().setBorder(Border.NO_BORDER));
    }

}