Domanda

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.

È stato utile?

Soluzione

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

Altri suggerimenti

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>

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.

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!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top