![]() ![]() Get maximum performance from the most respected and secure eSignature platform. What about variable length watermark text? How would you dynamically resize the rectangle to fit the text? This is not inbuilt into iText, you would need to play around with the following dimension parameters: float watermarkTrimmingRectangleWidth = 600 įloat watermarkTrimmingRectangleHeight = 600 įor my use-case I checked the length of the watermark text and based on that adjusted the parameters accordingly eg: if (watermarkText.Your step-by-step guide - delete watermark onlineĪccess helpful tips and quick steps covering a variety of signNow’s most popular features.ĭelete watermark certificate. If ((annotation.GetAsName(PdfName.Subtype))) PdfDictionary annotation = annots.GetAsDictionary(j) PdfArray annots = pageDict.GetAsArray(PdfName.Annots) PdfDictionary pageDict = pdfDoc.GetPage(i).GetPdfObject() To remove the watermark: public void RemovetWatermarkPDF(string sourceFile, string destinationPath) Watermark.SetAppearance(PdfName.N, new PdfAnnotationAppearance(form.GetPdfObject())) SetTextMatrix(transformValues, transformValues, transformValues, transformValues, transformValues, transformValues) BeginText().SetColor(Color.GRAY, true).SetExtGState(gs1) PdfCanvas canvas = new PdfCanvas(form, pdfDoc) PdfExtGState gs1 = new PdfExtGState().SetFillOpacity(0.6f) PdfFormXObject form = new PdfFormXObject(formRectangle) Observation: font XObject will be resized to fit inside the watermark rectangle Rectangle formRectangle = new Rectangle(formXOffset, formYOffset, formWidth, formHeight) PdfFixedPrint fixedPrint = new PdfFixedPrint() Transform.Translate(xTranslation, yTranslation) PdfWatermarkAnnotation watermark = new PdfWatermarkAnnotation(watermarkTrimmingRectangle) ĪffineTransform transform = new AffineTransform() //No-args constructor creates the identity transform Rectangle watermarkTrimmingRectangle = new Rectangle(bottomLeftX, bottomLeftY, watermarkTrimmingRectangleWidth, watermarkTrimmingRectangleHeight) PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFile), new PdfWriter(destinationPath)) įloat bottomLeftX = ps.GetWidth() / 2 - watermarkTrimmingRectangleWidth / 2 įloat bottomLeftY = ps.GetHeight() / 2 - watermarkTrimmingRectangleHeight / 2 PdfFont font = PdfFontFactory.CreateFont(FontConstants.TIMES_ROMAN) To add a watermark on every page: public void WatermarkPDF(string sourceFile, string destinationPath)įloat watermarkTrimmingRectangleWidth = 300 įloat watermarkTrimmingRectangleHeight = 300 If you intend to remove the watermark later, you will need to add it as a 'PDF watermark annotation'. With help from the guys at iText I was able to solve this. Not what I want.need to remove the layer Var t = layers.GetPdfObject().Get(PdfName.Name) PageSize ps = pdfDoc.GetDefaultPageSize() įor (var i = 1 i layers = pdfDoc.GetCatalog().GetOCProperties(true).GetLayers() ![]() Var numberOfPages = pdfDoc.GetNumberOfPages() This is how I added the Watermark (using Layers): pdfDoc = new PdfDocument(new PdfReader(sourceFile), new PdfWriter(destinationPath)) ![]() I could only find relevant code/examples related to iText 5. I was able to add the watermark, but unable to remove it again. #PDF PLUS REMOVE TRIAL WATERMARK PDF#I would like to add and remove a watermark to a PDF using iText 7. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |