jsPDF不渲染html对象 [英] jsPDF doesn´t render html objects

查看:238
本文介绍了jsPDF不渲染html对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到以下问题:

当使用jsPDF时,应该可以从HTML代码生成PDF。

我这样做的方式是使用图像,我似乎无法以正确的方式将html表格转换为pdf(这清除了所有的表格布局)。在使用html2canvas时,添加HTML插件仍然不会生成包含内容的pdf。我没有收到任何错误,所以我不知道问题可能是什么。

另外通过下面的链接给出的例子,代码写的有点不同,但是当我使用时这段代码作为参数传递的anomymous函数甚至没有执行,因此我使用以下构造。

`pdf.addHTML(document.title,(function(){})( ));`

即使这是正确的,内容也不会显示在PDF内部。



http:// mrrio.github.io/jsPDF/#



我的代码有以下结构我尝试过:



 $( function (){
$(' #createPDF')。点击( function (){

var pdf = new jsPDF(' p'' pt'' a4');
var options = {
pagesplit: true
};
pdf.addHTML($(' body'), 0 0 ,options,( function (){
pdf.save( test.pdf);
})());





var pdf = new jsPDF(' p' ' pt'' a4'< /跨度>);
pdf.addHTML(' Hallo'函数(){
var string = pdf.output(' datauristring');
$(' .profrop-窗格')。attr(' src',string);
} );
pdf.save(' Test.pdf');




var doc = new jsPDF();
window .alert( document .title);
doc.addHTML( document .title,( function (){})()) ;
doc.text( 20 20 document .getElementById(' learningCurve'));
doc.text( 20 20 document .getElementById(' 123'));
doc.setProperties({pagesplit: true });
doc.addPage();
doc.text(' 你喜欢吗?');
doc.save(' Maandrapportage.pdf');
});
});

解决方案

function (){

' #createPDF')。click( function (){

var pdf = new jsPDF(' p'' pt'' a4' );
var options = {
pagesplit: true
} ;
pdf.addHTML(


' body'), 0 0 ,options,( function (){
pdf.save( test.pdf);
})());





var pdf = new jsPDF(' p' ' pt'' a4'< /跨度>);
pdf.addHTML(' Hallo'函数(){
var string = pdf.output(' datauristring');

I´m here with the following problem:
When using jsPDF it should be possible to generate a PDF from HTML code.
The way im looking at doing this is with the use of images, I can't seem to get html tables into the pdf the right way (this clears all of the table layouts). While using html2canvas, addHTML plugins the pdf still won't be generated with content. I'm not getting any errors, so I don't know what the problem could be.
Also with the examples given at the link below, the code is written a bit differently, but when I use this code the anomymous function which is passed on as a parameter isn't even executed, therefor i use to following construct.
`pdf.addHTML(document.title, (function() {})());`
Even when this is right, the content won't be shown inside of the PDF.

http://mrrio.github.io/jsPDF/#

My code has the following structure(s) which I has tried:

$(function() {
    $('#createPDF').click(function () {

        var pdf = new jsPDF('p', 'pt', 'a4');
        var options = {
                 pagesplit: true
            };
        pdf.addHTML($('body'), 0, 0, options, (function() {
            pdf.save("test.pdf");
        })());





        var pdf = new jsPDF('p','pt','a4');
        pdf.addHTML('Hallo' ,function() {
            var string = pdf.output('datauristring');
            $('.preview-pane').attr('src', string);
        });
        pdf.save('Test.pdf');




        var doc = new jsPDF();
        window.alert(document.title);
        doc.addHTML(document.title, (function() {})());
        doc.text(20, 20, document.getElementById('learningCurve'));
        doc.text(20, 20, document.getElementById('123'));
        doc.setProperties({ pagesplit: true} );
        doc.addPage();
        doc.text('Do you like that?');
        doc.save('Maandrapportage.pdf');
    });
});

解决方案

(function() {


('#createPDF').click(function () { var pdf = new jsPDF('p', 'pt', 'a4'); var options = { pagesplit: true }; pdf.addHTML(


('body'), 0, 0, options, (function() { pdf.save("test.pdf"); })()); var pdf = new jsPDF('p','pt','a4'); pdf.addHTML('Hallo' ,function() { var string = pdf.output('datauristring');


这篇关于jsPDF不渲染html对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆