I have this pdf page i got through Itext pdf, but it is not coming out well.
The html table does not appear with their background colour in pdf file, it is just plain table background in the original page.
Lastly the text are clumsy, it is not looking professional at all.
Please help
My code
<style>
#customers {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#customers td, #customers th {
border: 1px solid #ddd;
padding: 8px;
}
#customers tr:nth-child(even) {
}
#customers th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #4CAF50;
color: white;
}
#customers0 {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
table.roundedCorners {
border: 1px solid DarkOrange;
border-radius: 13px;
border-spacing: 0;
}
table.roundedCorners td,
table.roundedCorners th {
border-bottom: 1px solid DarkOrange;
padding: 4px;
}
table.roundedCorners tr:last-child > td {
border-bottom: none;
}
</style>
<asp:Panel ID="Panel2" runat="server">
<table align="center" height="70%" style="width: 1100px;">
<tr>
<td align="center">
<asp:Button ID="btnExport" runat="server" Text="EXPORT TO PDF" OnClick="ExportToPDF" />
<asp:Button ID="btnExport0" runat="server" OnClick="PRINT" Text="PRINT" Width="154px" />
<asp:Label
ID="Label25" runat="server" Visible="False"></asp:Label>
<asp:Label ID="Label26" runat="server" Visible="False"></asp:Label>
<asp:Label ID="Label27" runat="server" Visible="False"></asp:Label>
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="False"
Font-Names="Arial Narrow"
Font-Size="13px" DataKeyNames="unit"
Width="100%" Style="margin-bottom: 0px"
CssClass="grid" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="unit" HeaderText="UNIT" />
<asp:BoundField DataField="colour" HeaderText="COLOUR" />
<asp:BoundField DataField="inkcoverage" HeaderText="INK.COV" />
<asp:BoundField DataField="inkcode" HeaderText="INK CODE" />
<asp:BoundField DataField="posino" HeaderText="POSI NO" />
<asp:BoundField DataField="referencecolour" HeaderText="REF.COLOUR" />
<asp:BoundField DataField="screen" HeaderText="SCREEN/ANGLE/LENS SURF" />
<asp:BoundField DataField="stylusangle" HeaderText="STYLUS ANGLE" />
<asp:BoundField DataField="depth" HeaderText="DEPTH" />
<asp:BoundField DataField="xdiagonal" HeaderText="XDIAGONAL/BRD SURF" />
<asp:BoundField DataField="stretchfactor" HeaderText="STRETCHFACTOR" />
<asp:BoundField DataField="RAVINGtype" HeaderText="RAVING" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</td>
</tr>
</table>
</asp:Panel>
protected void ExportToPDF(object sender, EventArgs e)
{
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
Panel2.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 0f, 0f, 0f, 0f);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
}
}
}