There are tons of articles out there but they often just show a specific task, so I thought I might do one simple step by step, starting off with the basics. In this article series I use a web application to show how easily you can create a valid PDF document with just a few lines of code, using the tool iTextSharp which is a free. Version 5. After we have downloaded and unzipped the iTextSharp dll and created our project we need to add a reference to iTextSharp. Do that by right clicking the Reference folder in your solution. Select the file by browsing to the save directory and selecting the file iTextSharp.
|Genre:||Health and Food|
|Published (Last):||4 July 2018|
|PDF File Size:||12.44 Mb|
|ePub File Size:||15.38 Mb|
|Price:||Free* [*Free Regsitration Required]|
In fact, these are used in most of the following code samples. You can see that various font faces, sizes, weights, and colors can be specified. The first significant lines of the Build method initialize the file ScienceReport. Next, margins and page size are set. An additional form of metadata is added by the CreateXmpMetadata function, which will be explained later.
After the pages are added to the document, page labels are added by populating a pdfPageLabels object and adding it to the document. At this point the content of the document has been completely written. The only other thing to point out in this sample is the error handling. Catch errors of type iTextSharp. DocumentException to handle errors originating from iTextSharp operations. The next code sample shows two methods: AddPageWithBasicFormatting , which is one of the methods used to add a page to the document, and AddParagraph , which is a helper function used to add a paragraph to current page of the document.
It starts by calling the AddParagraph helper method to add two short text strings to the current page. Notice that when adding a paragraph, you can specify the alignment and font to be used to render the paragraph contents.
Next, a small JPG image is read from disk and inserted into the document. The method finishes up by adding two more paragraphs to the page.
Subscribe to RSS
C# (CSharp) iTextSharp.text.pdf PdfStamper Examples