use of com.itextpdf.kernel.pdf.canvas.PdfCanvas in project i7js-highlevel by itext.
the class AlternatingBackgroundTableRenderer method draw.
@Override
public void draw(DrawContext drawContext) {
for (int i = 0; i < rows.size() && null != rows.get(i) && null != rows.get(i)[0]; i++) {
CellRenderer[] renderers = rows.get(i);
Rectangle leftCell = renderers[0].getOccupiedAreaBBox();
Rectangle rightCell = renderers[renderers.length - 1].getOccupiedAreaBBox();
Rectangle rect = new Rectangle(leftCell.getLeft(), leftCell.getBottom(), rightCell.getRight() - leftCell.getLeft(), leftCell.getHeight());
PdfCanvas canvas = drawContext.getCanvas();
canvas.saveState();
if (isOdd) {
canvas.setFillColor(ColorConstants.LIGHT_GRAY);
isOdd = false;
} else {
canvas.setFillColor(ColorConstants.YELLOW);
isOdd = true;
}
canvas.rectangle(rect);
canvas.fill();
canvas.restoreState();
}
super.draw(drawContext);
}
use of com.itextpdf.kernel.pdf.canvas.PdfCanvas 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.kernel.pdf.canvas.PdfCanvas in project i7js-highlevel by itext.
the class C03E03_JekyllHydeTabsV3 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));
tabstops.add(new TabStop(stops[1], TabAlignment.LEFT));
tabstops.add(new TabStop(stops[2], TabAlignment.RIGHT));
tabstops.add(new TabStop(stops[3], TabAlignment.LEFT));
TabStop anchor = new TabStop(stops[4], TabAlignment.ANCHOR);
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.kernel.pdf.canvas.PdfCanvas in project i7js-highlevel by itext.
the class CanvasFontMethods method createPdf.
public void createPdf(String dest) throws IOException {
// Initialize PDF document
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
// Initialize document
PdfPage page = pdf.addNewPage();
PdfCanvas pdfCanvas = new PdfCanvas(page);
Rectangle rectangle = new Rectangle(36, 36, 523, 770);
Canvas canvas = new Canvas(pdfCanvas, rectangle);
Paragraph p;
p = new Paragraph("Testing font methods");
canvas.add(p);
PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
canvas.setFont(font);
p = new Paragraph("Testing font methods: changed font");
canvas.add(p);
canvas.setFontSize(18);
p = new Paragraph("Testing font methods: changed font size");
canvas.add(p);
canvas.setFontColor(ColorConstants.BLUE);
p = new Paragraph("Testing font methods: changed color");
canvas.add(p);
canvas.setBold();
p = new Paragraph("Testing font methods: to bold");
canvas.add(p);
canvas.setItalic();
p = new Paragraph("Testing font methods: to italic");
canvas.add(p);
canvas.setProperty(Property.BOLD_SIMULATION, false);
canvas.setProperty(Property.ITALIC_SIMULATION, false);
canvas.setProperty(Property.FONT_COLOR, null);
p = new Paragraph("Testing font methods: resetting style and color");
canvas.add(p);
canvas.setLineThrough();
p = new Paragraph("Testing font methods: line through (default)");
canvas.add(p);
canvas.setProperty(Property.UNDERLINE, null);
canvas.setUnderline();
p = new Paragraph("Testing font methods: underline (default)");
canvas.add(p);
canvas.setProperty(Property.UNDERLINE, null);
canvas.setUnderline(2, 4);
canvas.setUnderline(ColorConstants.BLUE, 5, 0.1f, 2, -0.5f, PdfCanvasConstants.LineCapStyle.ROUND);
p = new Paragraph("Testing font methods: underline (custom)");
canvas.add(p);
canvas.setProperty(Property.UNDERLINE, null);
canvas.setTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE);
p = new Paragraph("Testing font methods: change text rendering mode");
canvas.add(p);
canvas.setStrokeWidth(0.1f);
canvas.setStrokeColor(ColorConstants.BLUE);
p = new Paragraph("Testing font methods: change stroke width and color");
canvas.add(p);
// Close document
pdf.close();
}
use of com.itextpdf.kernel.pdf.canvas.PdfCanvas in project pdf-editor by Pdf-Creator.
the class PDFDocument method addRectangleWithTableItem.
public void addRectangleWithTableItem(TableItem tableItem) {
PdfCanvas canvas = new PdfCanvas(currentPage);
Rectangle rect = new Rectangle(tableItem.getX(), tableItem.getY(), tableItem.getW(), tableItem.getH());
canvas.setStrokeColor(tableItem.getRectangleStrokeColor()).setFillColor(tableItem.getRectangleFillColor()).rectangle(rect).fill().stroke();
Table table = new Table(tableItem.getCols());
table.setFontColor(tableItem.getFontColor());
for (String cellContent : tableItem.getCellContents()) {
table.addCell(cellContent);
}
new Canvas(canvas, rect).add(table);
}
Aggregations