Overall flow:
ContentVersion File
│
▼
AutoGenDocPreviewController
│
▼
Base64 PDF String
│
▼
Visualforce Page
│
▼
JavaScript atob()
│
▼
Binary PDF
│
▼
Blob
│
▼
Temporary URL
│
▼
iframe
│
▼
PDF displayed in browser
Why This Approach Is Useful for Guest Users
Instead of exposing the file directly through:
/servlet/servlet.FileDownload?file=...
the Apex controller retrieves the file and sends it as Base64. The browser reconstructs the PDF locally.
This is often used when:
- Guest users cannot access
ContentVersiondirectly. - Secure Guest User Access is enabled.
- Files are owned by an integration user.
- You need custom security checks before showing the document.