1

Here's the code:

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
});

Target browser is IE8. I'm using the image example from jsPDF.com. If I remove the doc.addImage line it works just fine. Ideas? Thanks.

user899641
  • 341
  • 1
  • 4
  • 20

1 Answers1

3

Finally got it.

Added dataType: 'base64' for image, and changed the data: function().

Here is my working code:

 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
});
falsarella
  • 12,217
  • 9
  • 69
  • 115
user899641
  • 341
  • 1
  • 4
  • 20
  • Thank you so much falsarella - I would never have gotten this working without this post! The 'normal' version (i.e. the first snippet minus the addImage command) wasn't working, but this base64 + btoa() version does. Can anyone explain WHY this fixed it? – Brondahl Dec 15 '14 at 20:25
  • EDIT: It occurs to me that I am using the "addHTML" + html2canvas approach, so I am infact doing it all as an image .... so it is in fact the same scenario you had. I'd still be interested if anyone had a theory about WHY this works though :) – Brondahl Dec 15 '14 at 20:28