Jump to content

Extension:PdfHandler: Difference between revisions

From mediawiki.org
Content deleted Content added
mNo edit summary
No idea what this is trying to say
 
(14 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
{{bundled|1.21}}
{{Extension
{{Extension
|author=Martin Seidel (xarax)
|author=Martin Seidel (xarax)
Line 10: Line 9:
|needs-updatephp=No
|needs-updatephp=No
|readme=
|readme=
|description=Allows to handle PDF files like multipage DJVU
|description=<translate><!--T:34--> Allows to handle PDF files like multipage DJVU</translate>
|vagrant-role=pdfhandler
|vagrant-role=pdfhandler
|rights=
|rights=
Line 17: Line 16:
* [https://sandbox.semantic-mediawiki.org/wiki/PDFHandler sandbox.semantic-mediawiki.org]
* [https://sandbox.semantic-mediawiki.org/wiki/PDFHandler sandbox.semantic-mediawiki.org]
|phabricator = MediaWiki-extensions-PdfHandler
|phabricator = MediaWiki-extensions-PdfHandler
|pagedrive1 = true
|CheckUsageNameOverride = PDF_Handler
|CheckUsageNameOverride = PDF_Handler
}}
}}


<translate><!--T:12--> The '''<tvar name=1>PdfHandler</tvar>''' extension shows uploaded PDF files in a multipage preview layout.</translate><ref>
<translate><!--T:12--> The '''<tvar name=1>PdfHandler</tvar>''' extension shows uploaded PDF files in a multipage preview layout.</translate>
PROBABLY not required any more: with {{ll|Extension:WebStore|WebStore}} enabled, the extension automatically generates images from the specified page
</ref>


<translate><!--T:13--> Together with the [[<tvar name=1>Special:MyLanguage/Extension:ProofreadPage</tvar>|Proofread Page extension]], PDF files can be displayed side-by-side with text.</translate>
<translate><!--T:13--> Together with the [[<tvar name=1>Special:MyLanguage/Extension:ProofreadPage</tvar>|Proofread Page extension]], PDF files can be displayed side-by-side with text.</translate>
Line 31: Line 27:
== Usage == <!--T:1-->
== Usage == <!--T:1-->
</translate>
</translate>
* <translate><!--T:16--> A user can display PDF files as an image, showing a single page at a time, like so: <tvar name=1><code><nowiki>[[File:myPdfFile.pdf|page=1|600px]]</nowiki></code></tvar>.</translate> <translate><!--T:17--> The <code>page</code> and <code>size</code> parameters are optional; the default page is page #1.</translate> <translate><!--T:18--> Instead of a <code>size</code>-parameter, you can also use the <code>thumb</code>-parameter, with or without captions:</translate> <code><nowiki>[[File:myPdfFile.pdf|page=1|thumb|My PDF]]</nowiki></code>.<ref><translate><!--T:19--> This single page option was introduced quite long ago ([<tvar name=1>http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/PdfHandler/PdfHandler_body.php?revision=25575&view=markup</tvar> r25575])</translate></ref>
* <translate><!--T:16--> A user can display PDF files as an image, showing a single page at a time, like so: <tvar name=1><code><nowiki>[[File:myPdfFile.pdf|page=1|600px]]</nowiki></code></tvar>.</translate> <translate><!--T:17--> The <code>page</code> and <code>size</code> parameters are optional; the default page is page #1.</translate> <translate><!--T:18--> Instead of a <code>size</code>-parameter, you can also use the <code>thumb</code>-parameter, with or without captions:</translate> <code><nowiki>[[File:myPdfFile.pdf|page=1|thumb|My PDF]]</nowiki></code>.<ref><translate><!--T:19--> This single page option was introduced quite long ago (<tvar name=2>[http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/PdfHandler/PdfHandler_body.php?revision=25575&view=markup r25575]</tvar>)</translate></ref>
* <translate><!--T:27--> Because PdfHandler extends ImageHandler, you can use all the arguments that you would for an [[Help:Image|Image]] -- for example: <code>thumb</code>, <code>right</code>/<code>left</code>, <code>caption</code>, <code>border</code>, <code>link</code>, etc.</translate>
* <translate><!--T:27--> Because PdfHandler extends ImageHandler, you can use all the arguments that you would for an [[Help:Image|Image]] -- for example: <code>thumb</code>, <code>right</code>/<code>left</code>, <code>caption</code>, <code>border</code>, <code>link</code>, etc.</translate>
:<translate><!--T:28--> If you would like to present a 2-page pdf, for example, do the following: <code><nowiki>[[File:myPdfFile.pdf|page=1]] [[File:myPdfFile.pdf|page=2]]</nowiki></code></translate>
:<translate><!--T:28--> If you would like to present a 2-page pdf, for example, do the following: <code><nowiki>[[File:myPdfFile.pdf|page=1]] [[File:myPdfFile.pdf|page=2]]</nowiki></code></translate>
* The main usage of the PdfHandler extension is without user interaction. If you upload a new pdf file, the metadata will be stored in the database, and then this file can be shown in a multipage preview layout like the djvu handler does. Without this extension, pdfs will not display properly when uploaded.
* <translate><!--T:35--> The main usage of the PdfHandler extension is without user interaction.</translate> <translate><!--T:36--> If you upload a new pdf file, the metadata will be stored in the database, and then this file can be shown in a multipage preview layout like the djvu handler does.</translate> <translate><!--T:37--> Without this extension, pdfs will not display properly when uploaded.</translate>
* Additionally, this extension allows [[Extension:ProofreadPage]] to handle pdfs in side-by-side view for transcribing/proofreading, as is done on [[s:|Wikisource]]
* <translate><!--T:38--> Additionally, this extension allows <tvar name=1>{{ll|Extension:ProofreadPage}}</tvar> to handle pdfs in side-by-side view for transcribing/proofreading, as is done on [[s:|Wikisource]]</translate>


<translate>
<translate>

== Pre-requisites == <!--T:2-->
== Pre-requisites == <!--T:2-->
</translate>
</translate>
Line 44: Line 39:


{|class=wikitable
{|class=wikitable
! <translate><!--T:29--> Package</translate>
! Package !! Description !! Link
! <translate><!--T:30--> Description</translate>
! <translate><!--T:31--> Link</translate>
|- valign=top
|- valign=top
! <code>ghostscript</code>
! <code>ghostscript</code>
| Renders the page images.
| <translate><!--T:32--> Renders the page images.</translate>


<translate><!--T:21--> It provides the command <tvar name=1><code>gs</code></tvar>.</translate>
<translate><!--T:21--> It provides the command <tvar name=1><code>gs</code></tvar>.</translate>
Line 53: Line 50:
|- valign=top
|- valign=top
! [[Special:MyLanguage/Manual:Image administration#Image thumbnailing|<code>imagemagick</code>]]
! [[Special:MyLanguage/Manual:Image administration#Image thumbnailing|<code>imagemagick</code>]]
| Does dynamic resizing and thumbnailing of images.
| <translate><!--T:33--> Does dynamic resizing and thumbnailing of images.</translate>


It provides the command <code>convert</code>.
<translate><!--T:39--> It provides the command <tvar name=1><code>convert</code></tvar>.</translate>
| [https://www.imagemagick.org/script/install-source.php www.imagemagick.org]
| [https://www.imagemagick.org/script/install-source.php www.imagemagick.org]
|- valign=top
|- valign=top
! <code>xpdf-utils</code><br>or<br><code>poppler-utils</code>
! <code>xpdf-utils</code> <code>poppler-utils</code>
| Extracts metadata from PDF files. If you see "0 × 0 pixel" on the file description of a PDF, you lack this package.
| <translate><!--T:40--> Extracts metadata from PDF files. If you see "0 × 0 pixel" on the file description of a PDF, you lack this package.</translate>


<translate><!--T:22--> It provides the command <tvar name=1><code>pdfinfo</code></tvar>.</translate>
<translate><!--T:22--> It provides the command <tvar name=1><code>pdfinfo</code></tvar>.</translate>
| [https://www.xpdfreader.com/download.html www.xpdfreader.com]
| [https://www.xpdfreader.com/download.html www.xpdfreader.com]


On Ubuntu and Debian, the "poppler-utils" package can be used instead of "xpdf-utils".
<translate><!--T:41--> On Ubuntu and Debian, the "<tvar name=1>poppler-utils</tvar>" package can be used instead of "<tvar name=2>xpdf-utils</tvar>".</translate>
|}
|}


Type the following in your [[wikipedia:Shell (computing)|shell]] to see if you have the above installed first (it should list 4 rows):
<translate><!--T:42--> Type the following in your [[wikipedia:Shell (computing)|shell]] to see if you have the above installed first (it should list 4 rows):</translate>
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
which gs convert pdfinfo pdftotext
which gs convert pdfinfo pdftotext
Line 85: Line 82:
== Installation == <!--T:3-->
== Installation == <!--T:3-->
</translate>
</translate>
{{bundled|1.21}}
{{ExtensionInstall
{{ExtensionInstall
|custom-steps0=* <translate><!--T:10--> Make sure that the [[<tvar name=1>#Pre-requisites</tvar>|required software]] is installed before you continue!</translate>
|custom-steps0=* <translate><!--T:10--> Make sure that the [[<tvar name=1>#Pre-requisites</tvar>|required software]] is installed before you continue!</translate>
Line 95: Line 93:
== Configuration == <!--T:4-->
== Configuration == <!--T:4-->
</translate>
</translate>
You can (or, depending on the operating system of the server, will have to) set some variables in the "LocalSettings.php" file:
<translate><!--T:43--> You can (or, depending on the operating system of the server, will have to) set some variables in the "<tvar name=1>LocalSettings.php</tvar>" file:</translate>
; <code>$wgPdfProcessor</code> (default = "gs")
: path to your ghostscript implementation
; <code>$wgPdfPostProcessor</code> (default = "convert")
: path to your imagemagick convert
; <code>$wgPdfInfo</code> (default = "pdfinfo")
: path to your pdfinfo
; <code>$wgPdftoText</code> (default = "pdftotext")
: path to your pdftotext
; <code>$wgPdfOutputExtension</code> (default = "jpg")
: preferred output format<ref name="wgPdfOutputExtension">This does not preclude rendering to other formats, as the picture is served in a format determined by the extension (suffix) in its <code>src=</code> path, not by <code>$wgPdfOutputExtension</code>. The server-side choice can be overridden with a user script&nbsp;– see [[m:User:Incnis_Mrsi/PDF-PNG.js|example]].</ref>
; <code>$wgPdfHandlerDpi</code> (default = "150" )
: resolution in dpi
: The extension extracts a bitmap image for each page of the PDF, using this resolution (dpi = dots per inch). For example, a PDF page with the European size A4 is 210 mm wide, corresponding to 595 points (at 72 dpi). This yields an image 1240 pixels wide (at 150 dpi). If instead this parameter is set to 300 dpi, the width will be 2480 pixels.
; <code>$wgPdfHandlerJpegQuality</code> (default = "95" / since MW 1.24+ )
: Quality level, which the post processor should use.


{| class="wikitable"
; Variables below are not specific to this extension
! <translate><!--T:44--> Name</translate> !! <translate><!--T:45--> Default</translate> !! <translate><!--T:46--> Description</translate>
* Enable PDF uploads, if you haven't already: <code>{{ll|Manual:$wgFileExtensions|$wgFileExtensions}}[] = 'pdf';</code>
|-
* Enable ImageMagick, if you haven't already: <code>{{ll|Manual:$wgUseImageMagick|$wgUseImageMagick}} = true;</code>
| <code>$wgPdfProcessor</code>
* '''<code>{{ll|Manual:$wgMaxShellMemory|$wgMaxShellMemory}}</code>''' - memory limit for gs, convert and pdfinfo. The default value might be too low.
| {{phpi|"gs"}}
| <translate><!--T:47--> path to your ghostscript implementation</translate>
|-
| <code>$wgPdfPostProcessor</code>
| {{phpi|"convert"}}
| <translate><!--T:48--> path to your imagemagick convert</translate>
|-
| <code>$wgPdfInfo</code>
| {{phpi|"pdfinfo"}}
| <translate><!--T:49--> path to your pdfinfo</translate>
|-
| <code>$wgPdftoText</code>
| {{phpi|"pdftotext"}}
| <translate><!--T:50--> path to your pdftotext</translate>
|-
| <code>$wgPdfOutputExtension</code>
| {{phpi|"jpg"}}
| <translate><!--T:51--> preferred output format</translate><ref name="wgPdfOutputExtension"><translate><!--T:52--> This does not preclude rendering to other formats, as the picture is served in a format determined by the extension (suffix) in its <tvar name=1><code>src=</code></tvar> path, not by <tvar name=2><code>$wgPdfOutputExtension</code></tvar>.</translate> <translate><!--T:53--> The server-side choice can be overridden with a user script&nbsp;– see [[m:User:Incnis_Mrsi/PDF-PNG.js|example]].</translate></ref>
|-
| <code>$wgPdfHandlerDpi</code>
| {{phpi|"150"}}
| <translate><!--T:54--> resolution in dpi</translate>
<translate><!--T:55--> The extension extracts a bitmap image for each page of the PDF, using this resolution (dpi = dots per inch).</translate> <translate><!--T:56--> For example, a PDF page with the European size A4 is 210 mm wide, corresponding to 595 points (at 72 dpi).</translate> <translate><!--T:57--> This yields an image 1240 pixels wide (at 150 dpi).</translate> <translate><!--T:58--> If instead this parameter is set to 300 dpi, the width will be 2480 pixels.</translate>
|-
| <code>$wgPdfHandlerJpegQuality</code>
| {{phpi|"95"}} {{introduced-inline|1.24}}
| <translate><!--T:60--> Quality level, which the post processor should use.</translate>
|}

; <translate><!--T:61--> Variables below are not specific to this extension</translate>
* <translate><!--T:62--> Enable PDF uploads, if you haven't already:</translate> <code>{{ll|Manual:$wgFileExtensions|$wgFileExtensions}}[] = 'pdf';</code>
* <translate><!--T:63--> Enable ImageMagick, if you haven't already:</translate> <code>{{ll|Manual:$wgUseImageMagick|$wgUseImageMagick}} = true;</code>
* '''<code>{{ll|Manual:$wgMaxShellMemory|$wgMaxShellMemory}}</code>''' - <translate><!--T:64--> memory limit for gs, convert and pdfinfo.</translate> <translate><!--T:65--> The default value might be too low.</translate>


=== Ubuntu ===
=== Ubuntu ===
{{Note}} This is identical to the default settings for this extension.
{{Note|1=<translate><!--T:66--> This is identical to the default settings for this extension.</translate>}}

<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
$wgPdfProcessor = 'gs';
$wgPdfProcessor = 'gs';
$wgPdfPostProcessor = $wgImageMagickConvertCommand; // if defined via ImageMagick
$wgPdfPostProcessor = $wgImageMagickConvertCommand; // <translate nowrap><!--T:67--> if defined via ImageMagick</translate>
// $wgPdfPostProcessor = 'convert'; // if not defined via ImageMagick
// $wgPdfPostProcessor = 'convert'; // <translate nowrap><!--T:68--> if not defined via ImageMagick</translate>
$wgPdfInfo = 'pdfinfo';
$wgPdfInfo = 'pdfinfo';
$wgPdftoText = 'pdftotext';
$wgPdftoText = 'pdftotext';
Line 130: Line 147:
<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
$wgPdfProcessor = '/usr/bin/gs';
$wgPdfProcessor = '/usr/bin/gs';
$wgPdfPostProcessor = $wgImageMagickConvertCommand; // if defined via ImageMagick
$wgPdfPostProcessor = $wgImageMagickConvertCommand; // <translate nowrap><!--T:69--> if defined via ImageMagick</translate>
// $wgPdfPostProcessor = '/usr/bin/convert'; // if not defined via ImageMagick
// $wgPdfPostProcessor = '/usr/bin/convert'; // <translate nowrap><!--T:70--> if not defined via ImageMagick</translate>
$wgPdfInfo = '/usr/bin/pdfinfo';
$wgPdfInfo = '/usr/bin/pdfinfo';
$wgPdftoText = '/usr/bin/pdftotext';
$wgPdftoText = '/usr/bin/pdftotext';
Line 139: Line 156:
<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
$wgPdfProcessor = 'C:\Program Files\gs\gs8.60\bin\gswin32.exe';
$wgPdfProcessor = 'C:\Program Files\gs\gs8.60\bin\gswin32.exe';
$wgPdfPostProcessor = $wgImageMagickConvertCommand; // if defined via ImageMagick
$wgPdfPostProcessor = $wgImageMagickConvertCommand; // <translate nowrap><!--T:71--> if defined via ImageMagick</translate>
// $wgPdfPostProcessor = 'C:\Program Files\ImageMagick-6.6.2-Q16\convert.exe'; // if not defined via ImageMagick
// $wgPdfPostProcessor = 'C:\Program Files\ImageMagick-6.6.2-Q16\convert.exe'; // <translate nowrap><!--T:72--> if not defined via ImageMagick</translate>
$wgPdfInfo = 'C:\Program Files\xpdf-3.02pl1-win32\pdfinfo.exe';
$wgPdfInfo = 'C:\Program Files\xpdf-3.02pl1-win32\pdfinfo.exe';
$wgPdftoText = 'C:\Program Files\xpdf-3.02pl1-win32\pdftotext.exe';
$wgPdftoText = 'C:\Program Files\xpdf-3.02pl1-win32\pdftotext.exe';
Line 148: Line 165:
<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
$wgPdfProcessor = '/usr/local/bin/gs';
$wgPdfProcessor = '/usr/local/bin/gs';
$wgPdfPostProcessor = $wgImageMagickConvertCommand; // if defined via ImageMagick
$wgPdfPostProcessor = $wgImageMagickConvertCommand; // <translate nowrap><!--T:73--> if defined via ImageMagick</translate>
// $wgPdfPostProcessor = '/usr/local/bin/convert'; // if not defined via ImageMagick
// $wgPdfPostProcessor = '/usr/local/bin/convert'; // <translate nowrap><!--T:74--> if not defined via ImageMagick</translate>
$wgPdfInfo = '/usr/local/bin/pdfinfo';
$wgPdfInfo = '/usr/local/bin/pdfinfo';
$wgPdftoText = '/usr/local/bin/pdftotext';
$wgPdftoText = '/usr/local/bin/pdftotext';
Line 157: Line 174:
== Troubleshooting == <!--T:5-->
== Troubleshooting == <!--T:5-->
</translate>
</translate>
* If PDF files do not display after upload, make sure that MediaWiki can execute the pdfinfo command and that [[#Configuration|configuration parameter <code>$wgPdfInfo</code>]] is set properly. Also check your error log, and make sure that your host hasn't disabled running external commands.
* <translate><!--T:75--> If PDF files do not display after upload, make sure that MediaWiki can execute the pdfinfo command and that [[<tvar name=1>#Configuration</tvar>|configuration parameter <tvar name=2><code>$wgPdfInfo</code></tvar>]] is set properly.</translate> <translate><!--T:76--> Also check your error log, and make sure that your host hasn't disabled running external commands.</translate>
* If PDF files do not show properly after installation (for example, showing "0 × 0 pixels") you may need to use the {{ll|Manual:Maintenance scripts|maintenance scripts}} {{Manual|refreshImageMetadata.php}} and/or {{Manual|rebuildImages.php}}. For example:<syntaxhighlight lang=bashg>$ php ./maintenance/run.php refreshImageMetadata --mime application/pdf --force</syntaxhighlight>
* <translate><!--T:77--> If PDF files do not show properly after installation (for example, showing "0 × 0 pixels") you may need to use the <tvar name=1>{{ll|Manual:Maintenance scripts|nsp=0}} {{Manual|refreshImageMetadata.php}}</tvar> and/or <tvar name=2>{{Manual|rebuildImages.php}}</tvar>.</translate> <translate><!--T:78--> For example:</translate><syntaxhighlight lang=bash>$ php ./maintenance/run.php refreshImageMetadata --mime application/pdf --force</syntaxhighlight>
*: Also try to purge the page of the file. See [[Manual:Purge]].
*: <translate><!--T:79--> Also try to purge the page of the file.</translate> <translate><!--T:80--> See <tvar name=1>{{ll|Manual:Purge}}</tvar>.</translate>
* If PDF files are rendered randomly check if the "C.UTF-8" locale is available on your server by running <code>locale -a</code>.
* <translate><!--T:81--> If PDF files are rendered randomly check if the "C.UTF-8" locale is available on your server by running <tvar name=1><code>locale -a</code></tvar>.</translate>


<translate>
<translate>

==Notes== <!--T:6-->
==Notes== <!--T:6-->
</translate>
</translate>

Latest revision as of 01:33, 22 July 2026

MediaWiki extensions manual
PdfHandler
Release status: stable
Implementation Media
Description Allows to handle PDF files like multipage DJVU
Author(s) Martin Seidel (xarax)
Compatibility policy Snapshots releases along with MediaWiki. Master is not backward compatible.
Database changes No
  • $wgPdfHandlerJpegQuality
  • $wgPdfOutputExtension
  • $wgPdfInfo
  • $wgPdfProcessor
  • $wgPdftoText
  • $wgPdfPostProcessor
  • $wgPdfHandlerDpi
Licence GNU General Public License 2.0 or later
Download
Example
Translate the PdfHandler extension if it is available at translatewiki.net
Vagrant role pdfhandler
Issues Open tasks · Report a bug

The PdfHandler extension shows uploaded PDF files in a multipage preview layout.

Together with the Proofread Page extension, PDF files can be displayed side-by-side with text. This allows users to transcribe books and other documents.[1]

Usage

[edit | edit source]
  • A user can display PDF files as an image, showing a single page at a time, like so: [[File:myPdfFile.pdf|page=1|600px]]. The page and size parameters are optional; the default page is page #1. Instead of a size-parameter, you can also use the thumb-parameter, with or without captions: [[File:myPdfFile.pdf|page=1|thumb|My PDF]].[2]
  • Because PdfHandler extends ImageHandler, you can use all the arguments that you would for an Image -- for example: thumb, right/left, caption, border, link, etc.
If you would like to present a 2-page pdf, for example, do the following: [[File:myPdfFile.pdf|page=1]] [[File:myPdfFile.pdf|page=2]]
  • The main usage of the PdfHandler extension is without user interaction. If you upload a new pdf file, the metadata will be stored in the database, and then this file can be shown in a multipage preview layout like the djvu handler does. Without this extension, pdfs will not display properly when uploaded.
  • Additionally, this extension allows Extension:ProofreadPage to handle pdfs in side-by-side view for transcribing/proofreading, as is done on Wikisource

Pre-requisites

[edit | edit source]

This extension requires the following packages to be installed first:

Package Description Link
ghostscript Renders the page images.

It provides the command gs.

www.ghostscript.com
imagemagick Does dynamic resizing and thumbnailing of images.

It provides the command convert.

www.imagemagick.org
xpdf-utils poppler-utils Extracts metadata from PDF files. If you see "0 × 0 pixel" on the file description of a PDF, you lack this package.

It provides the command pdfinfo.

www.xpdfreader.com

On Ubuntu and Debian, the "poppler-utils" package can be used instead of "xpdf-utils".

Type the following in your shell to see if you have the above installed first (it should list 4 rows):

which gs convert pdfinfo pdftotext

If something is missing, install the related packages. Example in Debian and Ubuntu:

sudo apt install ghostscript imagemagick xpdf-utils

If you are unable to install these packages, kindly contact your server administrator for assistance in your environment.

Installation

[edit | edit source]
This extension comes with MediaWiki 1.21 and later, so you do not need to download it. The remaining configuration instructions must still be followed.
  • Make sure that the required software is installed before you continue!
  • Download and move the extracted PdfHandler folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:
    cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/PdfHandler
    
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'PdfHandler' );
    
  • Configure as required. (see also the examples provided)
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration

[edit | edit source]

You can (or, depending on the operating system of the server, will have to) set some variables in the "LocalSettings.php" file:

Name Default Description
$wgPdfProcessor "gs" path to your ghostscript implementation
$wgPdfPostProcessor "convert" path to your imagemagick convert
$wgPdfInfo "pdfinfo" path to your pdfinfo
$wgPdftoText "pdftotext" path to your pdftotext
$wgPdfOutputExtension "jpg" preferred output format[3]
$wgPdfHandlerDpi "150" resolution in dpi

The extension extracts a bitmap image for each page of the PDF, using this resolution (dpi = dots per inch). For example, a PDF page with the European size A4 is 210 mm wide, corresponding to 595 points (at 72 dpi). This yields an image 1240 pixels wide (at 150 dpi). If instead this parameter is set to 300 dpi, the width will be 2480 pixels.

$wgPdfHandlerJpegQuality "95" (introduced in 1.24) Quality level, which the post processor should use.
Variables below are not specific to this extension

Ubuntu

[edit | edit source]
This is identical to the default settings for this extension.
$wgPdfProcessor = 'gs';
$wgPdfPostProcessor = $wgImageMagickConvertCommand; // if defined via ImageMagick
// $wgPdfPostProcessor = 'convert'; // if not defined via ImageMagick
$wgPdfInfo = 'pdfinfo';
$wgPdftoText = 'pdftotext';

Debian

[edit | edit source]
$wgPdfProcessor = '/usr/bin/gs';
$wgPdfPostProcessor = $wgImageMagickConvertCommand; // if defined via ImageMagick
// $wgPdfPostProcessor = '/usr/bin/convert';  // if not defined via ImageMagick
$wgPdfInfo = '/usr/bin/pdfinfo';
$wgPdftoText = '/usr/bin/pdftotext';

Windows

[edit | edit source]
$wgPdfProcessor = 'C:\Program Files\gs\gs8.60\bin\gswin32.exe';
$wgPdfPostProcessor = $wgImageMagickConvertCommand; // if defined via ImageMagick
// $wgPdfPostProcessor = 'C:\Program Files\ImageMagick-6.6.2-Q16\convert.exe'; // if not defined via ImageMagick
$wgPdfInfo = 'C:\Program Files\xpdf-3.02pl1-win32\pdfinfo.exe';
$wgPdftoText = 'C:\Program Files\xpdf-3.02pl1-win32\pdftotext.exe';

macOS

[edit | edit source]
$wgPdfProcessor = '/usr/local/bin/gs';
$wgPdfPostProcessor = $wgImageMagickConvertCommand; // if defined via ImageMagick
// $wgPdfPostProcessor = '/usr/local/bin/convert'; // if not defined via ImageMagick
$wgPdfInfo = '/usr/local/bin/pdfinfo';
$wgPdftoText = '/usr/local/bin/pdftotext';

Troubleshooting

[edit | edit source]
  • If PDF files do not display after upload, make sure that MediaWiki can execute the pdfinfo command and that configuration parameter $wgPdfInfo is set properly. Also check your error log, and make sure that your host hasn't disabled running external commands.
  • If PDF files do not show properly after installation (for example, showing "0 × 0 pixels") you may need to use the Maintenance scripts refreshImageMetadata.php and/or rebuildImages.php. For example:
    $ php ./maintenance/run.php refreshImageMetadata --mime application/pdf --force
    
    Also try to purge the page of the file. See Manual:Purge .
  • If PDF files are rendered randomly check if the "C.UTF-8" locale is available on your server by running locale -a.

Notes

[edit | edit source]
  1. This allows users to transcribe books and other documents as is commonly done with DjVu files (particularly in Wikisource).
  2. This single page option was introduced quite long ago (r25575)
  3. This does not preclude rendering to other formats, as the picture is served in a format determined by the extension (suffix) in its src= path, not by $wgPdfOutputExtension. The server-side choice can be overridden with a user script – see example.

See also

[edit | edit source]