I'm trying to get a PDF to download via a cloud page, so when the user accesses the page it will show them a popup to download a PDF from a URL.

I have the code that achieves this but my PDF that is downloaded just includes blank white pages rather than the content.

Does anyone know what the issue could be?

The function I'm using is

var DownloadPDF = function(url, filename)
    HTTPHeader.SetValue("Content-Disposition", 'attachment; filename="'+filename+'"');
  • It might be easier to host the PDF inside of Content Builder and then use the corresponding URL as the 'link' the user clicks on. This will also let them view the PDF via the browser as well as provide the option to download it. – Gortonington Jun 29 '18 at 13:09

I typically use JavaScript to download a PDF file from a CloudPage. I would avoid implementing as a pop-up, as most browsers block pop-up windows by default.

Here's an example:

var @pdfDownloadUrl
set @pdfDownloadUrl = 'https://url-to-pdf-file.com/file.pdf'
  window.location.href = '%%=v(@pdfDownloadUrl)=%%';

When the page loads, the PDF file will download to the default 'download directory' used by the web browser.

| improve this answer | |

You need to set the HttpHeader as application/octet-stream

| improve this answer | |
  • Unfortunately not, I had already tried with octet-stream and it performed the same as using the PDF mime type – Amtera Jun 28 '18 at 19:32

You can have your PDF as a page and get its content without actually loading the page in Apex.

public Blob downloadPDF(){

    ApexPages.PageReference refPage = Page.MyPDFPage;
    refPage.getParameters().put( 'id', myrecordIdVariable );
    refPage.setRedirect( false );
    Blob pdfValue = refPage.getContentAsPDF();

    return pdfValue;

You can then pull in this to build your file.

| improve this answer | |
  • This is for Marketing Cloud, not Apex. – Eliot Harper Jun 30 '18 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.