![]() Even though it shouldn’t suppose to be too hard to do something like that, we could end up losing too much time if we don’t know how to do it properly. NET Core Web API project in which we need to generate a PDF report. Write the content out using (FileStream fs = new FileStream(unwatermarkedFile,įileMode.Create, FileAccess.Write, FileShare.Let’s imagine that we have a. Stream.Put(PdfName.LENGTH, new PdfNumber( 0)) Remove it by giving it zero length and zero data Loop through each page for ( int i = 1 i = 0 & content.IndexOf(watermarkText) >= 0) Get the number of pages int pageCount2 = reader2.NumberOfPages NOTE: This will destroy all layers in the Document, only use if you don't have any addtional layers // Remove the OCG group completely from the Document: (PdfName.OCPROPERTIES) // Clean up the reader, optional PdfReader reader2 = new PdfReader(watermarkedFile) Finally use a simple stamper to write out the edited reader First we bind a reader to the watermarked file // 2. Removing the layer created above // 1. Convert each stream into Bytes using Static method.Object using GetAsStream(int arrayIndex) method of 's Loop through this array and Get each element as 's.Object using GetAsArray(PdfName.CONTENTS) method of 's Taking the Content of the Page in the 's.Using GetPageN(int pageNumber) method of 's Read the existing watermarked document using 's.Now follow the Steps below to remove the Watermark Text from Layer: You have to remove OCG Group completely from the Document using (PdfName.OCPROPERTIES). To remove all the Layers from PDF Document, So if I remove this Layer we can remove the content of the Whenever we add Layer in PDF Document, then the content of the Layer resides under Removing Watermark from the just created Watermarked Document by Removing Layer: Tell the cb that the next commands should be "bound" to this new layerīaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 50) Ĭb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, watermarkText, rect.Width / 2, rect.Height / 2, 45f) PdfContentByte cb = stamper.GetUnderContent(i) Loop through each Page for ( int i = 1 i <= pageCount i++) PdfLayer layer = new PdfLayer( " WatermarkLayer", stamper.Writer) Getting total number of pages of the Existing Document int pageCount = reader1.NumberOfPages Creating object to write Data from object to FileStream object using (PdfStamper stamper = new PdfStamper(reader1, fs)) Using (FileStream fs = new FileStream(watermarkedFile, FileMode.Create, FileAccess.Write, FileShare.None)) PdfReader reader1 = new PdfReader(originalFile) Creating watermark on a separate layer // Creating object to read the Existing PDF Document String watermarkedFile = " Watermarked.pdf" Step 1: Create a System.IO.FileStream object:.The necessary namespace that you have to add into your C# file to do what are in.Add the following library into your project by adding reference to that library.Or you can download the library DLL from the above link or from To compile this library, you need a C# 2008 compiler or better, Visual Studio 2008.To know the history or any other details of iTextSharp, please go through the Official Website So if any one is interested in using this library, he/she will get a good kick start. I'llĮxplain all the examples of the rest Chapters in my next release of this Article. IText in Action, Second Edition which is written for Java Developers. Frankly speaking, in this Article, you find all the This, then it will help me also as a future reference as I'll describe each functionality Besides, I think that if I write an Article on So, it will be difficult for beginners to convert Yes, there are a few examples in C#, but that is not sufficient to the BeginnersĪnd the examples are in older version of iTextSharp, there are lots The main problem is that lacks of Documentation. Recently I was looking for an Advance Tool to create complex PDF Report in C#.NetĪnd I found iTextSharp. Setting Viewer Preferences of a PDF Document.The following two contents are added in this updated version: Export/Print/Output the PDF File directly to the Client without saving.Adding Watermark to each Page during Creation.Removing Watermark from the just created Watermarked Document by Removing.Adding Watermark to PDF Document using Layer.Creating a New PDF Document from an existing PDF Document.Setting Meta Information or Properties of a PDF Document.Setting Background Color of PDF Document.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |