繁体   English   中英

jsPDF正在下载EMPTY PDF

[英]jsPDF is downloading EMPTY PDF

我有一个内容div,其ID为“ divDownload”。 在内容div中,我有一个面板,其中包含一些中继器,一些表和标签,等等。 当用户单击下载按钮时,我想将该div下载为pdf。 为此,我正在使用jsPDF库。 但是它正在下载空的PDF。

HTML页面:

<asp:Button ID="btnDownload" runat="server" Text="Download" />

<div id="divDownload">
    <asp:Panel ID="pnldownload" runat="server">
        // repeaters 
        //tables 
        //labels
    </Panel>
</div>

<div id="noprint"></div>

JavaScript函数:

  $(document).ready(function () {
      $("#<%= btnDownload.ClientID %>").click(function (e) {

          var pdf = new jsPDF('p', 'pt', 'a4');
          var source = $("#divDownload");

          alert(source);
          specialElementHandlers = {
              // element with id of "bypass" - jQuery style selector
              '#noprint': function (element, renderer) {
                  // true = "handled elsewhere, bypass text extraction"
                  return false;
              }
          };
          pdf.fromHTML(
          source,
          15,
          15, {
              'width': 150,
              'elementHandlers': specialElementHandlers
          });
          pdf.save('test.pdf');


      });
  });

有人可以帮我解决这个问题吗? 在StackOverFlow中进行了大量搜索并尝试了不同的方法,但是没有运气。

我用过:

var source = $("#divDownload").html;

我也对#noprint使用true

希望对您有帮助!

我再次尝试,以下是完整的代码:

      var pdf = new jsPDF('p', 'pt', 'a4');
      var source = $("#divDownload").html();

      specialElementHandlers = {
          // element with id of "bypass" - jQuery style selector
          '#noprint': function (element, renderer) {
              // true = "handled elsewhere, bypass text extraction"
              return true;
          }
      };

      pdf.fromHTML(
        source, 20, 20, { 'width': 150,
            'elementHandlers': specialElementHandlers
       },

      function (dispose) {
            // dispose: object with X, Y of the last line add to the PDF 
            //          this allow the insertion of new lines after html
            pdf.save('Test.pdf');
      }, margins);

请让我知道它是否有效。 喜欢解决这个问题! 谢谢!

@阿比

jsPdf可用于html表。

因此,您必须提供html表的ID,而不要提供div的ID。 尝试使用html表。

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM