jsPDF使用downloadify包括图像不工作

时间:2013-07-18 16:50:36

标签: javascript jspdf downloadify

以下是代码:

Downloadify.create('downloadify',{
    filename: 'Example.pdf',
    data: function(){ 
        var doc = new jsPDF();
        doc.setFontSize(40);
        doc.text(35, 25, "Octonyan loves jsPDF");
        doc.addImage(imgData, 'JPEG', 15, 40, 180, 180);
        return doc.output();
    },
    onComplete: function(){ alert('Your File Has Been Saved!'); },
    onCancel: function(){ alert('You have cancelled the saving of this file.'); },
    onError: function(){ alert('Error'); },
    swf: 'Downloadify/media/downloadify.swf',
    downloadImage: 'Downloadify/images/save.png',
    width: 250,
    height: 40,
    transparent: true,
    append: false
});

目标浏览器是IE8。我正在使用jsPDF.com的图片示例。如果我删除doc.addImage行,它就可以了。想法?感谢。

1 个答案:

答案 0 :(得分:3)

终于明白了。

为图片添加了dataType: 'base64',并更改了data: function()

这是我的工作代码:

 Downloadify.create('downloadify',{
    filename: 'Example.pdf',
    dataType: 'base64',
    data: function(){ 
        var doc = new jsPDF();
        doc.addImage(img64, 'JPEG', 0, 0, 215, 40);
        var output = doc.output();
        return btoa(output);
    },
    onComplete: function(){ alert('Your File Has Been Saved!'); },
    onCancel: function(){ alert('You have cancelled the saving of this file.'); },
    onError: function(){ alert('Error'); },
    swf: 'Downloadify/media/downloadify.swf',
    downloadImage: 'Downloadify/images/save.png',
    width: 250,
    height: 40,
    transparent: true,
    append: false
});