When I try to convert HTML to PDF using iTextSharp
, the CSS styling I apply to the webpage does not get carried over to the converted PDF file.
Here is the CSS code I am using:
<style type="text/css">
.cssformat
{
width:300px;
height:200px;
border:2px solid black;
background-color:white;
border-top-left-radius:60px 90px;
border-bottom-right-radius:60px 90px;
}
</style>
And here is my HTML code:
<div id="divpdf" runat="server">
<table id="tid" runat="server">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="this is new way of pdf" CssClass="cssformat"></asp:Label>
</td>
</tr>
</table>
</div>
I have attempted the following in C#:
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
Document pdfDoc = new Document(PageSize.A4, 60f, 80f, -2f, 35f);
divpdf.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
hw1.Parse(new StringReader(sttt));
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
sw.Close();
sr.Close();
hw.Close();