jquery打印对话框和webmethod

时间:2012-08-14 04:53:31

标签: jquery printing webmethod

我遇到了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添加添加到书籍页面上的所有帖子与AddEditFieldData相同,如果有文本字段添加到pdfs中。

任何帮助将不胜感激?

我也都这样。

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"); }
            }
        });

    }

1 个答案:

答案 0 :(得分:0)

问题解决了这是一个缓存问题,图像到pdf。我减少了