I wanted to convert my markdown content to PDF and have it downloaded via the browser. This thread provided me with my start point so thanks everybody
After a bit of investigation I found the npm package markdown-pdf to be an excellent choice for me and one that got me to a satisfactory working solution.
You should provide more details about your requirements, if itās server side or client side.
The package that iāve mentioned above is capable of generating pdf from data form submission, but the limitation of it is generate pdf on a table dynamically, actually, I have an open issue regarding this, issue#4.
Client-side should be good enough since all the client has requested is to be able to export a displayed list of items by the click of a button and send it through an email service.
The package you linked looks like it would do just the job and Iāll give it a try at the office tomorrow =) Thanks!
I am sure you have figured this out by now. Just in case for some one else who is thinking the same. The code assumes you have iron:router installed. If you donāt you can use the method @ryanswapp has mentioned.
Hey, I tried a few different packages from atmosphere but in the end none quite worked out for me. So I did it the old way: Downloaded PDFKit and a certain āblob-streamā package (youāll find a link to both and instructions on pdfkit.org). Put both inside public/ and then <script> tags on the <head>
Thatās it. Now you can create and compose client side pdfās and output them to a blobURL.
The PDFKit documentation is excellent so take a look and youāll be able to use it easily.
Note: the unit of measure on most of these pdf packages is pt, so keep that in mind. http://www.unitconversion.org/typography/postscript-points-to-pixels-x-conversion.html Hereās a site to convert units.
Hi, Iām not sure if youāve solved your problem, but perhaps you can try this: You can turn things from a <canvas> into an image with HTMLCanvasElement.toDataURL() or HTMLCanvasElement.toBlob(). The latter doesnāt work on Chrome yet, but both are native APIās
It might be a bit of work, but if you can compose whatever you have to create an image of, inside a canvas, then you can use that method on it. Rember that canvas accepts text. You can then access the output image by simply opening the dataURL or blobURL that is generated, or using it as the src attribute on an <img> .
Hereās info on the API https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL
I run my own server at first I use their free version and then I purchase their license. I create templates using handlebars which makes it very easy since itās so somewhere to meteor it even has the ability to run Scripts.
Quick pseudo gist of what iāve done in the past.
On the server
Use Meteor SSR to generate a template for the pdf on the server SSR.compileTemplate('myTemplate')
then . SSR.render('myTemplate).
Will give you an html_string of the pdf template.
Then I have a meteor.wrapAsync method
that takes that html_string passes it to webshot to take a screenshot of the rendered PDF (via phatomjs), access the file with FS and then return the file as base64 string in a callback.
On the client
I then return that base64 string to client, and in my case convert the base64 string into a Blob, create a URL, and open a preview window.
Meteor.call('openPdf, function(err,res) {
//var view = convert res from base64 to blob ....
var blob = new Blob( [view], { type: "application/pdf" });
var url = URL.createObjectURL(blob);
window.open(url);
}