Search in sources :

Example 1 with Paragraph

use of com.itextpdf.layout.element.Paragraph 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 2 with Paragraph

use of com.itextpdf.layout.element.Paragraph 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 Paragraph

use of com.itextpdf.layout.element.Paragraph in project java-example by saxingz.

the class A0025PdfApplication method addText2.

private static void addText2(PdfCanvas canvas, Rectangle pageSize, int totalPage, int i, Document document, PdfDocument pdfDoc, PdfPage page) throws IOException {
    // Draw header text
    canvas.beginText().setFontAndSize(PdfFontFactory.createFont(FontConstants.HELVETICA), 7).moveText(pageSize.getWidth() / 2 - 24, pageSize.getHeight() - 10).showText(randomStr() + WECHAT_STR + randomStr()).endText();
    // Draw footer line
    canvas.setStrokeColor(Color.BLACK).setLineWidth(.2f).moveTo(pageSize.getWidth() / 2 - 30, 20).lineTo(pageSize.getWidth() / 2 + 30, 20).stroke();
    // Draw page number
    canvas.beginText().setFontAndSize(PdfFontFactory.createFont(FontConstants.HELVETICA), 7).moveText(pageSize.getWidth() / 2 - 7, 10).showText(randomStr() + WECHAT_STR + randomStr()).endText();
    int waterTimes = randomInt(WATER_TIMES_RANGE);
    System.out.println("本页水印: " + waterTimes + "层");
    for (int j = 0; j < waterTimes; j++) {
        // Draw watermark
        Paragraph p = new Paragraph(WECHAT_STR).setFontSize(randomInt(WATER_FONT_SIZE_RANGE));
        PdfExtGState gs1 = new PdfExtGState().setFillOpacity(WATER_OPACITY);
        canvas.setExtGState(gs1);
        document.showTextAligned(p, pageSize.getWidth() / WATER_POSITION_RANGE * randomInt(WATER_POSITION_RANGE), pageSize.getHeight() / WATER_POSITION_RANGE * randomInt(WATER_POSITION_RANGE), pdfDoc.getPageNumber(page), TextAlignment.CENTER, VerticalAlignment.MIDDLE, randomInt(360));
        // add random char
        Paragraph p2 = new Paragraph(getRandomWechat(WECHAT_STR)).setFontSize(randomInt(WATER_FONT_SIZE_RANGE));
        PdfExtGState gs2 = new PdfExtGState().setFillOpacity(WATER_OPACITY);
        canvas.setExtGState(gs2);
        document.showTextAligned(p2, pageSize.getWidth() / WATER_POSITION_RANGE * randomInt(WATER_POSITION_RANGE), pageSize.getHeight() / WATER_POSITION_RANGE * randomInt(WATER_POSITION_RANGE), pdfDoc.getPageNumber(page), TextAlignment.CENTER, VerticalAlignment.MIDDLE, randomInt(360));
        // transparent
        Paragraph p3 = new Paragraph(WECHAT_STR).setFontSize(randomInt(WATER_FONT_SIZE_RANGE));
        PdfExtGState gs3 = new PdfExtGState().setFillOpacity(0);
        canvas.setExtGState(gs3);
        document.showTextAligned(p3, pageSize.getWidth() / WATER_POSITION_RANGE * randomInt(WATER_POSITION_RANGE), pageSize.getHeight() / WATER_POSITION_RANGE * randomInt(WATER_POSITION_RANGE), pdfDoc.getPageNumber(page), TextAlignment.CENTER, VerticalAlignment.MIDDLE, randomInt(360));
    }
    canvas.saveState();
    canvas.restoreState();
}
Also used : PdfExtGState(com.itextpdf.kernel.pdf.extgstate.PdfExtGState) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 4 with Paragraph

use of com.itextpdf.layout.element.Paragraph in project spring-learning by moon-zhou.

the class Demo001 method main.

public static void main(String[] args) {
    try {
        String dest = "/Users/xxx/tmp/pdf/demo001.pdf";
        PdfWriter writer = new PdfWriter(dest);
        PdfDocument pdf = new PdfDocument(writer);
        Document document = new Document(pdf);
        document.add(new Paragraph("Hello World!"));
        document.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) FileNotFoundException(java.io.FileNotFoundException) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 5 with Paragraph

use of com.itextpdf.layout.element.Paragraph 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)

Aggregations

Paragraph (com.itextpdf.layout.element.Paragraph)128 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)109 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)109 Document (com.itextpdf.layout.Document)103 PdfFont (com.itextpdf.kernel.font.PdfFont)45 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)29 BufferedReader (java.io.BufferedReader)26 FileReader (java.io.FileReader)26 Table (com.itextpdf.layout.element.Table)22 Cell (com.itextpdf.layout.element.Cell)21 AreaBreak (com.itextpdf.layout.element.AreaBreak)20 Image (com.itextpdf.layout.element.Image)20 List (java.util.List)17 CsvTo2DList (com.itextpdf.highlevel.util.CsvTo2DList)16 Text (com.itextpdf.layout.element.Text)16 Rectangle (com.itextpdf.kernel.geom.Rectangle)15 PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)14 Tab (com.itextpdf.layout.element.Tab)13 ArrayList (java.util.ArrayList)13 TabStop (com.itextpdf.layout.element.TabStop)12