Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 带有css的Htm到pdf转换器_Asp.net_C# 4.0_Itextsharp_Wkhtmltopdf - Fatal编程技术网

Asp.net 带有css的Htm到pdf转换器

Asp.net 带有css的Htm到pdf转换器,asp.net,c#-4.0,itextsharp,wkhtmltopdf,Asp.net,C# 4.0,Itextsharp,Wkhtmltopdf,我已经使用itextsharp.dll将html转换为Pdf。它工作得很好,唯一的问题是它不会在pdf中呈现css。我的代码如下: string[] attachment; Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=Certificate.pdf"); Re

我已经使用itextsharp.dll将html转换为Pdf。它工作得很好,唯一的问题是它不会在pdf中呈现css。我的代码如下:

 string[] attachment;
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=Certificate.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            System.Text.StringBuilder ss = new System.Text.StringBuilder(CertificateHtml);
            StringWriter sw = new StringWriter(ss);
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);


            string PdfName = "Certificate" + name;
            PdfWriter.GetInstance(pdfDoc, new FileStream(Server.MapPath("~/DesktopModules/SterlingPlanet-SP_CheckOut/PDfCertificate/" + PdfName + ".pdf"), FileMode.Create));

            pdfDoc.Open();
            htmlparser.Parse(sr);

            pdfDoc.Close();
我的css就像傻瓜一样

body {
    font-family: Conv_Californian FB,Arial;
    margin: 0;
    padding: 0;
}
#wrapper {
    background: url("../images/bg.jpg") no-repeat scroll 0 0 transparent;
    height: 719px;
    margin: 25px auto 0;
    position: relative;
    width: 959px;
}
.wrapper_inner {
    color: White;
    text-align: center;
    width: 100%;
}
.wrapper_inner h1 {
    color: #FFFFFF;
    font-size: 65px;
    letter-spacing: 16px;
    padding-top: 38px;
    text-align: center;
}
.wrapper_inner h6 {
    color: #FFFFFF;
    font-size: 17px;
    letter-spacing: 10px;
    margin: -53px;
    text-align: center;
}

是否有任何替代itextsharp.dll的方法可以使用css将html转换为pdf,或者如果我缺少任何可以将css转换为html的代码,请提供帮助。

当我过去在安全服务器上处理此问题时,我必须在传递到pdf转换器之前更改css引用。在图像引用方面也有类似的问题


如果引用指向安全服务器,转换器将看不到它,如果它指向非安全服务器,则安全页面会向用户唠叨不安全的内容。

使用内联css和像素大小,它在itextsharp html到pdf中不起作用。

HTMLWorker类已被弃用,不再受支持。相反,我们鼓励您使用XMLWorker。它是否没有呈现任何CSS,或者只是未能呈现背景图像:
background:url(“../images/bg.jpg”)
?证书先生,我正在使用上面的内联样式,但它仍然无法加载以下图像。请使用pdfpcell并使用边框,然后在添加解析html时使用and和cell.addelement(),这样应该可以正常工作。等等,我给你举个例子。