Generating PDFs in Apex Salesforce has always been more complicated than it should be. For years, developers had to rely on Visualforce with renderAs="pdf", adding extra pages, more maintenance, and unnecessary technical debt. With Spring ’26, Salesforce finally introduces a native way to generate PDFs directly from Apex using Blob.toPdf() — no Visualforce required.
🔎 Generate PDFs in Apex Salesforce: What Changed?
Before Spring ’26
If you wanted a PDF, you had to:
- Create a Visualforce page
- Use
renderAs="pdf" - Call it from Apex
- Maintain both Apex and Visualforce
That’s a lot of moving parts for something that should be simple.
Now
You can generate a PDF entirely inside Apex using HTML as the source.
⚙️ How to Generate PDFs in Apex Salesforce
1️⃣ Create Your HTML
String htmlContent = '<h1>Account Summary</h1><p>Generated in Apex 🚀</p>';You can build this dynamically from your data (Accounts, Opportunities, invoices, anything).
2️⃣ Convert HTML → PDF (One Line)
Blob pdfBlob = Blob.toPdf(htmlContent);That’s it.
Salesforce handles the rendering for you.
3️⃣ Save It as a File and Link It to a Record
ContentVersion cv = new ContentVersion();
cv.Title = 'Account Summary';
cv.PathOnClient = 'AccountSummary.pdf';
cv.VersionData = pdfBlob;
cv.FirstPublishLocationId = accountId;
insert cv;✅ The Result
- PDF generated instantly
- Stored as a Salesforce File
- Automatically linked to the record
- Ready for preview or download
No extra infrastructure. No Visualforce dependency.
💡 Why This Matters
This is a big deal for modern Salesforce development.
Blob.toPdf() means:
✔ Cleaner architecture (Apex-only)
✔ Less technical debt
✔ Faster implementations
✔ Easier testing and deployment
✔ Better fit for LWC + API-first designs
It’s perfect for:
- Invoices
- Quotes
- Account summaries
- Contracts
- Reports
- Any document generated from Salesforce data
🧠 Real-World Impact
In projects where we generate documents (especially managed packages like SharinPix), removing Visualforce reduces:
- Metadata complexity
- Security review surface
- Maintenance overhead
And that’s a huge win for ISVs and enterprise teams.
🚀 Final Thoughts
Spring ’26 didn’t just add a new method — it removed an entire legacy pattern.
Generating PDFs in Salesforce is now:
Native. Simple. Apex-only.
And honestly… it’s about time.
If your goal is to generate PDFs in Apex Salesforce with less complexity, better performance, and cleaner deployments, Blob.toPdf() should now be your default approach.