9

I made a custom module allowing user to upload .PDF file type in CMS > Pages. The code used is below:

app/etc/modules

<?xml version="1.0"?>
<config>
  <modules>
    <Pdf_WysiwygFiles>
      <active>true</active>
      <codePool>local</codePool>
    </Pdf_WysiwygFiles>
  </modules>
</config>

app/code/local/Pdf/WysiwygFiles/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <modules>
    <Pdf_WysiwygFiles>
      <version>1.0.0</version>
    </Pdf_WysiwygFiles>
  </modules>
  <adminhtml>
    <cms>
      <browser>
        <extensions>
          <allowed>
            <jpg>1</jpg>
            <jpeg>1</jpeg>
            <png>1</png>
            <gif>1</gif>
            <pdf>1</pdf>
          </allowed>
        </extensions>
      </browser>
    </cms>
  </adminhtml>
</config>

This works in CE-1.9 and does allow to upload PDF file when you click on Insert Image button and does not allow to link it.

Also, how to add a pdf preview icon for each file uploaded ? The result would be like below image

enter image description here

2
  • What did you try ? Feb 14, 2015 at 1:28
  • @RKT-JoinMageStackDay2015, the above code says what I tried. Feb 16, 2015 at 4:25

3 Answers 3

8

In order to allow to upload and link pdf file, I modified your config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <modules>
    <Pdf_WysiwygFiles>
      <version>1.0.0</version>
    </Pdf_WysiwygFiles>
  </modules>
  <adminhtml>
    <cms>
      <browser>
        <extensions>
          <allowed>
            <pdf>1</pdf>
          </allowed>
        </extensions>
      </browser>
    </cms>
  </adminhtml>
</config>

For the icon you can use css styles. Add this in your stylesheet, for example: skin/frontend/rwd/default/css/styles.css

.col-main a[href$=".pdf"]:after {
  content: "";
  display: inline-block;
  width: 20px;
  height: 20px;
  background: url(../images/icon_pdf.png) no-repeat;
  margin-left: 5px;
}

EDIT:

Removed this part:

          <media_allowed>
            <pdf>1</pdf>
          </media_allowed>
5
  • Thanks for your response, but with my config.xml I can still insert link, upload pdf file and insert it. What is the base difference between <media_allowed> and <allowed> Feb 16, 2015 at 5:05
  • And how do I know if the file type uploaded is a .doc/.xls/.pdf ? Feb 16, 2015 at 5:45
  • I think @Vikram is right, "media_allowed" isn't present anywhere in Magento so probably has no effect. Maybe it used to in old versions but I checked down to 1.4.0.0 and couldn't find anything. Jun 2, 2015 at 13:43
  • It looks like you are right, it has no effect.
    – mkutyba
    Jun 3, 2015 at 5:39
  • This is not enough any more, see e.g. stackoverflow.com/q/44387645/719023
    – Simon
    Jan 18, 2018 at 14:13
1

For upload pdf file on WYSIWYG follow the below steps:

We need to upload pdf files through the WYSIWYG tool on Magento. I have checked the native functionality and it allows by default only images (jpg, png and gif).

So, to change the initial behavior I opened the file app/code/core/Mage/Cms/etc/config.xml, which defines the filetypes that can be uploaded, and around line 110 I have added the line 1 as below:

<allowed>
<jpg>1</jpg>
<jpeg>1</jpeg>
<png>1</png>
<gif>1</gif>
  <pdf>1</pdf>
</allowed>

Now refresh the browser and you can upload pfd file also.

1
  • 2
    So you are practically editing a Core file, right? Which is always a bad idea. The very moment an upgrade or patch will update this file, your own updates are lost.
    – Dragos
    Sep 19, 2017 at 12:25
0

in Order to allow upload a pdf you should add the following in a modoules config.xml

<adminhtml>
        <cms>
            <browser>
                <extensions>
                    <image_allowed>
                        <pdf>1</pdf>
                    </image_allowed>
                </extensions>
            </browser>
        </cms>
    </adminhtml>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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