How to open PDF attachments from the wiki directly in the browser?

Last modified by Ecaterina Moraru (Valica) on 2017/09/04

In order to improve security a new feature was added starting with XWiki 5.2: the possibility to specify in xwiki.properties which types of attachments can be displayed inline. See the release notes for XWiki 5.2

Here is the default behaviour (starting with XE 5.2) when you want to open PDF attachments from your wiki:

  •  if the PDF file was uploaded by users with no programming rights, then the file is automatically downloaded upon click
  •  if the PDF file was uploaded by a user with programming rights (e.g. Admin) then the file is opened directly in browser upon click

To always allow opening the PDF attachment directly in browser, you would need to add the MIME-type application/pdf in WEB-INF/xwiki.properties as follows:

  • open WEB-INF/xwiki.properties and go to the Attachment section
  • uncomment the line with the default whitelist and add to it application/pdf:
    attachment.download.whitelist=audio/basic,audio/L24,audio/mp4,audio/mpeg,audio/ogg,audio/vorbis,audio/vnd.rn-realaudio,audio/vnd.wave,audio/webm,image/gif,image/jpeg,image/pjpeg,image/png,image/svg+xml,image/tiff,text/csv,text/plain,text/xml,text/rtf,video/mpeg,video/ogg,video/quicktime,video/webm,video/x-matroska,video/x-ms-wmv,video/x-flv,application/pdf
  • save the modifications and restart the server

XWikiProperties.png 

The same behaviour can be achieved for other types of attachments that you want to open directly in browser. You need to search what is the right MIME type for your file and add it to the Attachment section from WEB-INF/xwiki.properties.

Get Connected