Hi,

I have a pdf file. I like to have an opt-in block which will allow people to enter email address and then click download. PDF file should be downloaded to their machine. Please advise.

Comments

mikebrooks’s picture

Use the Webform module https://www.drupal.org/project/webform to collect the email address. You can configure the form to be exposed as a block.

In the Webform module configuration, you can indicate a page to redirect the user upon form submission. In this page, include the download link.

drupalfriend123’s picture

Thank you. I got everything except the download part "In this page, include the download link.". How can I have a link that will download the file?

mikebrooks’s picture

It is not clear to me the step(s) that you are having a problem with.

In summary, I would:

Create a new page node.

In the Body of the page, include the hyperlink to the PDF, e.g. <a href="http://www.example.com/sites/default/files/mypdf.pdf">Download my PDF!</a>

In the <a></a> tag, you can include the target="_blank" attribute to force the PDF to open (or download) from a new tab. (How the PDF will open is browser dependent and/or subject to the user's browser preference settings.)

If you want to force the PDF to download, i.e. open a 'save as' dialog box, try putting the following line in the .htaccess file of the docroot:

# Set PDF files to download, rather than open in the browser.
AddType application/octet-stream .pdf
drupalfriend123’s picture

Thank you. That is what I needed.

DenisVS’s picture

Will the new page be unavailable for a direct link?