private void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); Document doc = new Document(pdfDoc); ImageData img = ImageDataFactory.Create(IMG); Image image = new Image(img); PdfPattern.Tiling imgPattern = new PdfPattern.Tiling(image.GetImageScaledWidth(), image.GetImageScaledHeight()); PdfPatternCanvas canvas = new PdfPatternCanvas(imgPattern, pdfDoc); canvas.AddImageAt(img, 0, 0, false); Color color = new PatternColor(imgPattern); Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth(); table.AddCell(new Cell().Add(new Paragraph("Behold a cell with an image pattern:"))); Cell cell = new Cell(); cell.SetHeight(60); cell.SetBackgroundColor(color); table.AddCell(cell); doc.Add(table); doc.Close(); }
protected void ManipulatePdf(string dest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); Document doc = new Document(pdfDoc); PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage()); PdfFont font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA); string fillText = "this is the fill text! "; float fillTextWidth = font.GetWidth(fillText, 6); PdfPattern.Tiling tilingPattern = new PdfPattern.Tiling(fillTextWidth, 60, fillTextWidth, 60); PdfPatternCanvas patternCanvas = new PdfPatternCanvas(tilingPattern, pdfDoc); patternCanvas.BeginText().SetFontAndSize(font, 6f); float x = 0; for (float y = 0; y < 60; y += 10) { patternCanvas.SetTextMatrix(x - fillTextWidth, y); patternCanvas.ShowText(fillText); patternCanvas.SetTextMatrix(x, y); patternCanvas.ShowText(fillText); x += (fillTextWidth / 6); } patternCanvas.EndText(); canvas.Rectangle(10, 10, 575, 822); canvas.SetFillColor(new PatternColor(tilingPattern)); canvas.Fill(); doc.Close(); }
public override void Draw(DrawContext drawContext) { PdfPattern.Tiling imgPattern = new PdfPattern.Tiling(img.GetWidth(), img.GetHeight(), img.GetWidth(), img.GetHeight()); PdfPatternCanvas patternCanvas = new PdfPatternCanvas(imgPattern, drawContext.GetDocument()); patternCanvas.AddImageAt(img, 0, 0, false); PdfCanvas canvas = drawContext.GetCanvas(); canvas.SaveState(); ColorRectangle(canvas, new PatternColor(imgPattern), GetOccupiedAreaBBox().GetX(), GetOccupiedAreaBBox().GetY(), GetOccupiedAreaBBox().GetWidth(), GetOccupiedAreaBBox().GetHeight()); canvas.SetFillColor(new PatternColor(imgPattern)); canvas.Stroke(); canvas.RestoreState(); }