Create/Read Advance PDF Report using i. Text. Sharp in C# . NET: Part ICreate/Read/Write Advance PDF Report using i. Text. Sharp. DLL in Desktop, Mobile, Web Application. Recently I was looking for an Advance Tool to create complex PDF Report in C#. Net. and I found i. Text. Sharp. The main problem is that lacks of Documentation. So, it will be difficult for beginners to convert. Besides, I think that if I write an Article on. I'll describe each functionality. Frankly speaking, in this Article, you find all the. Chapter 1 of the book. Text in Action, Second Edition which is written for Java Developers. I'll. explain all the examples of the rest Chapters in my next release of this Article. Then. do the following: Add the following library into your project by adding reference to that library. DLL. Just see the image below: The necessary namespace that you have to add into your C# file to do what are in. Article are: . i. Text. Sharp. texti. Text. Sharp. text. Creating PDF Document in 6 Steps: Step 1: Create a System. IO. File. Stream object: File. Stream fs = new File. Stream(. It helps to. Document to the Specified File. Stream: Pdf. Writer writer = Pdf. Writer. Get. Instance(doc, fs); Step 4: Openning the Document: doc. Open(); Step 5: Adding a Paragraph by creating a i. Text. Sharp. text. Paragraph object: doc. Add(new Paragraph(. There are a few way. Page Size. First Way to define Page Size. Creating Page Size by Pixels or Inch. NOTE: In i. Text. 2012/04/converting-html-to-pdf-using-itextsharp.html Using. Create a PDF document file in C#. This article describes how we can create a multi-page pdf using iTextSharp. When you are done with iTextSharp dll reference, create the HTML. Automatically create standards compliant PDFs from databases. Leading PDF library company iText Software is proud to announce the official launch of. I was trying to create a pdf document which should show document in table format in C#. So at first I added iTextSharp. Sharp library, unit is 'point'. Suppose we want to create a PDF File of width = 2 inch &. Lets see. how to do this: Rectangle rec = new Rectangle(1. Second Way to define Page Size: Taking Page Size from in- built i. Text. Sharp. text. ASP.Net C# Convert HTML to PDF using iTextSharp. Page. Size class: Rectangle rec. Rectangle(Page. Size. A4). The following are the Supported in- built Page Size. Read the full. Documentation of Page Size. Base. Color constructor. System. Drawing. Color object Or you can pass RGB values to the constructor. Background. Color = new Base. Color(System. Drawing. Color. White. Smoke); Second Way to Set Background Color: It takes the object of i. Text. Sharp. text. CMYKColor. CMYKColor constructor. CMYK values in different forms: rec. Background. Color = new CMYKColor(2. Setting Page Margins of PDF Document. Margins can be set during Document object creation like Page Size. Suppose we set the margins as below. Left Margin: 0. 5 inch. Right Margin: 1 inch. Top Margin: 1. 5 inch. Bottom Margin: 2. So, we need to do set the following points for the Left, Right, Top, Bottom Margins. Text. Sharp library only understand. Left Margin: 3. 6pt => 0. Right Margin: 7. 2pt => 1 inch. Top Margin: 1. 08pt => 1. Bottom Margini: 1. Lets implement: Document doc = new Document(Page. Size. A4, 3. 6, 7. Setting Text Alignment in PDF Document: Alignment is one of the property of i. Text. Sharp. text. Paragraph's. object. These. Alignments can be access through i. Text. Sharp. text. Element class. The. Alignment types provides i. Text. Sharp. As we already see the i. Text. Sharp. text. Document's constructor takes. Text. Sharp. text. Paragraph's object during Document creation. So, after. creating the Paragraph object and setting Alignment property, we can pass this object. Text. Sharp. text. Document's constructor during Document ceration. Lets add five pages in PDF Document: for (int i = 1; i < = 5; i++). Lets implement: string original. File = ! Here I'll add Watermark to existing PDF Document i. Original. pdf. through creating a i. Text. Sharp. text. Pdf. Layer object. Lets implement: string watermarked. File = . So if I remove this Layer we can remove the content of the. Layer also e. g. To remove all the Layers from PDF Document. OCG Group completely from the Document using reader. Catalog. Remove(Pdf. Name. OCPROPERTIES). So, I've created a class PDFWriter. Events. which implements the interface i. Text. Sharp. text. IPdf. Page. Event and. On. Start. Page. This interface contains a set of events. Openning & to Closing the PDF Document. The events are following: public void On. Open. Document(Pdf. Writer writer, Document document)public void On. Close. Document(Pdf. Writer writer, Document document)public void On. Start. Page(Pdf. Writer writer, Document document)public void On. End. Page(Pdf. Writer writer, Document document)public void On. Paragraph(Pdf. Writer writer, Document document, float paragraph. Position)public void On. Paragraph. End(Pdf. Writer writer, Document document, float paragraph. Position)public void On. Chapter(Pdf. Writer writer, Document document, float paragraph. Position. Paragraph title)public void On. Chapter. End(Pdf. Writer writer, Document document, float paragraph. Position)public void On. Section(Pdf. Writer writer, Document document, float paragraph. Position. int depth, Paragraph title)public void On. Section. End(Pdf. Writer writer, Document document, float paragraph. Position)public void On. Generic. Tag(Pdf. Writer writer, Document document, Rectangle rect. String text). You may modify other events accroding to your needs which occured against a particular. Let see the which I've created: class PDFWriter. Events : IPdf. Page. Event. need to add watermark later: ). Export/Print/Output the PDF File directly to the Client without saving it to the. We can create PDF File in memory by creatig System. IO. Memory. System's. Lets see: using (Memory. Stream ms = new Memory. Stream()). using(Document document = new Document(Page. Size. A4, 2. 5, 2. Pdf. Writer writer = Pdf. Writer. Get. Instance(document, ms)). Viewer. Preferences by following two ways. By setting property Viewer. Preferences of i. Text. Sharp. text. Pdf. Writer. class. To know all the Viewer. Preferences and its purpose, please read. E. g.- writer. Viewer. Preferences = Pdf. Writer. Hide. Menubar; By calling method Add. Viewer. Preference(Pdf. Name key, Pdf. Object value). Text. Sharp. text. Pdf. Writer's object. To know which value. E. g.- writer. Add. Viewer. Preference(Pdf. Name. HIDEMENUBAR, new Pdf. Boolean(true)). Encrypting a PDF Document. By Set. Encryption() method of i. Text. Sharp. text. Pdf. Writer's. object, we can encrypt a PDF document. Read full documentation of this method. To know all the encryption types, click. E. g.- writer. Set. Encryption(Pdf. Writer. STRENGTH4. 0BITS, null, null, Pdf. Writer. ALLOW. I hope you'll understand as the source. If any doubt, just post your comment below. PART- II will release soon : ).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2016
Categories |