Tags:
create new tag
, view all tags

EmbedPDFPlugin

Embed PDF documents in TWiki pages

Introduction

Many browsers can show PDF documents embedded just like pictures within HTML documents using the <object> HTML tag. Unfortunately, they are usually unable to detect the preferred (screen) size and aspect ratio of the PDF document and display only a little unreadable thumbnail version of the PDF file.

This plugin adds %EMBEDPDF{...}% and %EMBEDPDFSIZE{...}% variables. These variables are helpful for embedding PDF documents in TWiki webs. %EMBEDPDF{...}% will create an <object> HTML tag to show the specified PDF file in a reasonable size (as specified within that PDF file). %EMBEDPDFSIZE{...}% will expand to the width and height of the file.

Caution

  1. This plugin read files from your disk using TWiki::Func::readFile(). It may be possible for an attacker to gain access to arbitrary files on your disk. I have taken some simple precautions to prevent this, but I'm not sure whether they are sufficient.
  2. TWiki may run out of memory if the PDF file referenced is very large. It is mainly intended for small single-page PDF files.

You might want to restrict write access to your Web to prevent intruders from exploiting possible vulnerabilities. I do not think exploits are possible through read-only access. Use at your own risk.

Syntax Rules

  • %EMBEDPDF{ <filename> }%
  • %EMBEDPDFSIZE{ <filename> }%
    • <filename> is the file name of an attachment of the current topic.

Examples

Assume that test.pdf has a height of 40 points and a width of 100 points. Then:

  • %EMBEDPDF{ test }% expands to
    <object data="%ATTACHURLPATH%/test.pdf" width="100" height="40" type="application/pdf">
    <param name="src" value="%ATTACHURLPATH%/test.pdf" />
    <a href="/p/pub/Plugins/EmbedPDFPlugin/pdf.pdf">pdf.pdf</a>
    </object>
  • %EMBEDPDFSIZE{ test }% expands to
    width="100" height="40"
Note that the .pdf extension is automatically added to the attachment name.

The plugin checks the user agent setting reported by your browser to detect IE. For IE, the width and height will be enlarged since IE displays the PDF viewer controls within the HTML document along with the PDF document itself.

EmbedPDFPlugin Global Settings

Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %INTERWIKIPLUGIN_SHORTDESCRIPTION%

  • One line description, is shown in the TextFormattingRules topic:
    • Set SHORTDESCRIPTION = Embed PDF documents in TWiki pages

  • Debug plugin: (See output in data/debug.txt)
    • Set DEBUG = 0

  • Create a link under every embedded PDF file with the specified link text if set (useful for browsers that don't know how to embed PDF):
    • Set LINKTEXT = (click here to display this PDF file by itself)

  • Check whether a pre-rendered image of the PDF file with the specified extension is available, and if so, embed the image rather than the PDF file itself:
    • Set PRERENDERED = jpg

Plugin Installation Instructions

Note: You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the server where TWiki is running.

  • For an automated installation, run the configure script and follow "Find More Extensions" in the in the Extensions section.

  • Or, follow these manual installation steps:
    • Download the ZIP file from the Plugins home (see below).
    • Unzip EmbedPDFPlugin.zip in your twiki installation directory. Content:
      File: Description:
      data/TWiki/EmbedPDFPlugin.txt Plugin topic
      pub/TWiki/EmbedPDFPlugin/pdf.pdf Sample pdf file
      lib/TWiki/Plugins/EmbedPDFPlugin.pm Plugin Perl module
    • Set the ownership of the extracted directories and files to the webserver user.

  • Plugin configuration and testing:
    • Run the configure script and enable the plugin in the Plugins section.
    • Test if the installation was successful: The following two pictures should look the same (assuming you have a PDF plugin installed in your browser)
      • Embed tag created using %EMBEDPDF{ pdf }%:
        %EMBEDPDF{ pdf }%
      • Hard coded embed tag:
        pdf.pdf
    • The width and height of http://www.twiki.org/p/pub/Plugins/EmbedPDFPlugin/pdf.pdf as determined by %EMBEDPDFSIZE{ pdf }% are as follows:
      • %EMBEDPDFSIZE{ pdf }%
    • Here is a pdf file for which we have a pre-rendered version available. The actual pdf file is missing, so the link under the image is dead:
      %EMBEDPDF{ pdf-prerendered }%

Plugin Info

Plugin Author: TWiki:Main.JohannesMartin
Copyright: © 2003 TWiki:Main.JohannesMartin
© 2008-2011 TWiki:TWiki.TWikiContributor
Plugin Version: 2011-05-10
Change History:  
2011-05-10: TWikibug:Item6701: Change <embed> tag to <object> tag; doc improvements -- TWiki:Main.PeterThoeny
07 Mar 2003: added support for IE and link text
06 Mar 2003: Initial version
CPAN Dependencies: none
Other Dependencies: none
Perl Version: 5.080
Plugin Home: http://TWiki.org/cgi-bin/view/Plugins/EmbedPDFPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/EmbedPDFPluginDev

Related Topics: TWiki:Plugins.EmbedPDFPluginDev, TWikiPreferences, TWikiPlugins

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatmd5 EmbedPDFPlugin.md5 r4 r3 r2 r1 manage 0.2 K 2011-05-11 - 07:35 PeterThoeny  
Compressed Zip archivetgz EmbedPDFPlugin.tgz r4 r3 r2 r1 manage 9.0 K 2011-05-11 - 07:35 PeterThoeny  
Compressed Zip archivezip EmbedPDFPlugin.zip r9 r8 r7 r6 r5 manage 11.0 K 2011-05-11 - 07:35 PeterThoeny  
Unknown file formatEXT EmbedPDFPlugin_installer r3 r2 r1 manage 3.4 K 2011-05-11 - 07:35 PeterThoeny  
Edit | Attach | Watch | Print version | History: r15 < r14 < r13 < r12 < r11 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r15 - 2013-10-16 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2015 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.