I need some advise with the following use case:

We have a custom object "Invoice" and want to generate the Invoice PDF using a JavaScript Library that is able to convert an HTML Code of the Invoice Document into a PDF.

In another custom object called "Document Template" we store the full HTML code similar to this one:


The HTML Code in the Document Template Object is prepared for Visualforce and contains the logic to populate the fields from the Invoice record and it's related line items.

So far we are able to pass this in a way to have a proper looking Visualforce Page as in above sample.

Now our idea was to use the VF generated HTML Code and pass it to any PDF-JavaScript Library to get it rendered as a PDF and save it to the ContentDocument Object.

So far we tried with JSPDF but actually we don't understand if thats really possible how we imagine and we have not been able to find any similar solution. We made it work to pass single text strings or something to get it rendered as a PDF but we are not able to pass the whole HTML Code.

So I am asking for some advise to understand if someone else had such a use case already, knows some documentation on it or has some better idea on how to get this done WITHOUT any external API services that renders the PDF based on the HTML Code?

The issue with renderas=PDF and blob.toPDF is that it is not supporting custom fonts.

Thanks for your help.

  • 1
    Any reason why you don't simply pass the HTML to Apex and use Blob.toPdf? I mean, yes, you can use a JSPDF-style library to do it, but it might be easier to just render directly in Apex. Asking about a specific JS library might be out of scope here anyways, but if you want it to have a chance, you should probably edit your question that has code to demonstrate your problem.
    – sfdcfox
    Apr 8, 2022 at 23:33
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Apr 9, 2022 at 2:59
  • The reason for not using blob.toPDF is the limitation of not being able to use custom font and apply styling in a way we want. We could also go with render as PDF but that also does not support custom fonts. I understand that most people here want to get code reviews and similar but my problem is that my code is working till Visualforce Page generation but i just don't know what is the best way to convert this to a PDF with above reqs. I will make this more clear in the post. Thanks Apr 9, 2022 at 6:14

1 Answer 1


I've been in your situation and there are no alternatives to VF or Blob.toPdf when generating a PDF file from HTML code. The jsPDF library has some compatibility issues with SF's LWC framework when trying to convert HTML to PDF.

We ended up using the app SDocs. The free version lets you set up 1 document template with HTML code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .