PDF

From Meta, a Wikimedia project coordination wiki
This is an archived version of this page, as edited by NilamDoctor~metawiki (talk | contribs) at 17:02, 15 March 2007 (New page: ==PDF extension== Copy the code in to pdf.php and add the following string to LocalSettings.php require ("extension/pdf.php"); This will include a PDF file to you media wiki <?php // ...). It may differ significantly from the current version.
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

PDF extension

Copy the code in to pdf.php and add the following string to LocalSettings.php

require ("extension/pdf.php");

This will include a PDF file to you media wiki

<?php
// MediaWiki PDF Extension Ver 0.1
// Set up MediaWiki to react to the "<PDF>" tag
// Original file by Nilam Doctor
// <ceo@qualifiedtutorsinc.com> to allow local PDF files

$wgExtensionFunctions[] = "wfPDF";
function wfPDF() {
        global $wgParser;
        $wgParser->setHook( "pdf", "RenderPDF" );
}
function RenderPDF( $input, $argv ) {
     global $wgScriptPath;
     $output = "";
     // external URL
     if ( strpos($input , "http") === 0 && strpos($input, ".pdf") == strlen($input)-4 ) {
       $url = $input;
     }
     // internal Media:
     else { 
       $url = $input;       
     }
     $width  = isset($argv['width']) ? $argv['width']  : 800;
     $height = isset($argv['height'])? $argv['height'] : 600;
     $id = basename($input, ".pdf");
     $output  .=<<<EOM
     <IFRAME width=800 height=600 SRC="$url" FRAMEBORDER=0 FRAMEBORDERCOLOR="#000000"></IFRAME>

EOM;

     $output = str_replace("\n", "", $output);
     return $output;
}
?>