function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
liron169liron169 

Identify empty PDF

Hi.
I'm using function getContent(), to get blob of PDF page.

There are cases where the PDF is empty (blank page), and it's fine. The question how can I detect it.

-I cannot inspect the blob ,as the characters have no meaning....
-In the controller of the PDFpage I have such indication, but I cannot access it in the caller process.

Any suggestions?

PageReference page = new PageReference('/apex/PDFpage...');
blob bodyAttach=page.getContent();
Best Answer chosen by liron169
Ankit AroraAnkit Arora
You've to keep the check in your code from where PDF is generated (before page.getContent). Else you can check the size of PDF, as you can't read the PDF and content inside it.

All Answers

Ankit AroraAnkit Arora
There is no way to read PDF, so it seems difficult to implement. Though there is a very long workaround which if you make a Java util and host it somewhere say heroku. Then via web service you can read the PDF and do the needful.
liron169liron169
By the code in my controller I can know that the pdf will be empty (e.g. if no data was retrieved for some reason).

The issue is how the caller (code which open this page with getContent), can get response from the page, which inform it that pdf will be empty.
Ankit AroraAnkit Arora
You've to keep the check in your code from where PDF is generated (before page.getContent). Else you can check the size of PDF, as you can't read the PDF and content inside it.
This was selected as the best answer
liron169liron169
Thanks, I think you're right and the most appropriate solution will be to do the logic which deteremine if pdf will be empty before. In the process which call the pdf