Magento – Magento 1.9.1.0 – Upload PDF File Type in Wysiwyg Editor and show PDF Icon

cmscssmagento-1.9pdfwysiwyg

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

Best Answer

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>
Related Topic