Search in sources :

Example 66 with Paragraph

use of com.itextpdf.layout.element.Paragraph in project ComponentManagement by Bac3Phi.

the class InventoriesReportController method addHeader.

private void addHeader(String strheader, Document document) throws IOException {
    Paragraph header = new Paragraph(strheader);
    // Setting font of the text
    PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_BOLD);
    header.setFont(font);
    header.setFontSize(14);
    header.setTextAlignment(TextAlignment.LEFT);
    document.add(header);
}
Also used : PdfFont(com.itextpdf.kernel.font.PdfFont) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 67 with Paragraph

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

the class A0025PdfApplication method addText1.

private static void addText1(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("I want to believe").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(String.valueOf(i)).showText(" of ").showText(String.valueOf(totalPage)).endText();
    // Draw watermark
    Paragraph p = new Paragraph("wechat-diyicaizi").setFontSize(60);
    canvas.saveState();
    PdfExtGState gs1 = new PdfExtGState().setFillOpacity(0.2f);
    canvas.setExtGState(gs1);
    document.showTextAligned(p, pageSize.getWidth() / 2, pageSize.getHeight() / 2, pdfDoc.getPageNumber(page), TextAlignment.CENTER, VerticalAlignment.MIDDLE, 45);
    canvas.restoreState();
}
Also used : PdfExtGState(com.itextpdf.kernel.pdf.extgstate.PdfExtGState) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 68 with Paragraph

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

the class Demo002 method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF writer
    PdfWriter writer = new PdfWriter(dest);
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(writer);
    // Initialize document
    Document document = new Document(pdf);
    // Create a PdfFont
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    // Add a Paragraph
    document.add(new Paragraph("iText is:").setFont(font));
    // Create a List
    List list = new List().setSymbolIndent(12).setListSymbol("\u2022").setFont(font);
    // Add ListItem objects
    list.add(new ListItem("Never gonna give you up")).add(new ListItem("Never gonna let you down")).add(new ListItem("Never gonna run around and desert you")).add(new ListItem("Never gonna make you cry")).add(new ListItem("Never gonna say goodbye")).add(new ListItem("Never gonna tell a lie and hurt you"));
    // Add the list
    document.add(list);
    // Close document
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFont(com.itextpdf.kernel.font.PdfFont) List(com.itextpdf.layout.element.List) ListItem(com.itextpdf.layout.element.ListItem) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 69 with Paragraph

use of com.itextpdf.layout.element.Paragraph in project ISPP by josdomqui.

the class PaymentService method generateRecipt.

public String generateRecipt(Double price) {
    String fileName = "recipt.pdf";
    try {
        File file = new File(fileName);
        PdfWriter pdfWriter = new PdfWriter(file);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument);
        Paragraph paragraph = new Paragraph("Su pedido ha costado " + price + " euros.");
        document.add(paragraph);
        document.close();
        pdfWriter.close();
        System.out.println("PDF creado");
    } catch (FileNotFoundException ex) {
        System.out.println(ex.getMessage());
    } catch (IOException ex) {
        System.out.println(ex.getMessage());
    }
    return fileName;
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) File(java.io.File) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 70 with Paragraph

use of com.itextpdf.layout.element.Paragraph in project Rolls-Royce by EntryDSM.

the class ApplicationPdfGenerator method generateApplicationPdf.

private byte[] generateApplicationPdf(User user, Score score) {
    PdfData data = pdfDataConverter.applicationToInfo(user, score);
    ByteArrayOutputStream[] outputStreams = getTemplateFileNames(user).parallelStream().map(template -> templateProcessor.convertTemplateIntoHtmlString(template, data.toMap())).map(pdfProcessor::convertHtmlToPdf).toArray(ByteArrayOutputStream[]::new);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PdfDocument mergedDocument = new PdfDocument(new PdfWriter(outputStream));
    PdfMerger pdfMerger = new PdfMerger(mergedDocument);
    Document document = new Document(mergedDocument);
    for (ByteArrayOutputStream pdfStream : outputStreams) {
        PdfDocument pdfDoc = getPdfDocument(pdfStream);
        mergeDocument(pdfMerger, pdfDoc);
    }
    for (int i = 1; i <= mergedDocument.getNumberOfPages(); i++) {
        document.showTextAligned(new Paragraph(String.format("- %s -", i)), 300, 25, i, TextAlignment.CENTER, VerticalAlignment.BOTTOM, 0);
    }
    document.close();
    return outputStream.toByteArray();
}
Also used : PdfMerger(com.itextpdf.kernel.utils.PdfMerger) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) 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