Search in sources :

Example 11 with AreaBreak

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

the class DivProperties method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    // Initialize document
    Document document = new Document(pdf);
    Style style = new Style();
    style.setBackgroundColor(ColorConstants.YELLOW).setBorder(new SolidBorder(0.5f));
    document.add(createNewDiv().addStyle(style).setWidth(350).setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER).setDestination("Top"));
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    document.add(createNewDiv().setRotationAngle(Math.PI / 18).setFont(font).setFontSize(8).setFontColor(ColorConstants.RED));
    document.add(createNewDiv().setWidth(350).setHyphenation(new HyphenationConfig("en", "uk", 3, 3)).setKeepWithNext(true));
    document.add(createNewDiv().setWidth(UnitValue.createPercentValue(70)).setKeepTogether(true));
    document.add(createNewDiv().setHeight(350).setBackgroundColor(ColorConstants.YELLOW).setAction(PdfAction.createGoTo("Top")).setRelativePosition(10, 10, 50, 10));
    document.add(new AreaBreak());
    document.add(createNewDiv().setFixedPosition(100, 400, 350));
    document.add(new AreaBreak());
    document.add(createNewDiv().setBackgroundColor(ColorConstants.YELLOW).setMarginBottom(10));
    document.add(createNewDiv().setBackgroundColor(ColorConstants.LIGHT_GRAY).setPaddingLeft(20).setPaddingRight(50));
    document.add(createNewDiv().setBackgroundColor(ColorConstants.YELLOW));
    document.add(createNewDiv().setBackgroundColor(ColorConstants.LIGHT_GRAY));
    document.add(createNewDiv().setBackgroundColor(ColorConstants.YELLOW));
    document.add(createNewDiv().setBackgroundColor(ColorConstants.LIGHT_GRAY).setMargin(50).setPadding(30));
    document.add(createNewDiv().setBackgroundColor(ColorConstants.YELLOW));
    document.add(createNewDiv().setBackgroundColor(ColorConstants.LIGHT_GRAY));
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFont(com.itextpdf.kernel.font.PdfFont) Style(com.itextpdf.layout.Style) HyphenationConfig(com.itextpdf.layout.hyphenation.HyphenationConfig) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) SolidBorder(com.itextpdf.layout.borders.SolidBorder)

Example 12 with AreaBreak

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

the class ListSeparatorProperties method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    // Initialize document
    Document document = new Document(pdf);
    Style style = new Style();
    style.setBackgroundColor(ColorConstants.YELLOW);
    document.add(createNewSeparator().addStyle(style).setDestination("Top"));
    document.add(new Paragraph("test"));
    document.add(createNewSeparator().setWidth(300).setHorizontalAlignment(HorizontalAlignment.CENTER));
    document.add(createNewSeparator().setMargin(10).setVerticalAlignment(VerticalAlignment.BOTTOM).setBorder(new SolidBorder(0.5f)));
    document.add(createNewSeparator().setMargin(10).setWidth(300));
    document.add(createNewSeparator().setMargin(10).setRelativePosition(10, 10, 50, 10));
    document.add(createNewSeparator().setMargin(10).setWidth(UnitValue.createPercentValue(50)));
    document.add(createNewSeparator().setMargin(10).setWidth(50).setAction(PdfAction.createGoTo("Top")));
    document.add(createNewSeparator().setFixedPosition(100, 200, 350));
    document.add(new AreaBreak());
    document.add(createNewSeparator().setBackgroundColor(ColorConstants.YELLOW).setMarginBottom(10));
    document.add(createNewSeparator().setBackgroundColor(ColorConstants.LIGHT_GRAY).setPaddingLeft(20).setPaddingRight(50));
    document.add(createNewSeparator().setBackgroundColor(ColorConstants.YELLOW));
    document.add(createNewSeparator().setBackgroundColor(ColorConstants.LIGHT_GRAY).setMarginBottom(50));
    document.add(createNewSeparator().setBackgroundColor(ColorConstants.YELLOW));
    document.add(createNewSeparator().setBackgroundColor(ColorConstants.LIGHT_GRAY).setMargin(50).setPadding(30));
    document.add(createNewSeparator().setBackgroundColor(ColorConstants.YELLOW));
    document.add(createNewSeparator().setBackgroundColor(ColorConstants.LIGHT_GRAY));
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Style(com.itextpdf.layout.Style) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph) SolidBorder(com.itextpdf.layout.borders.SolidBorder)

Example 13 with AreaBreak

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

the class PDFStreamWorker method renderPDF.

/**
 * @throws DocumentException
 * @throws InterruptedException
 * @throws ExecutionException
 * @throws IOException
 * @throws ImageOpException
 */
protected OutputStream renderPDF() throws InterruptedException, ExecutionException, IOException, ImageOpException {
    long start_time = System.currentTimeMillis();
    // create document object
    PdfWriter writer = new PdfWriter(outstream);
    PdfDocument pdfdoc = new PdfDocument(writer);
    doc = new Document(pdfdoc, PageSize.A4);
    logger.debug("PDF: {} doc.open()ed ({}ms)", outstream, (System.currentTimeMillis() - start_time));
    // add title page
    PDFTitlePage titlepage = new PDFTitlePage(job_info);
    titlepage.createPage(doc);
    // add pages
    NumRange pgs = job_info.getPages();
    for (int p : pgs) {
        // start new page
        doc.add(new AreaBreak());
        logger.debug("PDF: adding Image {} to {}", p, outstream);
        // copy request and set page number (as new Parameter)
        DigilibRequest pageRequest = new DigilibRequest(dlConfig, job_info);
        pageRequest.put("pn", new Parameter("pn", p, p));
        // create ImageJobInformation
        ImageJobDescription iji = ImageJobDescription.getRawInstance(pageRequest, job_info.getDlConfig());
        iji.prepareScaleParams();
        addImage(doc, iji);
        logger.debug("PDF: done adding Image {} to {}", p, outstream);
    }
    logger.debug("PDF: done adding all Images to {}", outstream);
    doc.close();
    logger.debug("PDF: {} doc.close() ({}ms)", outstream, (System.currentTimeMillis() - start_time));
    writer.flush();
    writer.close();
    return outstream;
}
Also used : NumRange(digilib.util.NumRange) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ImageJobDescription(digilib.image.ImageJobDescription) DigilibRequest(digilib.conf.DigilibRequest) Parameter(digilib.util.Parameter) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument)

Example 14 with AreaBreak

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

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

the class C02E09_JekyllHydeV5 method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    // Initialize document
    Document document = new Document(pdf);
    // Set column parameters
    float offSet = 36;
    float gutter = 23;
    float columnWidth = (PageSize.A4.getWidth() - offSet * 2) / 2 - gutter;
    float columnHeight = PageSize.A4.getHeight() - offSet * 2;
    // Define column areas
    Rectangle[] columns = { new Rectangle(offSet, offSet, columnWidth, columnHeight), new Rectangle(offSet + columnWidth + gutter, offSet, columnWidth, columnHeight) };
    document.setRenderer(new ColumnDocumentRenderer(document, columns));
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    PdfFont bold = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
    document.setTextAlignment(TextAlignment.JUSTIFIED).setFont(font).setHyphenation(new HyphenationConfig("en", null, 3, 3));
    BufferedReader br = new BufferedReader(new FileReader(SRC));
    String line;
    Paragraph p;
    boolean title = true;
    AreaBreak nextPage = new AreaBreak(AreaBreakType.NEXT_PAGE);
    while ((line = br.readLine()) != null) {
        p = new Paragraph(line);
        if (title) {
            p.setFont(bold).setFontSize(12);
            title = false;
        } else {
            p.setFirstLineIndent(36);
        }
        if (line.isEmpty()) {
            document.add(nextPage);
            title = true;
        }
        document.add(p);
    }
    br.close();
    // Close document
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Rectangle(com.itextpdf.kernel.geom.Rectangle) HyphenationConfig(com.itextpdf.layout.hyphenation.HyphenationConfig) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph) ColumnDocumentRenderer(com.itextpdf.layout.ColumnDocumentRenderer) PdfFont(com.itextpdf.kernel.font.PdfFont) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Aggregations

AreaBreak (com.itextpdf.layout.element.AreaBreak)26 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 PdfFont (com.itextpdf.kernel.font.PdfFont)17 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)17 BufferedReader (java.io.BufferedReader)13 FileReader (java.io.FileReader)13 Rectangle (com.itextpdf.kernel.geom.Rectangle)8 DottedLine (com.itextpdf.kernel.pdf.canvas.draw.DottedLine)7 Tab (com.itextpdf.layout.element.Tab)7 TabStop (com.itextpdf.layout.element.TabStop)7 ArrayList (java.util.ArrayList)7 ColumnDocumentRenderer (com.itextpdf.layout.ColumnDocumentRenderer)6 Style (com.itextpdf.layout.Style)5 SolidBorder (com.itextpdf.layout.borders.SolidBorder)5 SimpleEntry (java.util.AbstractMap.SimpleEntry)5 Image (com.itextpdf.layout.element.Image)4 PdfPage (com.itextpdf.kernel.pdf.PdfPage)3