Search in sources :

Example 21 with Image

use of com.itextpdf.layout.element.Image in project digilib by robcast.

the class PDFTitlePage method createPage.

/**
 * Add the the title page to the PDF Document.
 *
 * @return
 */
public Document createPage(Document content) {
    /*
         * header with logo
         */
    Table headerBlock = new Table(UnitValue.createPercentArray(new float[] { 20, 80 }));
    Image logo = getLogo();
    if (logo != null) {
        logo.setWidth(UnitValue.createPercentValue(100));
        headerBlock.addCell(new Cell().add(logo).setBorderRight(null));
    }
    String headerText = getHeaderTitle();
    if (!headerText.isEmpty()) {
        Cell textCell = new Cell().setBorderLeft(null).setPaddingLeft(12).add(new Paragraph(headerText).setBold());
        String headerSubtext = getHeaderSubtitle();
        if (headerSubtext != null) {
            textCell.add(new Paragraph(headerSubtext));
        }
        headerBlock.addCell(textCell);
    }
    content.add(headerBlock.setMarginBottom(24));
    String reference = getReference();
    if (!reference.isEmpty()) {
        /*
             * full reference
             */
        content.add(new Paragraph(reference));
    } else {
        /*
             * author
             */
        String author = getAuthor();
        if (!author.isEmpty()) {
            content.add(new Paragraph(author).setTextAlignment(TextAlignment.CENTER));
        }
        /*
             * title
             */
        String title = getTitle();
        if (!title.isEmpty()) {
            content.add(new Paragraph(title).setTextAlignment(TextAlignment.CENTER));
        }
        /*
             * date
             */
        String date = getDate();
        if (!date.isEmpty()) {
            content.add(new Paragraph(date).setTextAlignment(TextAlignment.CENTER));
        }
    }
    /*
         * page numbers
         */
    content.add(new Paragraph(getPages()).setTextAlignment(TextAlignment.CENTER));
    /*
         * URL
         */
    try {
        content.add(new Paragraph().setTextAlignment(TextAlignment.CENTER).setFont(PdfFontFactory.createFont(StandardFonts.COURIER)).setFontSize(10).add(new Link(getUrl(), PdfAction.createURI(getUrl()))).setFixedPosition(24, 24, UnitValue.createPercentValue(98)));
    } catch (IOException e) {
        logger.error("{}", e);
    }
    return content;
}
Also used : Table(com.itextpdf.layout.element.Table) IOException(java.io.IOException) Image(com.itextpdf.layout.element.Image) Cell(com.itextpdf.layout.element.Cell) Link(com.itextpdf.layout.element.Link) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 22 with Image

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

the class PdfTicketBuilder method addImage.

public PdfTicketBuilder addImage(String fileName) {
    try {
        Image img = new Image(ImageDataFactory.create(this.absolutePathOfResource("img/" + fileName)));
        img.setWidth(IMAGE_WIDTH);
        img.setHorizontalAlignment(HorizontalAlignment.CENTER);
        this.getDocument().add(img);
    } catch (MalformedURLException mue) {
        Logger.getLogger(this.getClass()).error("File: " + mue);
    }
    return this;
}
Also used : MalformedURLException(java.net.MalformedURLException) Image(com.itextpdf.layout.element.Image)

Example 23 with Image

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

the class PdfTicketBuilder method qrCode.

public PdfTicketBuilder qrCode(String code) {
    BarcodeQRCode qrcode = new BarcodeQRCode(code.trim());
    Image qrcodeImage = new Image(qrcode.createFormXObject(this.getDocument().getPdfDocument()));
    qrcodeImage.setHorizontalAlignment(HorizontalAlignment.CENTER);
    qrcodeImage.setWidthPercent(50);
    this.getDocument().add(qrcodeImage);
    Paragraph paragraph = new Paragraph("Ref. " + code);
    paragraph.setTextAlignment(TextAlignment.CENTER);
    this.getDocument().add(paragraph);
    return this;
}
Also used : BarcodeQRCode(com.itextpdf.barcodes.BarcodeQRCode) Image(com.itextpdf.layout.element.Image) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 24 with Image

use of com.itextpdf.layout.element.Image in project MtgDesktopCompanion by nicho92.

the class PDFExport method createCell.

private Cell createCell(MagicCard card) throws IOException {
    ImageData imageData = null;
    try {
        imageData = ImageDataFactory.create(getEnabledPlugin(MTGPictureProvider.class).getFullSizePicture(card), null);
    } catch (Exception e) {
        imageData = ImageDataFactory.create(getEnabledPlugin(MTGPictureProvider.class).getBackPicture(), null);
    }
    var image = new Image(imageData);
    image.scaleAbsolute(2.49f * userPoint, 3.48f * userPoint);
    var cell = new Cell();
    if (getBoolean("PRINT_CUT_LINE")) {
        cell.setBorder(new DottedBorder(0.5f));
    } else
        cell.setBorder(Border.NO_BORDER);
    if (getInt(SPACE) != null)
        cell.setPadding(getInt(SPACE));
    cell.add(image);
    return cell;
}
Also used : MTGPictureProvider(org.magic.api.interfaces.MTGPictureProvider) ImageData(com.itextpdf.io.image.ImageData) Image(com.itextpdf.layout.element.Image) DottedBorder(com.itextpdf.layout.borders.DottedBorder) Cell(com.itextpdf.layout.element.Cell) NotImplementedException(org.apache.commons.lang3.NotImplementedException) IOException(java.io.IOException)

Example 25 with Image

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

the class PdfTicketBuilder method barCode.

public PdfTicketBuilder barCode(String code) {
    Barcode128 code128 = new Barcode128(this.getDocument().getPdfDocument());
    code128.setCodeType(Barcode128.CODE128);
    code128.setCode(code.trim());
    Image code128Image = new Image(code128.createFormXObject(this.getDocument().getPdfDocument()));
    int width = code.length() * 7;
    if (width > 100) {
        width = 100;
    }
    code128Image.setWidthPercent(width);
    code128Image.setHorizontalAlignment(HorizontalAlignment.CENTER);
    this.getDocument().add(code128Image);
    return this;
}
Also used : Barcode128(com.itextpdf.barcodes.Barcode128) Image(com.itextpdf.layout.element.Image)

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