Search in sources :

Example 6 with Rectangle

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();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Canvas(com.itextpdf.layout.Canvas) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) PdfFont(com.itextpdf.kernel.font.PdfFont) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) PdfPage(com.itextpdf.kernel.pdf.PdfPage) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 7 with Rectangle

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();
}
Also used : ColumnDocumentRenderer(com.itextpdf.layout.ColumnDocumentRenderer) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Rectangle(com.itextpdf.kernel.geom.Rectangle) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) DocumentRenderer(com.itextpdf.layout.renderer.DocumentRenderer) ColumnDocumentRenderer(com.itextpdf.layout.ColumnDocumentRenderer) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 8 with Rectangle

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);
}
Also used : Table(com.itextpdf.layout.element.Table) Canvas(com.itextpdf.layout.Canvas) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas)

Example 9 with Rectangle

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);
}
Also used : ImageData(com.itextpdf.io.image.ImageData) TeXFormula(org.scilab.forge.jlatexmath.TeXFormula) Canvas(com.itextpdf.layout.Canvas) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage) Image(com.itextpdf.layout.element.Image) BufferedImage(java.awt.image.BufferedImage) TeXIcon(org.scilab.forge.jlatexmath.TeXIcon)

Example 10 with Rectangle

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());
    }
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) Rectangle(com.itextpdf.kernel.geom.Rectangle) ConfirmEvent(com.itextpdf.commons.actions.confirmations.ConfirmEvent) ByteArrayOutputStream(com.itextpdf.io.source.ByteArrayOutputStream) PdfReader(com.itextpdf.kernel.pdf.PdfReader) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Aggregations

Rectangle (com.itextpdf.kernel.geom.Rectangle)118 ExtendedITextTest (com.itextpdf.test.ExtendedITextTest)76 IntegrationTest (com.itextpdf.test.annotations.type.IntegrationTest)76 Test (org.junit.Test)76 PdfString (com.itextpdf.kernel.pdf.PdfString)42 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)41 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)37 ArrayList (java.util.ArrayList)29 PdfReader (com.itextpdf.kernel.pdf.PdfReader)22 PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)16 Paragraph (com.itextpdf.layout.element.Paragraph)15 PdfFont (com.itextpdf.kernel.font.PdfFont)12 Document (com.itextpdf.layout.Document)12 Canvas (com.itextpdf.layout.Canvas)11 PdfPage (com.itextpdf.kernel.pdf.PdfPage)10 ColumnDocumentRenderer (com.itextpdf.layout.ColumnDocumentRenderer)9 LogMessages (com.itextpdf.test.annotations.LogMessages)9 AreaBreak (com.itextpdf.layout.element.AreaBreak)8 PdfCleanUpLocation (com.itextpdf.pdfcleanup.PdfCleanUpLocation)8 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)7