use of com.itextpdf.kernel.geom.Rectangle 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.geom.Rectangle in project i7js-highlevel by itext.
the class Renderers 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 = new Paragraph().add(TEXT);
document.add(p);
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
// 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));
document.add(new AreaBreak(AreaBreakType.LAST_PAGE));
for (int i = 0; i < 10; i++) document.add(p);
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
document.setRenderer(new DocumentRenderer(document));
document.add(new AreaBreak(AreaBreakType.LAST_PAGE));
document.add(p);
// Close document
document.close();
}
use of com.itextpdf.kernel.geom.Rectangle 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);
}
use of com.itextpdf.kernel.geom.Rectangle in project pdf-editor by Pdf-Creator.
the class PDFDocument method addRectangleWithFormulaItem.
public void addRectangleWithFormulaItem(FormulaItem formulaItem) throws IOException {
PdfCanvas canvas = new PdfCanvas(currentPage);
Rectangle rect = new Rectangle(formulaItem.getX(), formulaItem.getY(), formulaItem.getW(), formulaItem.getW());
canvas.setStrokeColor(formulaItem.getRectangleStrokeColor()).setFillColor(formulaItem.getRectangleStrokeColor()).rectangle(rect).fill().stroke();
// very strange method
TeXFormula tf = new TeXFormula(formulaItem.getFormula());
TeXIcon ti = tf.createTeXIcon(TeXConstants.STYLE_DISPLAY, formulaItem.getFontSize());
BufferedImage bimg = new BufferedImage(ti.getIconWidth(), ti.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR);
// -- painting the formula --
Graphics2D g2d = bimg.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, ti.getIconWidth(), ti.getIconHeight());
JLabel jl = new JLabel();
jl.setForeground(new Color(0, 0, 0));
ti.paintIcon(jl, g2d, 0, 0);
// --------------------------
// -- adding it to pdf --
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(bimg, "png", byteArrayOutputStream);
ImageData data = ImageDataFactory.create(byteArrayOutputStream.toByteArray());
Image image = new Image(data);
image.setFixedPosition(formulaItem.getX(), formulaItem.getY());
image.scaleAbsolute(formulaItem.getW(), formulaItem.getH());
new Canvas(canvas, rect).add(image);
}
use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.
the class CleanupLicenseEventsTest method cleanUpRedactAnnotationsWithAdditionalLocationSendsCoreAndCleanUpEventTest.
@Test
public void cleanUpRedactAnnotationsWithAdditionalLocationSendsCoreAndCleanUpEventTest() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfDocument document = new PdfDocument(new PdfReader(INPUT_PATH + "absentICentry.pdf"), new PdfWriter(baos));
String oldProducer = document.getDocumentInfo().getProducer();
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
PdfCleanUpLocation lineLoc = new PdfCleanUpLocation(1, new Rectangle(100, 560, 200, 30), ColorConstants.GREEN);
cleanUpLocations.add(lineLoc);
PdfCleaner.cleanUpRedactAnnotations(document, cleanUpLocations);
document.close();
List<ConfirmEvent> events = handler.getEvents();
Assert.assertEquals(2, events.size());
Assert.assertEquals(ITextCoreProductEvent.PROCESS_PDF, events.get(0).getEvent().getEventType());
Assert.assertEquals(PdfSweepProductEvent.CLEANUP_PDF, events.get(1).getEvent().getEventType());
try (PdfDocument pdfDocument = new PdfDocument(new PdfReader(new ByteArrayInputStream(baos.toByteArray())))) {
String expectedProdLine = createExpectedProducerLine(new ConfirmedEventWrapper[] { getCoreEvent(), getCleanUpEvent() }, oldProducer);
Assert.assertEquals(expectedProdLine, pdfDocument.getDocumentInfo().getProducer());
}
}
Aggregations