Extension talk:PdfHandler

About this board

PdfHandler Talk Archive


Darlig Gitarist (talkcontribs)

PDFHandler extension is supposed to allow viewing of pdf files. However, this does not appear to be working as advertised.

We've gone through the troubleshooting area of MediaWiki for this plugin and double-checked the paths to PDF converters. We re-ran the maint scripts for images and image meta. We checked the logs.

There is no indication of errors other than the images not showing up.

MediaWiki 1.35.5
PHP 7.4.27 (fpm-fcgi)
MySQL 5.7.37-0ubuntu0.18.04.1-log
ICU 60.2
Lua 5.1.5
PDF Handler – (16eda4b) 20:58, 2022 January 23

Any help or suggestions would be appreciated.

Cboltz (talkcontribs)

Wild guess: Some Linux distributions (for example openSUSE) have disabled rendering of PDF files in their default ImageMagick config because it has been a steady source of security issues (for example "ImageTragick"). In openSUSE, you'd need to install the ImageMagick-config-7-upstream package to enable rendering of PDF files.

Note: I don't know if Ubuntu did something similar with the ImageMagick config.

If unsure, test if converting a PDF to an image in the shell works: convert foo.pdf foo.png

Reply to "No PDF images displayed"

No PDF/thumbnail, issue executing pdfinfo/pdftotext, Windows Server 2012 R2, IIS 8.5, MW 1.31

5
Tommyheyser (talkcontribs)

MW 1.31.1 running on Windows Server 2012 R2 IIS 8.5

I'm getting the following error (from $wgDebugLogFile output log file) for all execution of pdfinfo and pdftotext.

[exec] Error running "pdfinfo" "-enc" "UTF-8" "-meta" "C:/inetpub/wwwroot/w/images/f/f4/Phone_List.pdf": 'pdfinfo" "-enc" "UTF-8" "-meta" "C:' is not recognized as an internal or external command, operable program or batch file.

I'm not sure if this is the result of the new Shell framework introduced in 1.30, Manual:Shell framework, which replaces wfShellExec(). The debug log line before the error is:

[exec] MediaWiki\Shell\Command::execute: "pdfinfo" "-enc" "UTF-8" "-meta" "C:/inetpub/wwwroot/w/images/f/f4/Phone_List.pdf"

Tommyheyser (talkcontribs)
Tommyheyser (talkcontribs)

In case someone else is having this issue of not seeing PDF and is running MW 1.31 on Windows Server 2012 R2.

  1. I added the path to pdfinfo.exe and pdftotext.exe to System variables path (mine was C:\Program Files\xpdf-tools-win-4.00\bin64).
  2. Then, I edit {mediawiki install path}/extensions/PdfHandler/includes/PdfImage.php function retrieveMetaData.

a. Replacing:

$cmdMeta = [
$wgPdfInfo,
'-enc', 'UTF-8', # Report metadata as UTF-8 text...
'-meta',         # Report XMP metadata
$this->mFilename,
];

with

$cmdMeta = "pdfinfo.exe -enc UTF-8 -meta " . $this->mFilename;

b. Replacing

$cmdPages = [
$wgPdfInfo,
'-enc', 'UTF-8', # Report metadata as UTF-8 text...
'-l', '9999999', # Report page sizes for all pages
$this->mFilename,
];

with

$cmdPages = "pdfinfo.exe -enc UTF-8 -l 9999999 " . $this->mFilename;

c. Replacing

$cmd = [ $wgPdftoText,  $this->mFilename, '-' ];

with

$cmd = "pdftotext.exe " . $this->mFilename;


It's a bit of a hack, but it works. This should last until the issue is properly fixed.

173.77.3.157 (talkcontribs)
Mwgbell (talkcontribs)

I had a similar problem using ImageMagick 7.1.0-19 Q16-HDRI with MedaiWiki 1.37.1 on Windows 11. To fix it, in extensions\PdfHandler\includes\PdfHandler.php

Change this line:

$cmd .= " | " . wfEscapeShellArg(

$wgPdfPostProcessor,

"-depth",

"8",

"-quality",

$wgPdfHandlerJpegQuality,

"-resize",

$width,

"-",

$dstPath

);

To this: (i.e. move the "-" to the first thing after the $wgPdfPostProcessor, line):

$cmd .= " | " . wfEscapeShellArg(

$wgPdfPostProcessor,

"-",

"-depth",

"8",

"-quality",

$wgPdfHandlerJpegQuality,

"-resize",

$width,

$dstPath

);

Reply to "No PDF/thumbnail, issue executing pdfinfo/pdftotext, Windows Server 2012 R2, IIS 8.5, MW 1.31"

PDFs won't display, MW shows security warning error

5
Woozle (talkcontribs)

I had this extension installed and working on two wikis. After upgrading each at different times (to 1.31.7 and 1.32), I later noticed that it is no longer rendering them on File: pages or anywhere else, and the File: pages now show a pop-up security warning (when you hover over the "application/pdf" text) which links to Special:MyLanguage/Help:Security/PDF_files -- but that page has no information about suppressing the warning.

I'm thinking that whatever is triggering the warning is preventing the extension from rendering the files, but I haven't been able to find any information about how to change that.

Does anyone have any information about this?

Thanks.

Dinoguy1000 (talkcontribs)

The first thing to do is to make sure your extensions are up to date as well.

The warning is about generic issues with the PDF format as a whole and has nothing to do with the configuration details of any individual website. It also shouldn't prevent the preview from displaying (see for example commons:File:JUA0680291.pdf, where both a preview of the PDF and the warning popup are visible). You should be able to hide the warning via CSS, though I've never done this myself so I can't advise on what classes or IDs you need to use. Unfortunately I can't provide any help with why the previews aren't displaying for you; I've had the same issue on a wiki of mine for a while.

Woozle (talkcontribs)

Another extension does seem to have been causing the issue in at least one wiki, though it's not clear how the two were interfering with each other. Still investigating -- but PDFs on that wiki seem to be rendering properly now.

Dinoguy1000 (talkcontribs)

Which extension?

Woozle (talkcontribs)

I think it was one of mine, not one that MW distributes.

Reply to "PDFs won't display, MW shows security warning error"

PdfHandler with ApprovedRevs

2
213.115.193.20 (talkcontribs)

Hello,

Im using approvedRevs to approve stuff on our wiki. So if I link to a file on a page it will display the latest approved version of it.

If I link to a pdf with PdfHander it will always displays the latest version.

Anyone using approvedRevs and managed to get PdfHandler only to display the latest approved version?


Thanks

Jonathan3 (talkcontribs)
Reply to "PdfHandler with ApprovedRevs"

There are a few PDF files for which no thumbnail is created

1
Jonathan3 (talkcontribs)

Is there anything to watch out for here? Anything I can change? The files which aren't working show as 0 x 0 pixels. Thanks.

Reply to "There are a few PDF files for which no thumbnail is created"

How to create thumbnails of all existing PDF files?

1
Jonathan3 (talkcontribs)

I've finally managed to get this great extension to work. But when I look at Special:NewFiles or a PDF's File: page, it still shows the generic PDF logo until I purge the File: page.

Is there any way of purging all the File: pages and creating thumbnails for them all, all at once? Thanks.

Reply to "How to create thumbnails of all existing PDF files?"
TelePointHistory (talkcontribs)

I am trying to use PdfHandler to show thumbnails but know I don't have the pre-requisites.

Running the command in SSH: which gs convert pdfinfo pdftotext

shows that I have ghostscript but no packages for xpdf-utils

/bin/gs

/bin/convert

/usr/bin/which: no pdfinfo etc

/usr/bin/which: no pdftotext etc


Looking at this page https://www.xpdfreader.com/download.html I don't know what file to download or where to put it once it's downloaded. I am on Siteground hosting with WM 1.35.3 if that makes a difference. I'm hoping someone can give me a basic rundown for how it's meant to work. thanks.

Kghbln (talkcontribs)

Siteground has to install this for you on the server I guess. Best way is to contact their support.

Reply to "Installing xpdf-utils"
Heinebold (talkcontribs)

The srcset is broken when on a locale that formats numbers differently.

The "1.5x" is generated using the current locale instead of ensuring that it is in a format that the browser understands.

On a locale that uses the decimal comma, that results in a broken image for unzoomed view, since the browser doesnt get image1 1.5x, image2 2x, but image1 1,5x, image2 2x , which means the three "images" image1 1, 5x, and image2.

I think you shouldn't rely on the locale to format numbers that have to follow source code syntax.

Dinoguy1000 (talkcontribs)

Would you mind filing a task for this on Phabricator? It is more likely to get developer attention there.

Reply to "Locale breaks images"
Huwmanbeing (talkcontribs)

I run MediaWiki 1.33 on Ubuntu with the latest version of PdfHandler, but thumbnails aren't being shown for PDFs. There's no obvious error being generated, the thumbnail images just don't appear. (Embedding a link like [[File:Sample.pdf|page=1|thumb|Test]] produces only the text link with no image, and the file page itself shows only the generic PDF file type icon.)

I've verified I have all the necessary prerequisites:

  • /usr/bin/gs
  • /usr/bin/convert
  • /usr/bin/pdfinfo
  • /usr/bin/pdftotext

I've run the recommended maintenance scripts, but still no luck. I've also made sure it's appropriately configured in my LocalSettings.php — the settings are present and identical to the default settings. Does anyone have any ideas/suggestions as to what might be causing thumbnails not to appear? Any assistance would be much appreciated! Huwmanbeing (talk) 14:33, 7 September 2019 (UTC)

This post was hidden by Heinebold (history)
Huwmanbeing (talkcontribs)

Thanks very much for the suggestions — unfortunately no luck. No thumbnails in links, and the file page still just shows the PDF icon and the 0 x 0 size.

I seem to have hit a wall here: everything's apparently set correctly as far as I can tell, and there are no obvious errors, but it just doesn't work. Could anyone suggest ways to debug this?

Kghbln (talkcontribs)

Try this:

  1. Have a look if you have a "temp" directory at path/to/images/temp
  2. If not create this directory: mkdir path/to/images/temp
  3. Make it writable for the webserver chown www-data:www-data path/to/images/temp
  4. Run php path/to/maintenance/refreshImageMetadata.php -f
  5. Run php path/to/maintenance/rebuildImages.php
Huwmanbeing (talkcontribs)

I've confirmed that "images/temp" is present and chown-ed properly to www-data, and have run the maintenance scripts, but unfortunately still no luck.

I'm curious, though — what should one normally see when running rebuildImages.php? Here's what it's showing me:

Processing image... [...] Finished image... 0 of 852 rows updated Processing oldimage... Finished oldimage... 0 of 13 rows updated

Is the fact that it's reporting no rows updated in any way significant?

Kghbln (talkcontribs)

0 just means that there was nothing to update. The more interesting script is the one of point 4. If this ran without throwing errors you should be fine, i.e. no longer pdf files with 0 x 0 size. Cannot tell why it is not working for you now. :( I guess I am really out of ideas now. The permissions of "temp" are ok with 755?

Huwmanbeing (talkcontribs)

A breakthrough — I decided to start disabling all installed extensions just to see if there might be something there that's interfering, and I found that turning off TimedMediaHandler allows PDFs to be displayed and thumbnailed correctly. Now when refreshImageMetadata runs it does so successfully (well, mostly — it gives some warnings about some metadata inconsistencies in some of my .ogg files). I'll investigate further and see if I can find out more specifically what's happening, but at least it's working now.

Huwmanbeing (talkcontribs)

Here's the fault:

PHP Notice: Undefined offset: 0 in [...]/includes/libs/mime/MimeAnalyzer.php on line 811
[5cd1086a420507df361326be] [no req]   Error from line 15 of [...]/extensions/TimedMediaHandler/includes/handlers/ID3Handler/ID3Handler.php: Class 'getID3' not found
Backtrace:
#0 [...]/extensions/TimedMediaHandler/includes/handlers/ID3Handler/ID3Handler.php(51): ID3Handler->getID3(string)
#1 [...]/includes/utils/MWFileProps.php(84): ID3Handler->getMetadata(FSFile, string)
#2 [...]/includes/filerepo/FileRepo.php(1560): MWFileProps->getPropsFromPath(string, string)
#3 [...]/includes/filerepo/file/LocalFile.php(402): FileRepo->getFileProps(string)
#4 [...]/includes/filerepo/file/LocalFile.php(710): LocalFile->loadFromFile()
#5 [...]/maintenance/refreshImageMetadata.php(173): LocalFile->upgradeRow()
#6 [...]/maintenance/doMaintenance.php(96): RefreshImageMetadata->execute()
#7 [...]/maintenance/refreshImageMetadata.php(264): require_once(string)
#8 {main}
Kghbln (talkcontribs)

Oh, that's interesting. Good find. Are you also on REL1_33 for TimedMediaHandler? If yes, this is a bug which should be reported on Phabricator for TimedMediaHandler.

Huwmanbeing (talkcontribs)

Yep, my version of TimedMediaHandler is indeed the latest — REL1_33.

Looks like there's already a thread about it here and that other users have experienced something similar. It sounds like those (like me) who download the TimedMediaHandler extension as a file via the ExtensionDistributor will miss out on certain necessary dependencies, and that instead one must install it through composer. I'm afraid I'm not familiar with Phabricator, but if the problem hasn't already been raised there then it seems like it should be.

Thank you again for your help!

Reply to "Thumbnails not appearing"

Error creating thumbnail: /bin/bash: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)

4
Jonathan3 (talkcontribs)

When I enable this extension and set the four path config variables, I get the message above. It appears several times on the File: pages. I'll look into it myself, but wonder if anyone can help put me on the right track. Thanks. ~~~~

Jonathan3 (talkcontribs)

It appears for every PDF file in Special:NewFiles - no problem with .txt and .gif files.

Additionally, two files have the following error: "**** Warning: Short look-up table in the Indexed color space was padded with 0's. **** Warning: Short look-up table in the Indexed color space was padded with 0's. **** This file had errors that were repaired or ignored. **** The file was produced by: **** >>>> Acrobat Distiller 9.3.3 (Windows) <<<< **** Please notify the author of the software that produced this **** file that it does not conform to Adobe's published PDF **** specification."

Jonathan3 (talkcontribs)

I've just upgraded to MW 1.34.1 and am having the same problem. Does anyone have any ideas? Thanks!

Jonathan3 (talkcontribs)
Reply to "Error creating thumbnail: /bin/bash: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)"