Search in sources :

Example 1 with Style

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

the class C01E10_ReusingStyles method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    Style normal = new Style();
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    normal.setFont(font).setFontSize(14);
    Style code = new Style();
    PdfFont monospace = PdfFontFactory.createFont(StandardFonts.COURIER);
    code.setFont(monospace).setFontColor(ColorConstants.RED).setBackgroundColor(ColorConstants.LIGHT_GRAY);
    Paragraph p = new Paragraph();
    p.add(new Text("The Strange Case of ").addStyle(normal));
    p.add(new Text("Dr. Jekyll").addStyle(code));
    p.add(new Text(" and ").addStyle(normal));
    p.add(new Text("Mr. Hyde").addStyle(code));
    p.add(new Text(".").addStyle(normal));
    document.add(p);
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFont(com.itextpdf.kernel.font.PdfFont) Style(com.itextpdf.layout.Style) Text(com.itextpdf.layout.element.Text) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 2 with Style

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

the class ImageProperties method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    Image img1 = new Image(ImageDataFactory.create(TEST1));
    img1.scaleToFit(100, 100).setDestination("Top");
    document.add(img1);
    Image img2 = new Image(ImageDataFactory.create(TEST2));
    img2.setHeight(300);
    document.add(img2);
    Image img3 = new Image(ImageDataFactory.create(TEST3));
    img3.scaleToFit(100, 100);
    img3.setBackgroundColor(ColorConstants.BLUE);
    document.add(img3);
    Image img4 = new Image(ImageDataFactory.create(TEST4));
    img4.scaleToFit(100, 100);
    img4.setBackgroundColor(ColorConstants.RED);
    document.add(img4);
    Image img5 = new Image(ImageDataFactory.create(TEST5));
    img5.scaleToFit(50, 50);
    Style style = new Style();
    style.setBorderRight(new SolidBorder(2));
    img5.addStyle(style);
    document.add(img5);
    Image img6 = new Image(ImageDataFactory.create(TEST6));
    PdfAction top = PdfAction.createGoTo("Top");
    img6.scaleToFit(100, 100).setAction(top);
    document.add(img6);
    document.close();
}
Also used : PdfAction(com.itextpdf.kernel.pdf.action.PdfAction) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Style(com.itextpdf.layout.Style) 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)

Example 3 with Style

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

the class ListProperties 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);
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    Style style = new Style();
    style.setBackgroundColor(ColorConstants.YELLOW).setTextAlignment(TextAlignment.CENTER);
    document.add(createNewList().addStyle(style).setWidth(300).setHorizontalAlignment(HorizontalAlignment.CENTER).setDestination("Top"));
    document.add(createNewList().setRotationAngle(Math.PI / 18).setFont(font).setFontSize(8).setFontColor(ColorConstants.RED));
    document.add(createNewList().setHyphenation(new HyphenationConfig("en", "uk", 3, 3)).setBorder(new SolidBorder(0.5f)).setKeepWithNext(true));
    document.add(createNewList().setKeepTogether(true).setHeight(200));
    document.add(createNewList().setWidth(UnitValue.createPercentValue(50)));
    document.add(createNewList().setRelativePosition(10, 10, 50, 10));
    document.add(createNewList());
    document.add(new AreaBreak());
    document.add(createNewList().setFixedPosition(100, 400, 350).setAction(PdfAction.createGoTo("Top")));
    document.add(createNewList().setBackgroundColor(ColorConstants.YELLOW).setMarginBottom(10));
    document.add(createNewList().setBackgroundColor(ColorConstants.LIGHT_GRAY).setPaddingLeft(20).setPaddingRight(50));
    document.add(createNewList().setBackgroundColor(ColorConstants.YELLOW));
    document.add(createNewList().setBackgroundColor(ColorConstants.LIGHT_GRAY));
    document.add(createNewList().setBackgroundColor(ColorConstants.YELLOW));
    document.add(createNewList().setBackgroundColor(ColorConstants.LIGHT_GRAY).setMargin(50).setPadding(30));
    document.add(createNewList().setBackgroundColor(ColorConstants.YELLOW));
    document.add(createNewList().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 4 with Style

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

the class ParagraphProperties 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);
    Paragraph p;
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    Style style = new Style();
    style.setBackgroundColor(ColorConstants.YELLOW);
    p = getNewParagraphInstance().addStyle(style).setBorder(new SolidBorder(0.5f)).setDestination("Top");
    document.add(p);
    p = getNewParagraphInstance();
    p.setBackgroundColor(ColorConstants.GRAY).setWidth(150).setHorizontalAlignment(HorizontalAlignment.CENTER).setTextAlignment(TextAlignment.CENTER);
    document.add(p);
    document.add(getNewParagraphInstance().setRotationAngle(Math.PI / 18));
    document.add(getNewParagraphInstance().setWidth(150).setHyphenation(new HyphenationConfig("en", "uk", 3, 3)));
    document.add(getNewParagraphInstance().setHeight(120).setVerticalAlignment(VerticalAlignment.BOTTOM).setBackgroundColor(ColorConstants.YELLOW).setRelativePosition(10, 10, 50, 10));
    document.add(getNewParagraphInstance().setWidth(UnitValue.createPercentValue(80)).setFont(font).setFontSize(8).setFontColor(ColorConstants.RED));
    document.add(new AreaBreak());
    document.add(getNewParagraphInstance().setFixedPosition(100, 400, 350).setAction(PdfAction.createGoTo("Top")));
    document.add(new AreaBreak());
    document.add(getNewParagraphInstance().setBackgroundColor(ColorConstants.YELLOW).setMarginBottom(10));
    document.add(getNewParagraphInstance().setBackgroundColor(ColorConstants.LIGHT_GRAY).setPaddingLeft(20).setPaddingRight(50));
    document.add(getNewParagraphInstance().setBackgroundColor(ColorConstants.YELLOW));
    document.add(getNewParagraphInstance().setBackgroundColor(ColorConstants.LIGHT_GRAY));
    document.add(getNewParagraphInstance().setBackgroundColor(ColorConstants.YELLOW));
    document.add(getNewParagraphInstance().setBackgroundColor(ColorConstants.LIGHT_GRAY).setMargin(50).setPadding(30));
    document.add(getNewParagraphInstance().setBackgroundColor(ColorConstants.YELLOW));
    document.add(getNewParagraphInstance().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) Paragraph(com.itextpdf.layout.element.Paragraph) SolidBorder(com.itextpdf.layout.borders.SolidBorder)

Example 5 with Style

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

Aggregations

PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)9 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)9 Document (com.itextpdf.layout.Document)9 Style (com.itextpdf.layout.Style)9 SolidBorder (com.itextpdf.layout.borders.SolidBorder)7 PdfFont (com.itextpdf.kernel.font.PdfFont)6 AreaBreak (com.itextpdf.layout.element.AreaBreak)5 Paragraph (com.itextpdf.layout.element.Paragraph)5 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)5 PdfAction (com.itextpdf.kernel.pdf.action.PdfAction)2 DottedBorder (com.itextpdf.layout.borders.DottedBorder)2 Text (com.itextpdf.layout.element.Text)2 Cell (com.itextpdf.layout.element.Cell)1 Image (com.itextpdf.layout.element.Image)1 Table (com.itextpdf.layout.element.Table)1