我在使用 jquery、webmethod 和打印时遇到问题。
我我的jQuery代码:
$("#PrintBtn").click(function () {
$("#printDialog").dialog({
modal: true, autoResize: true, height: $(window).height() - 10, width: '90%',
buttons: {
"CANCEL": function () {
$(this).dialog("close");
},
"PRINT ALL": function () {
$("#ProcessMsg").dialog({ modal: true, width: 320, height: 200 });
FillFe(function () {
PageMethods.ProcessPrintRequest(null, $("#hidPDF").val(), FreeEditFields, CreatePostItObjectArray(), function (link) {
printResult(link);
$("#ProcessMsg").dialog("close");
$(this).dialog("close");
});
});
},
"PRINT SELECTED PAGES": function () {
if (SelectedPages.length > 0) {
$("#ProcessMsg").dialog({ modal: true, width: 320, height: 200 });
FillFe(function () {
PageMethods.ProcessPrintRequest(SelectedPages, $("#hidPDF").val(), FreeEditFields, CreatePostItObjectArray(), function (link) {
printResult(link);
$("#ProcessMsg").dialog("close");
$(this).dialog("close");
});
});
}
},
"UNCHECK": function () {
$(".checkPrint").prop("checked", false);
SelectedPages = new Array();
}
}
, open: function () {
SelectedPages = new Array();
$("#BookMenu").fadeOut(500);
BookMenuShow = false;
// $(".checkPrint").prop("checked", false);
justShow = false;
currentPrTn = PageIndex;
//Popluate the chapter box
$("#slChapters").empty();
for (var ch = 0; ch < chaptsAndPages.length; ch++) {
var chPg = chaptsAndPages[ch].split(",");
$("#slChapters").append($("<option></option>")
.attr("value", chPg[0])
.text(chPg[1]));
}
PopulatePrintBoxEx();
}
});
});
我的网络方法代码
[WebMethod(true)]
public static string ProcessPrintRequest(string[] selected, string PDFName, List<FreeEditField> freeEditFields, List<PostItNote> PostIts)
{
string pdfName = PDFName + ".pdf";
string pathToOrginalPdf;
pathToOrginalPdf = HttpContext.Current.Server.MapPath(pdfName);
if (selected == null || select.length == 0)
{
List<string> ss = new List<string>();
QuickPDFAX0816.PDFLibrary qp = new PDFLibrary();
qp.UnlockKey("xxxxxcodexxxx");
qp.LoadFromFile(pathToOrginalPdf, "");
int n = qp.PageCount();
for (int t = 1; t < n + 1; t++)
{
ss.Add(t.ToString());
}
selected = ss.ToArray();
}
return Common.pdfUtilites.PrintSelectedPages(pathToOrginalPdf, Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".pdf", selected.ToList(), freeEditFields, PostIts);
}
我的实用程序代码
public static string PrintSelectedPages(string pathToPDF, string docName, List<string> selectedPages, List<FreeEditField> freeEdits, List<PostItNote> PostIts)
{
QuickPDFAX0816.PDFLibrary qp = new PDFLibrary();
qp.UnlockKey("xxxcodexxxx");
if (qp.LoadFromFile(pathToPDF, "") == 1)
{
string pages = "";
foreach (string s in selectedPages)
{
pages = pages + s + ",";
}
qp.ExtractPageRanges(pages);
StringBuilder sb = new StringBuilder();
sb.Append("var pp=this.getPrintParams();");
sb.Append("pp.interactive = pp.constants.interactionLevel.automatic;");
sb.Append("this.print(pp);");
qp.SetOpenActionJavaScript("var pp=this.getPrintParams();this.print(pp);");
qp.SaveToFile(HttpContext.Current.Server.MapPath("../TmpForDownloads/print" + docName));
qp = null;
string doc = AddEditFieldData(freeEdits, "../TmpForDownloads/print" + docName, selectedPages);
doc = AddPostItNotes(PostIts, "../TmpForDownloads/print" + docName, selectedPages);
return doc;
}
else
{
return "ERROR";
}
}
我的问题的链接。
http://www.agflipbooks.com/books/book.aspx?bookid=301
这是正在发生的事情。我去单击看起来像打印机的右下角图标上的打印按钮。大约 2 到 3 分钟后,我单击打印所有对话框显示系统进程。出现第二个框,说初始化然后注意。我让它静置了大约 15 分钟,没有任何东西被冻结。
点击上面的链接,自己看看。我转到目录 TmpForDownloas 并且 pdf 在那里我单击 pdf 并创建所有文件。
AddPostItNotes 添加任何添加到书籍页面的 postits,如果有带有文本的字段添加到 pdf,则与 AddEditFieldData 相同。
任何帮助将不胜感激?
我也有这个。
function printResult(res) {
var userAgent = navigator.userAgent.toLowerCase();
$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
$.browser.safari = /safari/.test(navigator.userAgent.toLowerCase());
$.browser.mozilla = /mozilla/.test(navigator.userAgent.toLowerCase());
var time = 3000;
var OSName = "Unknown OS";
if (navigator.appVersion.indexOf("Win") != -1) OSName = "Windows";
if (navigator.appVersion.indexOf("Mac") != -1) OSName = "MacOS";
if (navigator.appVersion.indexOf("X11") != -1) OSName = "UNIX";
if (navigator.appVersion.indexOf("Linux") != -1) OSName = "Linux";
$("#pdfPrintDialog").dialog({ modal: true, width: 640, height: 500,
open: function () {
var objectTag = "<object data='" + res + "#view=Fit&toolbar=1' type='application/pdf' width='100%' height='100%'><p>It appears your Web browser is not configured to display PDF files. No worries, just <a href='../TmpDownloads/testpdf.pdf'>click here to download the PDF file.</a></p>"
$("#pdfArea").html(objectTag);
},
buttons: {
"Done": function () { $(this).dialog("close"); }
}
});
}