Search in sources :

Example 26 with Image

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

the class PdfTag24Builder method addTag24.

public PdfTag24Builder addTag24(String description, String code) {
    assert description != null;
    assert code != null;
    if ((tag24 % 24) == 0) {
        if (tag24 > 0) {
            this.getDocument().add(new AreaBreak(AreaBreakType.NEXT_PAGE));
        }
        this.prepareTags24();
    }
    Cell cell = new Cell();
    cell.setPaddingTop(10);
    cell.setMinHeight(84.2F);
    cell.setBorder(Border.NO_BORDER);
    cell.setTextAlignment(TextAlignment.CENTER);
    cell.add(description);
    if (!code.isEmpty()) {
        BarcodeEAN barcode = new BarcodeEAN(this.getDocument().getPdfDocument());
        barcode.setCodeType(BarcodeEAN.EAN13);
        barcode.setCode(code.trim());
        Image barcodeImage = new Image(barcode.createFormXObject(this.getDocument().getPdfDocument()));
        barcodeImage.setWidthPercent(70);
        barcodeImage.setHorizontalAlignment(HorizontalAlignment.CENTER);
        cell.add(barcodeImage);
    }
    this.getTable().addCell(cell);
    this.getDocument().add(this.getTable());
    tag24++;
    return this;
}
Also used : BarcodeEAN(com.itextpdf.barcodes.BarcodeEAN) AreaBreak(com.itextpdf.layout.element.AreaBreak) Image(com.itextpdf.layout.element.Image) Cell(com.itextpdf.layout.element.Cell)

Example 27 with Image

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

the class PdfCoreBuilder method barcode.

public PdfCoreBuilder barcode(String code) {
    if (code.length() > 12) {
        code = code.substring(code.length() - 12);
    }
    Barcode128 code128 = new Barcode128(this.document.getPdfDocument());
    code128.setCodeType(Barcode128.CODE128);
    // UTF8
    code128.setCode(code.trim().replace('-', '/').replace('_', '?'));
    code128.setAltText(code.trim());
    Image code128Image = new Image(code128.createFormXObject(this.document.getPdfDocument()));
    code128Image.setWidthPercent(BARCODE_WIDTH);
    code128Image.setHeight(BARCODE_HEIGHT);
    code128Image.setHorizontalAlignment(HorizontalAlignment.CENTER);
    this.document.add(code128Image);
    return this;
}
Also used : Barcode128(com.itextpdf.barcodes.Barcode128) Image(com.itextpdf.layout.element.Image)

Example 28 with Image

use of com.itextpdf.layout.element.Image in project commons by mosip.

the class PDFGeneratorImpl method asPDF.

/*
	 * (non-Javadoc)
	 * 
	 * @see io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#asPDF(java.util.List)
	 */
@Override
public byte[] asPDF(List<BufferedImage> bufferedImages) throws IOException {
    byte[] scannedPdfFile = null;
    try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
        PdfWriter pdfWriter = new PdfWriter(byteArrayOutputStream);
        Document document = new Document(new PdfDocument(pdfWriter));
        for (BufferedImage bufferedImage : bufferedImages) {
            Image image = new Image(ImageDataFactory.create(getImageBytesFromBufferedImage(bufferedImage)));
            image.scaleToFit(600, 750);
            document.add(image);
        }
        document.close();
        pdfWriter.close();
        scannedPdfFile = byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), e.getMessage());
    }
    return scannedPdfFile;
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) BufferedImage(java.awt.image.BufferedImage) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) BufferedImage(java.awt.image.BufferedImage) PDFGeneratorException(io.mosip.kernel.core.pdfgenerator.exception.PDFGeneratorException)

Example 29 with Image

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

the class C03E10_MaryReillyV3 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 img1 = new Image(ImageDataFactory.create(MARY));
    document.add(img1);
    Image img2 = new Image(ImageDataFactory.create(MARY));
    document.add(img2);
    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 30 with Image

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

the class C03E18_ImageTypes method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    // raw
    byte[] data = new byte[256 * 3];
    for (int i = 0; i < 256; i++) {
        data[i * 3] = (byte) (255 - i);
        data[i * 3 + 1] = (byte) (255 - i);
        data[i * 3 + 2] = (byte) i;
    }
    ImageData raw = ImageDataFactory.create(256, 1, 3, 8, data, null);
    Image img = new Image(raw);
    img.scaleAbsolute(256, 10);
    document.add(img);
    // JPEG2000
    Image img1 = new Image(ImageDataFactory.create(TEST1));
    document.add(img1);
    document.add(new AreaBreak());
    // BMP
    Image img2 = new Image(ImageDataFactory.create(TEST2));
    img2.setMarginBottom(10);
    document.add(img2);
    // PNG
    Image img3 = new Image(ImageDataFactory.create(TEST3));
    img3.setMarginBottom(10);
    document.add(img3);
    // Transparent PNG
    Image img4 = new Image(ImageDataFactory.create(TEST4));
    img4.setBorderLeft(new SolidBorder(6));
    document.add(img4);
    // GIF
    Image img5 = new Image(ImageDataFactory.create(TEST5));
    img5.setBackgroundColor(ColorConstants.LIGHT_GRAY);
    document.add(img5);
    // AWT
    java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(TEST5);
    Image awt = new Image(ImageDataFactory.create(awtImage, java.awt.Color.yellow));
    awt.setMarginTop(10);
    document.add(awt);
    // JBIG2
    Image img6 = new Image(ImageDataFactory.create(TEST6));
    document.add(img6);
    // TIFF
    Image img7 = new Image(ImageDataFactory.create(TEST7));
    document.add(img7);
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ImageData(com.itextpdf.io.image.ImageData) AreaBreak(com.itextpdf.layout.element.AreaBreak) 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) java.awt(java.awt)

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