Skip to content

Instantly share code, notes, and snippets.

@sjurgis
Created June 20, 2024 00:53
Show Gist options
  • Save sjurgis/aaa4f0fefeb431cd8189a72a3430bd0a to your computer and use it in GitHub Desktop.
Save sjurgis/aaa4f0fefeb431cd8189a72a3430bd0a to your computer and use it in GitHub Desktop.
Print multiple record detail pages as PDF (Salesforce Apex Visualforce)
public inherited sharing class PDFPrinter {
public static String getContent() {
String[] ids = ApexPages.currentPage().getParameters().get('ids').split(',');
// TODO do record access checks!
String content = '';
for (String i : ids) {
PageReference p = new PageReference('/' + i + '/p');
content += p.getContent().toString();
}
content = content
.remove('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">')
.remove('<html class="" style="display:none !important;" lang="en-US"><head><script src="/static/111213/js/perf/stub.js">')
.remove('</html>');
return content;
}
}
<apex:page
renderAs="pdf"
controller="PDFPrinter"
applyHtmlTag="false"
applyBodyTag="false"
readOnly="true"
showChat="false"
showHeader="false"
sideBar="false"
standardStylesheets="false"
lightningStylesheets="false">
<apex:outputText value="{!content}" escape="false"/>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment