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?