以下是有关我的开发环境的信息:
-Microsoft Visual Studio Professional 2013
- .NET Framework 4.0
-jquery.min.js(1.11.3)
-Select.HtmlToPdf(2.0.1.0)
-jQuery DataTables(1.10.7)
在我们的应用程序中,我们有一个ASPX页面,其中包含动态填充的jquery DataTables和一个在运行时使用jquery动态生成的图形。
我们希望使用Select.HtmlToPdf(2.0.1.0)来创建pdf文件,该文件在Web浏览器中呈现时看起来就像上面提到的ASPX页面。
在我们的ASPX页面中,我们有一个下载pdf ASPX服务器端按钮,它调用ASPX代码后面文件中定义的以下C#方法:
public void generatePDF()
{
// instantiate a html to pdf converter object
HtmlToPdf converter = new HtmlToPdf();
var url =
HttpContext.Current.Server.MapPath("~/hos/pdf/displayTemplate.html");
Console.WriteLine(url.ToString());
SelectPdf.GlobalProperties.HtmlEngineFullPath =
HttpContext.Current.Server.MapPath("~/hos/pdf/SelectPdfAuxiliaries/Select.Html.dep");
PdfDocument doc = converter.ConvertUrl(url.ToString());
// save pdf document
doc.Save(Response, false, "displayContent.pdf");
}
displayTemplate.html包含将调用ASHX处理程序的AJAX jquery函数:
function GetHandlerTestJS() {
var testHandlerData = new FormData();
testHandlerData.append("handlerTestId", "1");
$.ajax({
type: "Post",
contentType: "application/json; charset=utf-8",
url: "testHandler.ashx",
enctype: 'multipart/form-data',
contentType: false,
processData: false,
data: testHandlerData,
dataType: "json",
success: function (data) {
$('#handlertestDebug').html(data);
//getSignatureImage();
},
error: function (Result) {
$('#handlertestDebug').html("error in handler test"); $('#handlertestResultDebug').html(Result);
}
//beforeSend: function () { $('#loader').show() }, //complete: function () { $('#loader').hide(); }
});
}
$(function () {
$(document).ready(function () {
console.log("Inside Start");
GetHandlerTestJS();
});
});
问题是当使用名为ConvertUrl的Select.HtmlToPdf(2.0.1.0)的API方法时,无法调用ASHX处理程序:
PdfDocument doc = converter.ConvertUrl(url.ToString());
有人可以告诉我我需要对上述代码做出哪些更改,以便使用Select.HtmlToPdf(2.0.1.0)的API从html调用处理程序?
答案 0 :(得分:1)
您是否尝试过使用testHandler.ashx的完整绝对路径?