Canvas extends RootElement<Canvas> { @Override public void close() { if (rootRenderer != null) { rootRenderer.close(); } } Canvas(PdfPage page, Rectangle rootArea);  Canvas(PdfCanvas pdfCanvas, Rectangle rootArea); @Deprecated  Canvas(PdfCanvas pdfCanvas, PdfDocument pdfDocument, Rectangle rootArea);  Canvas(PdfCanvas pdfCanvas, Rectangle rootArea, boolean immediateFlush); @Deprecated  Canvas(PdfCanvas pdfCanvas, PdfDocument pdfDocument, Rectangle rootArea, boolean immediateFlush);  Canvas(PdfFormXObject formXObject, PdfDocument pdfDocument); PdfDocument getPdfDocument(); Rectangle getRootArea(); PdfCanvas getPdfCanvas(); void setRenderer(CanvasRenderer canvasRenderer); PdfPage getPage(); void enableAutoTagging(PdfPage page); boolean isAutoTaggingEnabled(); boolean isCanvasOfPage(); void relayout(); void flush(); @Override void close();  }
@Test @LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.UNABLE_TO_APPLY_PAGE_DEPENDENT_PROP_UNKNOWN_PAGE_ON_WHICH_ELEMENT_IS_DRAWN)) public void canvasNoPageLinkTest() throws IOException, InterruptedException { String testName = "canvasNoPageLinkTest"; String out = destinationFolder + testName + ".pdf"; String cmp = sourceFolder + "cmp_" + testName + ".pdf"; PdfDocument pdf = new PdfDocument(new PdfWriter(out)); PdfPage page = pdf.addNewPage(); Rectangle pageSize = page.getPageSize(); PdfCanvas pdfCanvas = new PdfCanvas(page.getLastContentStream(), page.getResources(), pdf); Rectangle rectangle = new Rectangle( pageSize.getX() + 36, pageSize.getTop() - 80, pageSize.getWidth() - 72, 50); Canvas canvas = new Canvas(pdfCanvas, rectangle); canvas.add( new Paragraph( new Link("Google link!", PdfAction.createURI("https: .setUnderline() .setFontColor(ColorConstants.BLUE))); canvas.close(); pdf.close(); Assert.assertNull(new CompareTool().compareByContent(out, cmp, destinationFolder)); }
@Test public void canvasWithPageLinkTest() throws IOException, InterruptedException { String testName = "canvasWithPageLinkTest"; String out = destinationFolder + testName + ".pdf"; String cmp = sourceFolder + "cmp_" + testName + ".pdf"; PdfDocument pdf = new PdfDocument(new PdfWriter(out)); PdfPage page = pdf.addNewPage(); Rectangle pageSize = page.getPageSize(); Rectangle rectangle = new Rectangle( pageSize.getX() + 36, pageSize.getTop() - 80, pageSize.getWidth() - 72, 50); Canvas canvas = new Canvas(page, rectangle); canvas.add( new Paragraph( new Link("Google link!", PdfAction.createURI("https: .setUnderline() .setFontColor(ColorConstants.BLUE))); canvas.close(); pdf.close(); Assert.assertNull(new CompareTool().compareByContent(out, cmp, destinationFolder)); }
@Test public void canvasWithPageEnableTaggingTest01() throws IOException, InterruptedException { String testName = "canvasWithPageEnableTaggingTest01"; String out = destinationFolder + testName + ".pdf"; String cmp = sourceFolder + "cmp_" + testName + ".pdf"; PdfDocument pdf = new PdfDocument(new PdfWriter(out)); pdf.setTagged(); PdfPage page = pdf.addNewPage(); Rectangle pageSize = page.getPageSize(); Rectangle rectangle = new Rectangle( pageSize.getX() + 36, pageSize.getTop() - 80, pageSize.getWidth() - 72, 50); Canvas canvas = new Canvas(page, rectangle); canvas.add( new Paragraph( new Link("Google link!", PdfAction.createURI("https: .setUnderline() .setFontColor(ColorConstants.BLUE))); canvas.close(); pdf.close(); Assert.assertNull(new CompareTool().compareByContent(out, cmp, destinationFolder)); }