use of com.itextpdf.layout.Document in project i7js-highlevel by itext.
the class C05E09_JekyllHydeTableV2 method createPdf.
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf, PageSize.A4.rotate());
Table table = new Table(UnitValue.createPercentArray(new float[] { 3, 2, 14, 9, 4, 3 }));
table.setWidth(UnitValue.createPercentValue(100));
List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
List<String> header = resultSet.remove(0);
for (String field : header) {
table.addHeaderCell(field);
}
for (List<String> record : resultSet) {
for (String field : record) {
table.addCell(field);
}
}
Table outerTable = new Table(new float[] { 1 }).addHeaderCell("Continued from previous page:").setSkipFirstHeader(true).addCell(new Cell().add(table).setPadding(0));
document.add(outerTable);
document.close();
}
use of com.itextpdf.layout.Document in project i7js-highlevel by itext.
the class C02E08_JekyllHydeV4 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 nextArea = new AreaBreak(AreaBreakType.NEXT_AREA);
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(nextArea);
title = true;
}
document.add(p);
}
br.close();
// Close document
document.close();
}
use of com.itextpdf.layout.Document in project i7js-highlevel by itext.
the class C01E03_Text_Paragraph_NoCardo 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);
// Add content: the fonts aren't embedded! Don't do this!
PdfFont font = PdfFontFactory.createFont(REGULAR, PdfEncodings.WINANSI, EmbeddingStrategy.PREFER_NOT_EMBEDDED);
PdfFont bold = PdfFontFactory.createFont(BOLD, PdfEncodings.WINANSI, EmbeddingStrategy.PREFER_NOT_EMBEDDED);
PdfFont italic = PdfFontFactory.createFont(ITALIC, PdfEncodings.WINANSI, EmbeddingStrategy.PREFER_NOT_EMBEDDED);
Text title = new Text("The Strange Case of Dr. Jekyll and Mr. Hyde").setFont(bold);
Text author = new Text("Robert Louis Stevenson").setFont(font);
Paragraph p = new Paragraph().setFont(italic).add(title).add(" by ").add(author);
document.add(p);
// Close document
document.close();
}
use of com.itextpdf.layout.Document in project i7js-highlevel by itext.
the class C01E09_ColorRendering 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);
// Add content
Text title1 = new Text("The Strange Case of ").setFontColor(ColorConstants.BLUE);
Text title2 = new Text("Dr. Jekyll").setStrokeColor(ColorConstants.GREEN).setTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL_STROKE);
Text title3 = new Text(" and ");
Text title4 = new Text("Mr. Hyde").setStrokeColor(ColorConstants.RED).setStrokeWidth(0.5f).setTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE);
Paragraph p = new Paragraph().setFontSize(24).add(title1).add(title2).add(title3).add(title4);
document.add(p);
// Close document
document.close();
}
use of com.itextpdf.layout.Document in project i7js-highlevel by itext.
the class C01E04_Czech_Russian_Korean_Wrong 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);
// Add content
PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
document.add(new Paragraph().setFont(font).add(CZECH).add(" by Robert Louis Stevenson"));
document.add(new Paragraph().setFont(font).add(RUSSIAN).add(" by Robert Louis Stevenson"));
document.add(new Paragraph().setFont(font).add(KOREAN).add(" by Robert Louis Stevenson"));
// Close document
document.close();
}
Aggregations