html2pdf.js icon indicating copy to clipboard operation
html2pdf.js copied to clipboard

Get resulting file as File or Bin data for additional using

Open AstRonin opened this issue 9 years ago • 6 comments

This function created PDF and save to a file

html2pdf.makePDF(canvas, pageSize, opt);

How can I to get PDF as File, for example, if I want to send it to email?

AstRonin avatar May 31 '17 12:05 AstRonin

Good question! Right now, you can't. It would be a useful feature, and I'll add it to the list of improvements to make when I revamp the API.

eKoopmans avatar Jun 03 '17 06:06 eKoopmans

Hi, I have just pushed a new branch, new-api, which is ready for testing! The readme has all the information on the new API. Please let me know if there are any problems with it - I want to make sure it's stable before merging into master!

For this specific request, you could use the .output method to get a datauristring:

html2pdf().from(element).output('datauristring').then(function (val) {
  // Your code to send an email with val.
});

eKoopmans avatar Feb 24 '18 15:02 eKoopmans

Hi, I have just pushed a new branch, new-api, which is ready for testing! The readme has all the information on the new API. Please let me know if there are any problems with it - I want to make sure it's stable before merging into master!

For this specific request, you could use the .output method to get a datauristring:

html2pdf().from(element).output('datauristring').then(function (val) {
  // Your code to send an email with val.
});

Hi, the Above method downloads file too, i only need uristring (val). How to set it download:false

khateeburrehman avatar Nov 06 '18 07:11 khateeburrehman

This function created PDF and save to a file

html2pdf.makePDF(canvas, pageSize, opt);

How can I to get PDF as File, for example, if I want to send it to email?

@AstRonin did you find any solution for this ?

nauman555 avatar Nov 21 '18 07:11 nauman555

This function created PDF and save to a file

html2pdf.makePDF(canvas, pageSize, opt);

How can I to get PDF as File, for example, if I want to send it to email?

@AstRonin did you find any solution for this ?

Autor wrote changes, please look. https://github.com/eKoopmans/html2pdf/issues/12#issuecomment-368236593 Sorry, but I cannot test it right now...

AstRonin avatar Nov 21 '18 18:11 AstRonin

Hi everyone, my response last February is still valid, and should give you the file as a "data URI" string. Note it's the same solution I've posted here and other places. @khateeburrehman that code should not prompt the user to download the file, there must be something else in your code causing that.

Closing this issue as resolved by the v0.9.0 new API.

Edit: The .output() command ties into the jsPDF .output() method which can produce all sorts of different values. If you want a Blob, for instance, it's a simple change:

html2pdf().from(element).output('blob').then(function (myBlob) {
    // Use myBlob however you wish...
});

eKoopmans avatar Jan 19 '19 08:01 eKoopmans