In this article I will give fully functioning examples in C and VB. So, for example, in the report for this article I have rotated the text in the first column to save space. You will see that only the most basic styling is supported. Check out my other articles on the subject if you are interested in more articles about generating PDF documents in. The overall steps are: Import the iTextSharp.
|Published (Last):||10 December 2005|
|PDF File Size:||6.27 Mb|
|ePub File Size:||12.70 Mb|
|Price:||Free* [*Free Regsitration Required]|
Specifically, I will show how to absolutely size your PDF table, how to right and center align Phrase objects in your table cells, and how to horizontally and vertically align text in rotated cells.
However you may want to control the width of your table. This width must equal the width of the columns specified as a float array.
Next we populate the table with a float array of column sizes in Step 2 using the iTextSharp SetWidths method. Horizontally Align a Phrase in your PdfPCell If you are setting the horizontal alignment of text in an iTextSharp table cell, there is a difference between setting a Phrase and a Paragraph. For the sake of simplicity, we will use an example of a single Phrase in a table cell. AddCell CellTreeHdr ; Horizontally and Vertically Align a Phrase in a Rotated PdfPCell Things get a little more interesting when you are rotating one of your table cells, especially if you are spanning several rows and want to control the alignment both vertically and horizontally.
The key concept is that no matter how far you rotate your cell, iTextSharp will consider vertical and horizontal directions based on the original cell. What this means is that if you rotate your cell 90 degrees clockwise and top-align the text in your cell, the cell text will appear horizontally right aligned.
Likewise, if you right align your text horizontally and then rotate your cell 90 degrees clockwise, iTextSharp will render the cell text as bottom-aligned. Here is a code snippet that shows text rotated 90 degrees clockwise that is set to be top-aligned vertically and center aligned horizontally.
This code renders the text as horizontally right-aligned and vertically center aligned. If you are running the example, it consists of a page with a clickable button. Once the button is clicked, a PDF pops up with a styled iTextSharp table that looks like the screen capture at the start of this article.
GetFont "Arial", 8, iTextSharp. MapPath ". Create ; doc. AddCell CellTreeR2 ; doc. Add myTable ; doc. Close ; ScriptManager. RegisterStartupScript this.
Page, this. GetType , "myscript", "window.
Exporting Data From DataTable To PDF
iTextSharp - Working with Fonts
How can we export datatable to PDF using iTextSharp