Back to Blog

How to Generate a PDF from an LWC in Salesforce Without Visualforce

How to Generate a PDF from an LWC in Salesforce Without Visualforce

Every LWC-to-PDF path eventually funnels back through a Visualforce page and inherits its limits. Here is why, and a native way to generate the document without the round trip.

ZeroExport Team

You built a Lightning Web Component that shows exactly the document you want: a styled invoice, a service report, a summary. Now you need it as a PDF to attach to an email or offer as a download. And you discover there is no clean, native LWC way to do it. Every path you try leads back to Visualforce.

Why LWC can't just "export to PDF"

Lightning Web Components render in the browser, but Salesforce has no server-side LWC-to-PDF renderer. So the moment you need a real PDF file (saved to a record, attached to an email, generated in bulk), you have to hand the work to something that can produce one server-side. In practice that means one of these, each with a catch:

  • Route through a Visualforce page with renderAs="pdf". This is the most common answer, and it means your LWC's modern styling now has to survive Visualforce's older PDF engine (CSS 2.1 only). You often end up rebuilding a simplified layout just for the PDF.
  • Blob.toPdf() in Apex. It exists, but it is limited and easy to get wrong: developers report CSS parsing errors and blank or corrupt PDFs, and it still effectively expects Visualforce-style markup.
  • A third-party PDF API. Now you own an integration: authentication, callouts, error handling, and a dependency that can fail or change pricing. Callouts from asynchronous Apex also need their own auth handling.
  • A client-side JS PDF library. These are constrained inside Locker/Lightning Locker, produce lower-fidelity output, and can't easily save server-side.

So "generate a PDF from my LWC" quietly becomes "maintain a Visualforce page and its PDF-specific quirks," or "own an external service." Neither is what you set out to build.

What you actually want

Step back from the mechanics. The real goal is: turn Salesforce data into a well-formatted document, reliably, without babysitting a render engine or an integration. The LWC was just the UI you happened to prototype it in.

That reframing matters, because the hard part was never the button in your component: it is producing a consistent document server-side, at scale, that you can save and send.

A native alternative: generate the document, skip the round trip

ZeroExport generates documents natively inside Salesforce as a managed package. There is no Visualforce pass-through page to maintain and no external PDF service to authenticate:

  • No middleware. Nothing external to configure, authenticate, or keep patched. The document is produced where your records already live.
  • You design in a native builder, not by hand-tuning markup to survive a legacy PDF engine, so there is no "looks right in the LWC, breaks in the PDF" gap.
  • Deterministic output. Once the template is saved, the same record produces the same document every time.
  • It fits your existing UI. You can still trigger generation from a button in your LWC or Flow; ZeroExport handles turning the record into the document, so your component doesn't have to become a rendering engine.

The shortcut isn't a better Blob.toPdf() incantation. It is not making your component responsible for PDF rendering at all.

A fair caveat: very large documents at high volume run into Salesforce platform limits regardless of tool, and fine-grained page-break control is worth evaluating directly for any solution. This article is about the everyday "I just need a clean PDF from my LWC data" case, which a native generator handles without the Visualforce detour.

FAQ

Can an LWC generate a PDF directly in Salesforce?

Not on its own: there is no native server-side LWC-to-PDF renderer. To produce a real PDF file you route through Visualforce's renderAs="pdf", use Apex Blob.toPdf(), call an external PDF service, or use a constrained client-side JS library.

Why does my LWC-to-PDF approach still use a Visualforce page?

Because Visualforce is the built-in server-side HTML-to-PDF path in Salesforce. Most LWC-to-PDF solutions funnel through it, which is why they inherit Visualforce's PDF engine limits like CSS 2.1-only styling and font restrictions.

How do I generate a PDF from Salesforce data without Visualforce or an external API?

Use a native document generation tool such as ZeroExport. It runs as a managed package inside Salesforce, generates documents deterministically, and doesn't require a Visualforce pass-through page or a third-party PDF service.

Can I still trigger generation from my LWC or a button?

Yes. You keep your UI (a button in the LWC, a Flow, or an action) and let the document tool produce the document from the record, so your component isn't responsible for rendering the PDF.

Related Reading

Ready to try ZeroExport?

Start generating documents directly in your Salesforce org. No integrations, no setup overhead, no complexity.