This project has moved and is read-only. For the latest updates, please go here.

Suppose we have a list of users with their names and photos. We want to show the name and photo of each user in one cell and not 2 separate cells.
Built-in cell templates of PdfReport are suitable for displaying only one object per each cell. To define a custom cell template, we need to implement the IColumnItemsTemplate interface or using a shortcut:

                 columns.AddColumn(column =>
                     column.CalculatedField(list =>
                             var user = list.GetSafeStringValueOf("User");
                             var photo = new Uri(list.GetSafeStringValueOf("Photo"));
                             var image = string.Format("<img src='{0}' />", photo);
                                    @"<table style='width: 100%; font-size:9pt;'>
                                                    <td>" + user + @"</td>
                                                    <td>" + image + @"</td>
                     column.ColumnItemsTemplate(template =>
                             template.Html(); // Using iTextSharp's limited HTML to PDF capabilities (HTMLWorker class).

Here iTextSharp's HTMLWorker class is used behind the scene. By using the CalculatedField, we can inject our new value of a cell and then process it by the selected ColumnItemsTemplate.
Note: HTML to PDF capabilities of  iTextSharp's HTMLWorker class is very limited, and don't expect too much about it.

You can find this sample here: (+)

Last edited Nov 7, 2012 at 5:26 PM by VahidN, version 3


No comments yet.