use of com.itextpdf.layout.element.Paragraph in project i7js-highlevel by itext.
the class C02E13_JekyllHydeV9 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);
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();
int n = pdf.getNumberOfPages();
Paragraph footer;
for (int page = 1; page <= n; page++) {
footer = new Paragraph(String.format("Page %s of %s", page, n));
document.showTextAligned(footer, 297.5f, 20, page, TextAlignment.CENTER, VerticalAlignment.MIDDLE, 0);
}
// Close document
document.close();
}
use of com.itextpdf.layout.element.Paragraph in project i7js-highlevel by itext.
the class C03E04_JekyllHydeTabsV4 method createPdf.
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf, PageSize.A4.rotate());
float[] stops = new float[] { 80, 120, 580, 590, 720 };
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], 595);
}
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.element.Paragraph in project i7js-highlevel by itext.
the class C05E01_MyFirstTable 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);
Table table = new Table(new float[] { 1, 1, 1 });
table.addCell(new Cell(1, 3).add(new Paragraph("Cell with colspan 3")));
table.addCell(new Cell(2, 1).add(new Paragraph("Cell with rowspan 2")));
table.addCell("row 1; cell 1");
table.addCell("row 1; cell 2");
table.addCell("row 2; cell 1");
table.addCell("row 2; cell 2");
document.add(table);
document.close();
}
use of com.itextpdf.layout.element.Paragraph in project i7js-highlevel by itext.
the class C05E02_ColumnWidths4 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);
Table table = new Table(UnitValue.createPercentArray(new float[] { 2, 1, 1 }));
table.setWidth(UnitValue.createPercentValue(80));
table.setHorizontalAlignment(HorizontalAlignment.CENTER);
table.addCell(new Cell(1, 3).add(new Paragraph("Cell with colspan 3")));
table.addCell(new Cell(2, 1).add(new Paragraph("Cell with rowspan 2")));
table.addCell("row 1; cell 1");
table.addCell("row 1; cell 2");
table.addCell("row 2; cell 1");
table.addCell("row 2; cell 2");
document.add(table);
document.close();
}
use of com.itextpdf.layout.element.Paragraph in project i7js-highlevel by itext.
the class C05E05_CellPadding 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);
Table table = new Table(UnitValue.createPercentArray(new float[] { 2, 1, 1 }));
table.setBackgroundColor(ColorConstants.ORANGE);
table.setWidth(UnitValue.createPercentValue(80));
table.setHorizontalAlignment(HorizontalAlignment.CENTER);
table.addCell(new Cell(1, 3).add(new Paragraph("Cell with colspan 3")).setPadding(10).setBackgroundColor(ColorConstants.GREEN));
table.addCell(new Cell(2, 1).add(new Paragraph("Cell with rowspan 2")).setPaddingLeft(30).setFontColor(ColorConstants.WHITE).setBackgroundColor(ColorConstants.BLUE));
table.addCell(new Cell().add(new Paragraph("row 1; cell 1")).setFontColor(ColorConstants.WHITE).setBackgroundColor(ColorConstants.RED));
table.addCell(new Cell().add(new Paragraph("row 1; cell 2")));
table.addCell(new Cell().add(new Paragraph("row 2; cell 1")).setFontColor(ColorConstants.WHITE).setBackgroundColor(ColorConstants.RED));
table.addCell(new Cell().add(new Paragraph("row 2; cell 2")).setPadding(10).setFontColor(ColorConstants.WHITE).setBackgroundColor(ColorConstants.RED));
document.add(table);
document.close();
}
Aggregations