use of com.itextpdf.layout.Document in project i7js-highlevel by itext.
the class C02E12_JekyllHydeV8 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, PageSize.A4, false);
PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
PdfFont bold = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
document.setTextAlignment(TextAlignment.JUSTIFIED).setHyphenation(new HyphenationConfig("en", null, 3, 3)).setFont(font).setFontSize(11);
Text totalPages = new Text("This document has {totalpages} pages.");
IRenderer renderer = new TextRenderer(totalPages);
totalPages.setNextRenderer(renderer);
document.add(new Paragraph(totalPages));
BufferedReader br = new BufferedReader(new FileReader(SRC));
String line;
Paragraph p;
boolean title = true;
while ((line = br.readLine()) != null) {
p = new Paragraph(line);
p.setKeepTogether(true);
if (title) {
p.setFont(bold).setFontSize(12);
title = false;
} else {
p.setFirstLineIndent(36);
}
if (line.isEmpty()) {
p.setMarginBottom(12);
title = true;
} else {
p.setMarginBottom(0);
}
document.add(p);
}
br.close();
String total = renderer.toString().replace("{totalpages}", String.valueOf(pdf.getNumberOfPages()));
((TextRenderer) renderer).setText(total);
((Text) renderer.getModelElement()).setNextRenderer(renderer);
document.relayout();
// Close document
document.close();
}
use of com.itextpdf.layout.Document in project i7js-highlevel by itext.
the class C03E01_JekyllHydeTabsV1 method createPdf.
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf, PageSize.A4.rotate());
PdfCanvas pdfCanvas = new PdfCanvas(pdf.addNewPage());
for (int i = 1; i <= 10; i++) {
pdfCanvas.moveTo(document.getLeftMargin() + i * 50, 0);
pdfCanvas.lineTo(document.getLeftMargin() + i * 50, 595);
}
pdfCanvas.stroke();
List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
for (List<String> record : resultSet) {
Paragraph p = new Paragraph();
p.add(record.get(0).trim()).add(new Tab()).add(record.get(1).trim()).add(new Tab()).add(record.get(2).trim()).add(new Tab()).add(record.get(3).trim()).add(new Tab()).add(record.get(4).trim()).add(new Tab()).add(record.get(5).trim());
document.add(p);
}
document.close();
}
use of com.itextpdf.layout.Document in project i7js-highlevel by itext.
the class C03E05_JekyllHydeTabsV5 method createPdf.
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf, PageSize.A4);
float[] stops = new float[] { 70, 90, 420, 430, 520 };
List<TabStop> tabstops = new ArrayList();
tabstops.add(new TabStop(stops[0], TabAlignment.CENTER, new DottedLine()));
tabstops.add(new TabStop(stops[1], TabAlignment.LEFT));
tabstops.add(new TabStop(stops[2], TabAlignment.RIGHT, new SolidLine(0.5f)));
tabstops.add(new TabStop(stops[3], TabAlignment.LEFT));
TabStop anchor = new TabStop(stops[4], TabAlignment.ANCHOR, new DashedLine());
anchor.setTabAnchor(' ');
tabstops.add(anchor);
PdfCanvas pdfCanvas = new PdfCanvas(pdf.addNewPage());
for (int i = 0; i < stops.length; i++) {
pdfCanvas.moveTo(document.getLeftMargin() + stops[i], 0);
pdfCanvas.lineTo(document.getLeftMargin() + stops[i], 842);
}
pdfCanvas.stroke();
List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
for (List<String> record : resultSet) {
Paragraph p = new Paragraph();
p.addTabStops(tabstops);
p.add(record.get(0).trim()).add(new Tab()).add(record.get(1).trim()).add(new Tab()).add(record.get(2).trim()).add(new Tab()).add(record.get(3).trim()).add(new Tab()).add(record.get(4).trim()).add(new Tab()).add(record.get(5).trim() + " \'");
document.add(p);
}
document.close();
}
use of com.itextpdf.layout.Document in project i7js-highlevel by itext.
the class C03E10_MaryReillyV3 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 img1 = new Image(ImageDataFactory.create(MARY));
document.add(img1);
Image img2 = new Image(ImageDataFactory.create(MARY));
document.add(img2);
document.close();
}
use of com.itextpdf.layout.Document in project i7js-highlevel by itext.
the class C03E18_ImageTypes method createPdf.
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf);
// raw
byte[] data = new byte[256 * 3];
for (int i = 0; i < 256; i++) {
data[i * 3] = (byte) (255 - i);
data[i * 3 + 1] = (byte) (255 - i);
data[i * 3 + 2] = (byte) i;
}
ImageData raw = ImageDataFactory.create(256, 1, 3, 8, data, null);
Image img = new Image(raw);
img.scaleAbsolute(256, 10);
document.add(img);
// JPEG2000
Image img1 = new Image(ImageDataFactory.create(TEST1));
document.add(img1);
document.add(new AreaBreak());
// BMP
Image img2 = new Image(ImageDataFactory.create(TEST2));
img2.setMarginBottom(10);
document.add(img2);
// PNG
Image img3 = new Image(ImageDataFactory.create(TEST3));
img3.setMarginBottom(10);
document.add(img3);
// Transparent PNG
Image img4 = new Image(ImageDataFactory.create(TEST4));
img4.setBorderLeft(new SolidBorder(6));
document.add(img4);
// GIF
Image img5 = new Image(ImageDataFactory.create(TEST5));
img5.setBackgroundColor(ColorConstants.LIGHT_GRAY);
document.add(img5);
// AWT
java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(TEST5);
Image awt = new Image(ImageDataFactory.create(awtImage, java.awt.Color.yellow));
awt.setMarginTop(10);
document.add(awt);
// JBIG2
Image img6 = new Image(ImageDataFactory.create(TEST6));
document.add(img6);
// TIFF
Image img7 = new Image(ImageDataFactory.create(TEST7));
document.add(img7);
document.close();
}
Aggregations