Javascript 将HTML表格导出为PDF,但不获取内容

Javascript 将HTML表格导出为PDF,但不获取内容,javascript,c#,jquery,asp.net,export-to-pdf,Javascript,C#,Jquery,Asp.net,Export To Pdf,您好,我正在将HTML表格导出为PDF,但我无法获得正确格式的内容。所有内容仅在一个单元格中出现。我的HTML代码是(使用jspdf.debug.js) PDF 小时研究小时/研究 公寓预订 数据处理 标签 小时研究小时/研究 解释 数据处理 标签 小时研究小时/研究 AMSCRIPTING 数据处理 标签 小时研究小时/研究 全服务脚本 数据处理 标签 小时研究小时/研究 仅样品 欧洲、中东和非洲 AMS东部 AMS西部 AMS 小时研究小时/研究 仅限样本总数仅限样本 java脚本代码是

您好,我正在将HTML表格导出为PDF,但我无法获得正确格式的内容。所有内容仅在一个单元格中出现。我的HTML代码是(使用jspdf.debug.js)

PDF
小时研究小时/研究
公寓预订
数据处理
标签
小时研究小时/研究
解释
数据处理
标签
小时研究小时/研究
AMSCRIPTING
数据处理
标签
小时研究小时/研究
全服务脚本
数据处理
标签
小时研究小时/研究
仅样品
欧洲、中东和非洲
AMS东部
AMS西部
AMS
小时研究小时/研究
仅限样本总数仅限样本
java脚本代码是

<script type="text/javascript">
        function demoFromHTML() {
            var pdf = new jsPDF('p', 'pt', 'letter');
            // source can be HTML-formatted string, or a reference
            // to an actual DOM element from which the text will be scraped.
            source = $('#customers')[0];

            alert(source);

            // we support special element handlers. Register them with jQuery-style 
            // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
            // There is no support for any other type of selectors 
            // (class, of compound) at this time.
            specialElementHandlers = {
                // element with id of "bypass" - jQuery style selector
                '#bypassme': function(element, renderer) {
                    // true = "handled elsewhere, bypass text extraction"
                    return true
                }
            };
            margins = {
                top: 80,
                bottom: 60,
                left: 40,
                width: 522
            };
            // all coords and widths are in jsPDF instance's declared units
            // 'inches' in this case
            pdf.fromHTML(
                    source, // HTML string or DOM elem ref.
                    margins.left, // x coord
                    margins.top, {// y coord
                        'width': margins.width, // max width of content on PDF
                        '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);
        }
    </script>

函数demoFromHTML(){
var pdf=新的jsPDF(“p”、“pt”、“字母”);
//源可以是HTML格式的字符串或引用
//到实际的DOM元素,文本将从该元素中删除。
来源=$(“#客户”)[0];
警报(来源);
//我们支持特殊的元素处理程序。用jQuery风格注册它们
//ID或节点名称的ID选择器。(“#iAmID”、“div”、“span”等)
//不支持任何其他类型的选择器
//(类,指化合物)此时。
SpecialElementHandler={
//id为“bypass”的元素-jQuery样式选择器
“#绕过我”:函数(元素、渲染器){
//true=“在别处处理,绕过文本提取”
返回真值
}
};
边距={
排名:80,
底数:60,
左:40,,
宽度:522
};
//所有坐标和宽度都以jsPDF实例声明的单位表示
//在本例中为“英寸”
pdf.fromHTML(
source,//HTML字符串或DOM元素引用。
margins.left,//x坐标
margins.top,{//y坐标
“宽度”:margins.width,//PDF上内容的最大宽度
“elementHandlers”:specialElementHandlers
},
功能(处置){
//dispose:将最后一行的X,Y添加到PDF中的对象
//这允许在html之后插入新行
保存('Test.pdf');
}
,利润率);
}
如下图所示


更改
source=$(“#客户”)[0]
as
source=$(“customers”).html()
将获得实际的html,目前您通过[0]获得jquery对象,但仍然得到相同的结果。。
<script type="text/javascript">
        function demoFromHTML() {
            var pdf = new jsPDF('p', 'pt', 'letter');
            // source can be HTML-formatted string, or a reference
            // to an actual DOM element from which the text will be scraped.
            source = $('#customers')[0];

            alert(source);

            // we support special element handlers. Register them with jQuery-style 
            // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
            // There is no support for any other type of selectors 
            // (class, of compound) at this time.
            specialElementHandlers = {
                // element with id of "bypass" - jQuery style selector
                '#bypassme': function(element, renderer) {
                    // true = "handled elsewhere, bypass text extraction"
                    return true
                }
            };
            margins = {
                top: 80,
                bottom: 60,
                left: 40,
                width: 522
            };
            // all coords and widths are in jsPDF instance's declared units
            // 'inches' in this case
            pdf.fromHTML(
                    source, // HTML string or DOM elem ref.
                    margins.left, // x coord
                    margins.top, {// y coord
                        'width': margins.width, // max width of content on PDF
                        '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);
        }
    </script>