Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two code:
aspx:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Master Unlock Code</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <div style="text-align:center">
        
        <img src="images/logo.png" style="width: 185px; height: 200px" /></div>&nbsp;
       <div>
            <span style="font-size: 14pt; color: red"><em>Customer Name: Pham Duy Hoa</em></span><br />
            <span><em>Customer Phone</em>: <strong>0937927904</strong></span><br />
            <span><em>Customer Address</em>: <strong>TCH05</strong></span><br />
            <span><em>Date Invoice</em>:<strong> 02/06/2011</strong></span><br />
            
       </div>


and c#:
private string ReadHTMLCode(string URL)
 {

     try
     {
         WebClient webClient = new WebClient();
         byte[] reqHTML = webClient.DownloadData(URL);
         UTF8Encoding objUTF8 = new UTF8Encoding();
         return objUTF8.GetString(reqHTML);
     }
     catch (Exception Ex)
     {

     }
     return "error";
 }

 protected void Button1_Click(object sender, System.EventArgs e)
 {
     String htmlText = ReadHTMLCode(("http://localhost:52978/WebSite22/Default.aspx")).Replace("\"", "'").Replace("px", "").Replace("images", "http://localhost:52978/WebSite22/images").Replace("color", "").Replace("function", "");
     HTMLToPdf(htmlText, "PDFfile.pdf");
 }

 public void HTMLToPdf(string HTML, string FilePath)
 {
     Document document = new Document();

     PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "\\PDFfile.pdf", FileMode.Create));


     document.Open();
     //Image pdfImage = Image.GetInstance(Server.MapPath("logo.png"));
     //pdfImage.ScaleToFit(100, 50);
     //pdfImage.Alignment = iTextSharp.text.Image.UNDERLYING; pdfImage.SetAbsolutePosition(180, 760);
     //document.Add(pdfImage);
     iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
     hw.Parse(new StringReader(HTML));
     document.Close();
     ShowPdf("PDFfile.pdf");
 }
 private void ShowPdf(string s)
 {
     Response.ClearContent();
     Response.ClearHeaders();
     Response.AddHeader("Content-Disposition", "inline;filename=" + s);
     Response.ContentType = "application/pdf";
     Response.WriteFile(s);
     Response.Flush();
     Response.Clear();
 }


but document when export to the pdf don't using css:style.css
{
 color:Red;
 font-family:Times New Roman;
 font-size:13px ;  
}

when i format html to pdf.
please help me.
Posted
Comments
Sergey Alexandrovich Kryukov 2-Jun-11 0:09am    
Do not re-post. This question is really close to the previous one. Better use "Improve question" and post it on the page where your previous question is.
--SA
[no name] 2-Jun-11 0:20am    
Don't cross post.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900