2

I have a visualforce page that renders as a pdf. Is there any way in apex to get that page data as a blob? I've thought about doing an Http GET request, but I feel like there should be a more direct way to get the page's blob data in my apex class.

1 Answer 1

3

You can use any of the PageReference methods. The most straightforward would be:

Blob pdfData = Page.myPageName.getContent();

Note that this technically still counts as a callout (meaning, you cannot use DML before calling it), but is far shorter than any other solution.

If this should be dynamic:

Blob pdfData = new PageReference('/apex/myPageName').getContent();
1
  • Wonderful, thanks!
    – Tyler Zika
    Mar 28, 2019 at 7:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .