title: jquery print dialog box and webmethod
body: <p>I am having a problem with jquery, webmethod and printing.</p>
  
  <p>I my jquery code:</p>
  
  <pre><code> $("#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 &gt; 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 &lt; chaptsAndPages.length; ch++) {
                          var chPg = chaptsAndPages[ch].split(",");
                          $("#slChapters").append($("&lt;option&gt;&lt;/option&gt;")
                                          .attr("value", chPg[0])
                                          .text(chPg[1]));
                      }
                      PopulatePrintBoxEx();
                  }
              });
          });
  </code></pre>
  
  <p>My webmethod code</p>
  
  <pre><code>      [WebMethod(true)]
      public static string ProcessPrintRequest(string[] selected, string PDFName, List&lt;FreeEditField&gt; freeEditFields, List&lt;PostItNote&gt; PostIts)
      {
          string pdfName = PDFName + ".pdf";
          string pathToOrginalPdf;
          pathToOrginalPdf = HttpContext.Current.Server.MapPath(pdfName);
          if (selected == null || select.length == 0)
          {
              List&lt;string&gt; ss = new List&lt;string&gt;();
              QuickPDFAX0816.PDFLibrary qp = new PDFLibrary();
              qp.UnlockKey("xxxxxcodexxxx");
              qp.LoadFromFile(pathToOrginalPdf, "");
              int n = qp.PageCount();
              for (int t = 1; t &lt; n + 1; t++)
              {
                  ss.Add(t.ToString()); 
              }
              selected = ss.ToArray(); 
          }
          return Common.pdfUtilites.PrintSelectedPages(pathToOrginalPdf, Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".pdf", selected.ToList(), freeEditFields, PostIts);
      }
  </code></pre>
  
  <p>My utilities code</p>
  
  <pre><code> public static string PrintSelectedPages(string pathToPDF, string docName, List&lt;string&gt; selectedPages, List&lt;FreeEditField&gt; freeEdits, List&lt;PostItNote&gt; 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";
          }
      }
  </code></pre>
  
  <p>My link to my problems.</p>
  
  <p><a href="http://www.agflipbooks.com/books/book.aspx?bookid=301" rel="nofollow">http://www.agflipbooks.com/books/book.aspx?bookid=301</a></p>
  
  <p>Here is what is going on. 
  I go to click the print button on the right bottom icon that looks like a printer.
  I click print all dialog box comes up shows system process after about 2 to 3 minutes. 
  A second box comes up saying initializing then noting. I let it sit for about 15 minutes and nothing just frozen.</p>
  
  <p>Click on the link above and see for yourself.
  I go to the directory TmpForDownloas and the pdf is there I click on the pdf and all files are created.</p>
  
  <p>AddPostItNotes add any postits that was added to the pages on the books the same with AddEditFieldData if there are field with text it is added to the pdfs.</p>
  
  <p>any help will be appreciated?</p>
  
  <p>I all so have this as well.</p>
  
  <pre><code>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 = "&lt;object data='" + res + "#view=Fit&amp;toolbar=1' type='application/pdf' width='100%' height='100%'&gt;&lt;p&gt;It appears your Web browser is not configured to display PDF files. No worries, just &lt;a href='../TmpDownloads/testpdf.pdf'&gt;click here to download the PDF file.&lt;/a&gt;&lt;/p&gt;"
                  $("#pdfArea").html(objectTag);
              },
              buttons: {
                  "Done": function () { $(this).dialog("close"); }
              }
          });
  
      }
  </code></pre>