1

I am using Magento 2.1 and I want to display download link in my Contact us page.

enter image description here

If I click in this link then I want to display PDF file.

PЯINCƎ
11.8k3 gold badges27 silver badges85 bronze badges
asked Oct 3, 2018 at 20:29
2
  • You can follow the steps mentions in the @Renaud answer magento.stackexchange.com/questions/149584/… Commented Oct 3, 2018 at 20:41
  • Please accept and upvote answer if it's useful for you. So, other developer can use this answer. Commented Oct 4, 2018 at 11:27

6 Answers 6

4

For download PDF :

<a href="{{media url="pdf/1.pdf"}}" download>Please download PDF</a>

For view PDF :

<a href="{{media url="pdf/1.pdf"}}" target="_blank">Please download PDF</a>

Example output :

<a href="http://domanin.com/pub/media/pdf/1.pdf">Please download PDF</a>

File path location should be :

{MagentoRootFolder}/pub/media/pdf/1.pdf
answered Oct 4, 2018 at 4:27
1

If you want to add a Download link on the CMS page or CMS Static block, You can use the below code:

The file location to store the pdf is

app/design/frontend/{Vendor}/{themeName}/web/pdf/001.pdf

How to view and download file in CMS Block:

<a href="{{view url="pdf/001.pdf"}}" download="001.pdf">Please download PDF</a>

How to open in a new tab:

<a href="{{view url="pdf/001.pdf"}}" target="_blank">Next Page PDF</a>
answered Dec 5, 2020 at 11:13
0
0

1- Adding link in contact form 2- Adding pdf in server.

  1. app/design/frontend/{Vendor}/{themeName}/Magento_Contact/templates/form.phtml

    <a href="<?php echo $block->getViewFileUrl('pdf/001.pdf'); ?>" download="001.pdf"><?= $block->escapeHtml(__('Please download Appli...'))?></a>
    
  2. app/design/frontend/{Vendor}/{themeName}/web/pdf/001.pdf

    Now when you click on this link, you'll download the pdf 001.pdf file.

answered Oct 3, 2018 at 23:04
2
  • Hi! Thank you for the response, If I create Content-->blocks or Content-->pages then how can I give this dowmload link ? Commented Oct 4, 2018 at 1:22
  • <a href="{{media url="pdf/001.pdf"}}" download="001.pdf">Please download...</a> Commented Oct 4, 2018 at 5:58
0

If you want to add Download link on CMS page or CMS Static block, You can use below code.

<a href="{{media url="pdf/001.pdf"}}" download="001.pdf">Please download PDF</a>

If you want to Show pdf in new tab, You can use below code

<a href="{{media url="pdf/001.pdf"}}" target="_blank">Please download PDF</a>

And location of pdf file will be

{MagentoRoot}/pub/media/pdf/001.pdf

Hope above will help!

answered Oct 4, 2018 at 3:38
0

Place your pdf inside the web folder of your module then run all Magento commands. You can see your pdf to be generated in pub/static folder using that you can give downloadable link

<a id="sample-file-link" href="<?php echo $block->getViewFileUrl('Vendor_module/file.pdf'); ?> ">Download link</a>
answered Dec 30, 2021 at 6:39
0

I have done same functionality working fine. Now I want to save customer data in custom table on download pdf. Please anyone help.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.