Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.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
C# 使用nreco.generated将HTML转换为PDF时,第一页空白_C#_Html_Asp.net_Vb.net_Web Site Project - Fatal编程技术网

C# 使用nreco.generated将HTML转换为PDF时,第一页空白

C# 使用nreco.generated将HTML转换为PDF时,第一页空白,c#,html,asp.net,vb.net,web-site-project,C#,Html,Asp.net,Vb.net,Web Site Project,Nreco成功地将我的html代码转换为pdf,但它在pdf的第一页创建了空白页,A4页面大小为5,字母大小为104 我搜索了这个问题,测试了下面的所有样式,但都不起作用 page-break-before:avoid; page-break-after:avoid; page-break-inside :avoid; Dim sw As New StringWriter() Dim htw As New HtmlTextWriter(sw) Panel1.RenderControl(ht

Nreco成功地将我的html代码转换为pdf,但它在pdf的第一页创建了空白页,A4页面大小为5,字母大小为104

我搜索了这个问题,测试了下面的所有样式,但都不起作用

page-break-before:avoid;
page-break-after:avoid;
page-break-inside :avoid;



Dim sw As New StringWriter()
Dim htw As New HtmlTextWriter(sw)
Panel1.RenderControl(htw)
Dim Converter As HtmlToPdfConverter = New HtmlToPdfConverter()
Dim htmlContent As String = sw.ToString()
Dim pdf As Byte() = Converter.GeneratePdf(sw.ToString(),PdfSharp.PageSize.Letter)
Response.Charset = "utf-8"
Response.ContentEncoding = System.Text.Encoding.UTF8
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=" + "test.pdf")
Response.Buffer = True
Response.BinaryWrite(pdf)
Response.Flush()
Response.Clear()
Response.End()

如果使用NReco.PdfGenerator nuget包,则以下行是错误的:

Dim pdf As Byte() = Converter.GeneratePdf(sw.ToString(),PdfSharp.PageSize.Letter)
因为t需要两个参数:第一个字符串是主HTML内容(必需),第二个字符串是“封面”页(第一页的特殊内容),这是可选的(可以为null)

要设置输出页面大小,可以设置:


如果使用NReco.PdfGenerator nuget包,则以下行是错误的:

Dim pdf As Byte() = Converter.GeneratePdf(sw.ToString(),PdfSharp.PageSize.Letter)
因为t需要两个参数:第一个字符串是主HTML内容(必需),第二个字符串是“封面”页(第一页的特殊内容),这是可选的(可以为null)

要设置输出页面大小,可以设置: