As a result, using the FormXObject.getWidth() and FormXObject.getHeight() resulted in incorrect dimensions that squashed the stamp image. Not only does it give a greater height when the page is clearly landscape, but it also is not reflective of the true page size. Apparently, the FormXObject that encompasses the PDF file to merge does not store the corresponding Width and Height of the page it is storing. How do you go around this issue?Īlright so after hours of staring at the screen, I found out the hard way why my stamps were dimensioned incorrectly. However, that in turn sets my stamp image invisible as well. I tried using the "Graphics State" ( PdfGState state), setting its Opacity to 0, and applying it to the Canvas. My initial assumption is that the Canvas object has some sort of fill color that defaults to black? How would you go about setting the black fill to transparent. My stamp ends up appearing with a BLACK background. In attempting to turn it into a transparent PNG, I end up with a weird result. However, unlike my Adobe stamps, the images retain their white background and hence are not transparent. If I am not mistaken, the process of stamping using iText involves the use of an external image file - which I did. PdfDoc.GetFirstPage().AddAnnotation(stamp) Stamp.SetNormalAppearance(xObj.GetPdfObject()) PdfCanvas canvas = new PdfCanvas(xObj, pdfDoc) Ĭanvas.AddImage(img, 0, 0,iWidth, false) PdfFormXObject xObj = new PdfFormXObject(new Rectangle(iWidth, iHeight)) PdfStampAnnotation stamp = new PdfStampAnnotation(location).SetStampName(new PdfName("Logo")) Rectangle location = new Rectangle(crop.GetLeft(),crop.GetBottom(),iWidth/4,iHeight/4) ImageData img = ImageDataFactory.Create(imgsrc) ĭebug.WriteLine("Width = "+w+" and Height = "+h) Rectangle crop = pdfDoc.GetPage(1).GetCropBox() ĭebug.WriteLine("CropBox Rectangle Dim "+crop) PdfDocument pdfDoc = new PdfDocument(reader, writer) Thankfully, with some help, I got my stamp working using the following code: PdfReader reader = new PdfReader(source)
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |