我在没有 runat="server" 的 .aspx pahe 中有名为 RPTHtml 的字段
<asp:HiddenField ID="RPTHtml" />
并在javascript中添加此代码并调用此页面的pagemethod
document.getElementById('RPTHtml').setValue =window.encodeURI
(document.getElementById(eval(result)[0].columnLineConfig.divToRender).innerHTML);
PageMethods.getHTMLToPdf(eval(result)[0].columnLineConfig.divToRender, srcurl);
现在,在我的页面方法中
<WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function getHTMLToPdf(ByVal div As String, ByVal InnerHTMl As String) As Boolean
Dim pdfDocument As PdfDocument.Document = Nothing
Dim pdfConverter As PdfConverter = New PdfConverter()
Dim pdfBytes As Byte() = Nothing
Dim strHtml As String = ""
Dim htmlreport As String = ""
Dim ReportFileName As String = ""
Dim Response_1 As HttpResponse = System.Web.HttpContext.Current.Response
If InnerHTMl.ToString() = "" Then
Exit Function
End If
htmlreport = InnerHTMl.ToString()
htmlreport = HttpUtility.UrlDecode(htmlreport)
Response_1.Clear()
Response_1.Buffer = True
Response_1.ClearContent()
Response_1.ClearHeaders()
ReportFileName = GetReportName() + ".pdf"
pdfConverter = New Winnovative.WnvHtmlConvert.PdfConverter()
pdfConverter.AvoidImageBreak = True
pdfConverter.AvoidTextBreak = True
pdfConverter.TruncateOutOfBoundsText = True
pdfConverter.LicenseKey = "LicenseKey"
pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4
pdfConverter.PdfDocumentOptions.StretchToFit = True
pdfBytes = pdfConverter.GetPdfBytesFromHtmlString(htmlreport)
Response_1.AddHeader("Content-type", "application/pdf")
Response_1.AddHeader("Content-Disposition", "attachment; filename=" + ReportFileName)
Response_1.BinaryWrite(pdfBytes)
Response_1.Flush()
Response_1.End()
End Function
它没有给出任何输出,只是成功运行,但没有出现下载 pdf 的提示。
我错过了什么?或者它不能通过pagemethod实现。提前致谢!!!