private static Image GetWatermarkedImage(PdfDocument pdfDocument, Image img) { float width = img.GetImageScaledWidth(); float height = img.GetImageScaledHeight(); Table table = InitTable(width); TableRenderer renderer = (TableRenderer)table.CreateRendererSubTree(); renderer.SetParent(new DocumentRenderer(new Document(pdfDocument))); // Simulate the positioning of the renderer to find out how much space the table will occupy. LayoutResult result = renderer.Layout(new LayoutContext(new LayoutArea( 1, new Rectangle(10000, 10000)))); PdfFormXObject template = new PdfFormXObject(new Rectangle(width, height)); new Canvas(template, pdfDocument) .Add(img) .Close(); float left = 0; float bottom = height - result.GetOccupiedArea().GetBBox().GetHeight(); new Canvas(template, pdfDocument) .Add(table.SetFixedPosition(left, bottom, width)) .Close(); return(new Image(template)); }
public TableHeaderEventHandler(Document doc) { this.doc = doc; InitTable(); TableRenderer renderer = (TableRenderer)table.CreateRendererSubTree(); renderer.SetParent(new DocumentRenderer(doc)); // Simulate the positioning of the renderer to find out how much space the header table will occupy. LayoutResult result = renderer.Layout(new LayoutContext(new LayoutArea(0, PageSize.A4))); tableHeight = result.GetOccupiedArea().GetBBox().GetHeight(); }
public virtual void TableRendererAddByIDTest() { DocumentRenderer documentRenderer = new DocumentRenderer(null); TableRenderer tableRenderer = new TableRenderer(new Table(5)); tableRenderer.SetParent(documentRenderer); String id = "id5"; tableRenderer.SetProperty(Property.ID, id); LayoutContext layoutContext = new LayoutContext(new LayoutArea(4, new Rectangle(50, 50))); tableRenderer.Layout(layoutContext); documentRenderer.GetTargetCounterHandler().PrepareHandlerToRelayout(); NUnit.Framework.Assert.AreEqual((int?)4, TargetCounterHandler.GetPageByID(tableRenderer, id)); }