Reputation: 709
I need to create downloadable pdfs of a page which is rendered using Vue. The html to template API we're using is DocRaptor.
Passing in a url to the page, which is then rendered to a PDF. Problems.
Passing in the raw html in the DocRaptor POST request, with styling. Problems
The two options above seem like the way to go. Would love for option 1 to work, but I don't see how - which leaves me with option 2, however no amount of googling has given me answers beyond server side rendering. Can I even do that for single pages? I assume the whole app gets rendered.
Upvotes: 0
Views: 3094
Reputation: 4608
Option 1 could work, assuming you have some sort of authentication mechanism in place (for example a short lived token). DocRaptor does indeed execute your javascript, so it should work.
Upvotes: 1
Reputation: 18504
You can render to an invisible element on client (or may be even visible and make user think that this is a preview) and then use old good innerHTML
:
let html = document.querySelector('#render-placeholder').innerHTML;
and then post it to server to forward to pdf renderer (to keep service access tokens secret).
Upvotes: 0