我正在使用 ITextSharp 和 html2canvas 来添加二进制图片和 PDF生成。
以下是我的Codebehind
代码的摘要。
var overallResultsBase64string = hdnOverallResults.Value.Replace("data:image/png;base64,", "");
var appServerCapacityBase64string = hdnAppServerCapacity.Value.Replace("data:image/png;base64,", "");
var appPerformanceBase64string = hdnAppPerformance.Value.Replace("data:image/png;base64,", "");
var dbServerCapacityBase64string = hdnDBServerCapacity.Value.Replace("data:image/png;base64,", "");
var dbPerformanceBase64string = hdnDBPerformance.Value.Replace("data:image/png;base64,", "");
iTextSharp.text.Image overallResultsImg, appServerCapacityImg, appPerformanceImg
, dbServerCapacityImg, dbPerformanceImg;
byte[] overallResultsBytes = Convert.FromBase64String(overallResultsBase64string);
overallResultsImg = iTextSharp.text.Image.GetInstance(overallResultsBytes);
byte[] appServerCapacityBytes = Convert.FromBase64String(appServerCapacityBase64string);
appServerCapacityImg = iTextSharp.text.Image.GetInstance(appServerCapacityBytes);
byte[] appPerformanceBytes = Convert.FromBase64String(appPerformanceBase64string);
appPerformanceImg = iTextSharp.text.Image.GetInstance(appPerformanceBytes);
byte[] dbServerCapacityBytes = Convert.FromBase64String(dbServerCapacityBase64string);
dbServerCapacityImg = iTextSharp.text.Image.GetInstance(dbServerCapacityBytes);
byte[] dbPerformanceBytes = Convert.FromBase64String(dbPerformanceBase64string);
dbPerformanceImg = iTextSharp.text.Image.GetInstance(dbPerformanceBytes);
document.Add(overallResultsImg);
document.Add(new Paragraph("OVERALL APPLICATION PERFORMANCE"));
document.Add(appPerformanceImg);
document.Add(dbPerformanceImg);
document.Add(new Paragraph("OVERALL SERVER CAPACITY"));
document.Add(appServerCapacityImg);
document.Add(dbServerCapacityImg);
var appServerCapacityBase64string
NULL
,它会引发IndexOutOfBounds
例外
byte[] appServerCapacityBytes = Convert.FromBase64String(appServerCapacityBase64string);
appServerCapacityImg = iTextSharp.text.Image.GetInstance(appServerCapacityBytes);
我的 Javascript html2canvas 代码有问题吗?请检查。
<script>
html2canvas($("#overallResultsDiv"), {
onrendered: function (canvas) {
// canvas is the final rendered <canvas> element
var myImage = canvas.toDataURL("image/png");
document.getElementById("hdnOverallResults").value = myImage;
}
});
html2canvas($("#appServerCapacityDiv"), {
onrendered: function (canvas) {
// canvas is the final rendered <canvas> element
var myImage = canvas.toDataURL("image/png");
$("#hdnAppServerCapacity").value = myImage;
}
});
html2canvas($("#appPerformanceDiv"), {
onrendered: function (canvas) {
// canvas is the final rendered <canvas> element
var myImage = canvas.toDataURL("image/png");
document.getElementById("hdnAppPerformance").value = myImage;
}
});
html2canvas($("#dbServerCapacityDiv"), {
onrendered: function (canvas) {
// canvas is the final rendered <canvas> element
var myImage = canvas.toDataURL("image/png");
document.getElementById("hdnDBServerCapacity").value = myImage;
}
});
html2canvas($("#dbPerformanceDiv"), {
onrendered: function (canvas) {
// canvas is the final rendered <canvas> element
var myImage = canvas.toDataURL("image/png");
document.getElementById("hdnDBPerformance").value = myImage;
}
});
</script>
仅 第一个html2canvas 成功将base64 string
传递给相应的HiddenField
作为值,并且成功在CodeBehind
中访问。我的脚本有什么问题导致5 HiddenFields
返回 NULL ?
答案 0 :(得分:0)
您是否尝试将var myImage = canvas.toDataURL("image/png");
更改为功能中的其他名称?