Search in sources :

Example 1 with Image

use of com.itextpdf.layout.element.Image in project betca-tpv-core by miw-upm.

the class PdfCoreBuilder method image.

public PdfCoreBuilder image(String fileName) {
    try {
        Image img = new Image(ImageDataFactory.create(new ClassPathResource("imges/" + fileName).getURL()));
        img.setWidth(IMAGE_WIDTH);
        img.setHorizontalAlignment(HorizontalAlignment.CENTER);
        this.document.add(img);
    } catch (IOException e) {
        LogManager.getLogger(this.getClass()).error(String.format("PdfTicketBuilder::addImage. Error when add image to PDF (%s). %s", fileName, e));
        throw new PdfException("Can’t add image to PDF (" + fileName + "). " + e);
    }
    return this;
}
Also used : IOException(java.io.IOException) Image(com.itextpdf.layout.element.Image) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 2 with Image

use of com.itextpdf.layout.element.Image in project betca-tpv-core by miw-upm.

the class PdfCoreBuilder method qrCode.

public PdfCoreBuilder qrCode(String code) {
    BarcodeQRCode barcodeQRCode = new BarcodeQRCode(code.trim());
    Image qcCodeImage = new Image(barcodeQRCode.createFormXObject(this.document.getPdfDocument()));
    qcCodeImage.setHorizontalAlignment(HorizontalAlignment.CENTER);
    qcCodeImage.setWidthPercent(QR_CODE_PERCENT);
    this.document.add(qcCodeImage);
    Paragraph paragraph = new Paragraph(code);
    paragraph.setTextAlignment(TextAlignment.CENTER);
    this.document.add(paragraph);
    return this;
}
Also used : BarcodeQRCode(com.itextpdf.barcodes.BarcodeQRCode) Image(com.itextpdf.layout.element.Image) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 3 with Image

use of com.itextpdf.layout.element.Image in project i7js-highlevel by itext.

the class C03E15_MaryReillyV8 method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    Paragraph p = new Paragraph("Mary Reilly is a maid in the household of Dr. Jekyll: ");
    document.add(p);
    Image img = new Image(ImageDataFactory.create(MARY));
    img.setHorizontalAlignment(HorizontalAlignment.CENTER);
    img.setWidth(UnitValue.createPercentValue(80));
    document.add(img);
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 4 with Image

use of com.itextpdf.layout.element.Image in project i7js-highlevel by itext.

the class C03E19_PagedImages method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    Image img;
    // Animated GIF
    URL url1 = UrlUtil.toURL(TEST1);
    List<ImageData> list = ImageDataFactory.createGifFrames(url1);
    for (ImageData data : list) {
        img = new Image(data);
        document.add(img);
    }
    // JBIG2
    URL url2 = UrlUtil.toURL(TEST2);
    IRandomAccessSource ras2 = new RandomAccessSourceFactory().createSource(url2);
    RandomAccessFileOrArray raf2 = new RandomAccessFileOrArray(ras2);
    int pages2 = Jbig2ImageData.getNumberOfPages(raf2);
    for (int i = 1; i <= pages2; i++) {
        img = new Image(ImageDataFactory.createJbig2(url2, i));
        document.add(img);
    }
    // TIFF
    URL url3 = UrlUtil.toURL(TEST3);
    IRandomAccessSource ras3 = new RandomAccessSourceFactory().createSource(url3);
    RandomAccessFileOrArray raf3 = new RandomAccessFileOrArray(ras3);
    int pages3 = TiffImageData.getNumberOfPages(raf3);
    for (int i = 1; i <= pages3; i++) {
        img = new Image(ImageDataFactory.createTiff(url3, true, i, true));
        document.add(img);
    }
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) RandomAccessFileOrArray(com.itextpdf.io.source.RandomAccessFileOrArray) ImageData(com.itextpdf.io.image.ImageData) TiffImageData(com.itextpdf.io.image.TiffImageData) Jbig2ImageData(com.itextpdf.io.image.Jbig2ImageData) RandomAccessSourceFactory(com.itextpdf.io.source.RandomAccessSourceFactory) IRandomAccessSource(com.itextpdf.io.source.IRandomAccessSource) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) URL(java.net.URL)

Example 5 with Image

use of com.itextpdf.layout.element.Image in project i7js-highlevel by itext.

the class C04E01_DivExample1 method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
    resultSet.remove(0);
    for (List<String> record : resultSet) {
        Div div = new Div().setBorderLeft(new SolidBorder(2)).setPaddingLeft(3).setMarginBottom(10);
        String url = String.format("http://www.imdb.com/title/tt%s", record.get(0));
        Link movie = new Link(record.get(2), PdfAction.createURI(url));
        div.add(new Paragraph(movie.setFontSize(14))).add(new Paragraph(String.format("Directed by %s (%s, %s)", record.get(3), record.get(4), record.get(1))));
        File file = new File(String.format("src/main/resources/img/%s.jpg", record.get(0)));
        if (file.exists()) {
            Image img = new Image(ImageDataFactory.create(file.getPath()));
            img.scaleToFit(10000, 120);
            div.add(img);
        }
        document.add(div);
    }
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) SolidBorder(com.itextpdf.layout.borders.SolidBorder) Paragraph(com.itextpdf.layout.element.Paragraph) Div(com.itextpdf.layout.element.Div) CsvTo2DList(com.itextpdf.highlevel.util.CsvTo2DList) List(java.util.List) File(java.io.File) Link(com.itextpdf.layout.element.Link)

Aggregations

Image (com.itextpdf.layout.element.Image)37 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)25 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)25 Document (com.itextpdf.layout.Document)25 Paragraph (com.itextpdf.layout.element.Paragraph)20 CsvTo2DList (com.itextpdf.highlevel.util.CsvTo2DList)6 File (java.io.File)6 List (java.util.List)6 ImageData (com.itextpdf.io.image.ImageData)5 SolidBorder (com.itextpdf.layout.borders.SolidBorder)4 AreaBreak (com.itextpdf.layout.element.AreaBreak)4 Cell (com.itextpdf.layout.element.Cell)4 Link (com.itextpdf.layout.element.Link)4 IOException (java.io.IOException)4 PdfFont (com.itextpdf.kernel.font.PdfFont)3 Rectangle (com.itextpdf.kernel.geom.Rectangle)3 PdfReader (com.itextpdf.kernel.pdf.PdfReader)3 ListItem (com.itextpdf.layout.element.ListItem)3 Barcode128 (com.itextpdf.barcodes.Barcode128)2 BarcodeQRCode (com.itextpdf.barcodes.BarcodeQRCode)2