0

Good day everyone !

Before converting a gridview to PDF I can modify the font size and color using:

gridview.HeaderRow.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
gridview.HeaderRow.Style.Add("font-size", "7.20px");
gridview.HeaderRow.Style.Add("color", "#284775");
gridview.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
gridview.Style.Add("font-size", "6px");

The gridview has different column widths because of the information that is being displayed, those sizes are set .aspx file. But, the generated pdf file auto adjusts the width of each column to be the same size, therefore the information is shrinked and doesnt look good..

I tried the following:

gridview.Width =100;

gridview.Style.Add("width","100");

And many more but haven't been able to adjust the gridview to it's original columns width.

How can I do that?

Thanks in advance.

EDIT: I've also tried:

gridview.Columns[3].ItemStyle.Width =Unit.Pixel(10);

This is the code I use to generate the PDF file:

StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
gridview.HeaderRow.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
gridview.HeaderRow.Style.Add("font-size", "8.20px");
gridview.HeaderRow.Style.Add("color", "#284775");
gridview.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
gridview.Style.Add("font-size", "8px");
gridview.Columns[3].ItemStyle.Width =Unit.Pixel(10);
gridview.RenderControl(htextw);
Document document = new Document(iTextSharp.text.PageSize.LETTER.Rotate(), 10, 10, 42, 35);
string path = "path where im saving file".pdf";
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(path, FileMode.Create));            
StringReader str = new StringReader(stw.ToString());
iTextSharp.text.html.simpleparser.HTMLWorker htmlworker = new HTMLWorker(document);
htmlworker.Parse(str);
Response.Write(document);
document.Close();

EDIT: Found this link while searching and probably that is exactly what I need, but I'm getting the following error when creating the table :

the type or namespace name 'table' does not exist in the namespace 'itextsharp.text'

And I added all the itextsharp references. Is it maybe a version problem?

Heinser Diaz
  • 123
  • 4
  • 15
  • Please post the code that you are using to actually create the PDF along with version of iTextSharp that you are using. Also, before you spend too much time, iTextSharp is not an HTML renderer. It does, however, have some basic support for HTML and CSS although not much compared to a desktop browser. If you are using the `HTMLWorker` consider switching to the `XMLWorker` which all new HTML/CSS code is being added to. – Chris Haas Jun 05 '12 at 19:35
  • @ChrisHaas, I'm using itextsharp 5.2.1.0. Do you have any XMLWorker examples? Thanks for your time. – Heinser Diaz Jun 05 '12 at 23:57

0 Answers0