Created
June 20, 2024 00:53
-
-
Save sjurgis/aaa4f0fefeb431cd8189a72a3430bd0a to your computer and use it in GitHub Desktop.
Print multiple record detail pages as PDF (Salesforce Apex Visualforce)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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