#SalesforceSpring26 [Tip 33] - Use Visualforce PDF Rendering Service with Apex Blob.toPdf() (Vide...

With Spring ‘26 release, we can now generate PDFs directly in Apex using Blob.toPdf() method that uses the same PDF rendering service as Visualforce.

This means PDF files generated through Apex benefit from the Visualforce PDF rendering engine, including improved font support and better handling of multibyte characters.

The method itself does not change. Blob.toPdf() still accepts a string as input and returns a Blob as output. The only difference is the underlying rendering engine.

Product Area: Apex

Salesforce will enforce this update in Summer ’26, but you can enable it yourself by navigating to Setup → Release Updates.

Important note: The default font changes from serif to sans-serif. If your PDF content doesn’t explicitly define font styling, you may notice differences in line lengths, line breaks, and page breaks compared to PDFs generated using the old rendering service.

Here is short video on how to try this out.

spr26-blob-topdf-uses-visualforce-pdf-rendering-engine.mp4

And here is the anonymous Apex code used in the video that you can copy and paste to try out yourself. Replace the Account ID value with a valid Account ID from your Salesforce org.

// Replace with a real Account Id from your org
Id accountId = '<account_id>';

// 1. Get the Account
Account acc = [
    SELECT Id, Name, Phone, Website, Industry,
           BillingStreet, BillingCity, BillingState,
           BillingPostalCode, BillingCountry
    FROM Account
    WHERE Id = :accountId
    LIMIT 1
];

// 2. Build a clean billing address string
List<String> addrParts = new List<String>();
if (String.isNotBlank(acc.BillingStreet))      addrParts.add(acc.BillingStreet);
if (String.isNotBlank(acc.BillingCity))       addrParts.add(acc.BillingCity);
if (String.isNotBlank(acc.BillingState))      addrParts.add(acc.BillingState);
if (String.isNotBlank(acc.BillingPostalCode)) addrParts.add(acc.BillingPostalCode);
if (String.isNotBlank(acc.BillingCountry))    addrParts.add(acc.BillingCountry);
String billingAddress = String.join(addrParts, ', ');

// 3. Build HTML for the PDF (inline styles only)
String html = ''
    + '<html><body>'
    + '<div style="font-family: Arial; font-size: 11pt;">'
    + '  <h1 style="color:#1b5297; margin-bottom:4px;">Account Summary</h1>'

    + '  <div style="margin-bottom:8px;">'
    + '    <span style="font-weight:bold; display:inline-block; width:120px;">Name:</span> '
           + (acc.Name == null ? '' : acc.Name.escapeHtml4())
    + '  </div>'

    + '  <div style="margin-bottom:8px;">'
    + '    <span style="font-weight:bold; display:inline-block; width:120px;">Phone:</span> '
           + (acc.Phone == null ? '' : acc.Phone.escapeHtml4())
    + '  </div>'

    + '  <div style="margin-bottom:8px;">'
    + '    <span style="font-weight:bold; display:inline-block; width:120px;">Website:</span> '
           + (acc.Website == null ? '' : acc.Website.escapeHtml4())
    + '  </div>'

    + '  <div style="margin-bottom:8px;">'
    + '    <span style="font-weight:bold; display:inline-block; width:120px;">Industry:</span> '
           + (acc.Industry == null ? '' : acc.Industry.escapeHtml4())
    + '  </div>'

    + '  <div style="margin-bottom:8px;">'
    + '    <span style="font-weight:bold; display:inline-block; width:120px;">Billing Address:</span> '
           + (billingAddress == null ? '' : billingAddress.escapeHtml4())
    + '  </div>'

    + '  <p style="margin-top:12px;">'
    + '    Generated via Blob.toPdf() using the Visualforce PDF Rendering Service (Spring \'26).'
    + '  </p>'
    + '</div>'
    + '</body></html>';

// 4. Generate PDF using Visualforce PDF Rendering Service
Blob pdfBlob = Blob.toPdf(html);

// 5. Save as a File on the Account
ContentVersion cv = new ContentVersion(
    Title                  = 'Account Summary - ' + acc.Name,
    PathOnClient           = 'AccountSummary-' + acc.Name + '.pdf',
    VersionData            = pdfBlob,
    FirstPublishLocationId = acc.Id
);
insert cv;

Once the code executes, the PDF will be saved to the Account record and will appear in the Files related list.

References & Useful URLs

  • For Related Spring ’26 Release Note Article – Click Here