GS Only PDF Preview

GS Only PDF Preview

Wordpress plugin

Install on Wordpress

App Details

The plugin pre-empts the standard WordPress 4.7/4.8 PDF preview production process (which uses the PHP extension Imagick) to call Ghostscript directly to produce the preview.

This means that only Ghostscript is required on the server. Neither the PHP module Imagick nor the server package ImageMagick is needed or used (though it’s fine if they’re installed anyway, and if they are they’ll be used by WP (unless you override it) to produce the intermediate sizes of the preview).

Background

The plugin was prompted by the WP_Image_Editor_Imagick_External demonstration class uploaded to the WP Trac ticket #39262 Fall back to ImageMagick command line when the pecl imagic is not available on the server by Hristo Pandjarov, and by the wish to solve the WP Trac ticket #39216 PDFs with non-opaque alpha channels can result in previews with black backgrounds., which particularly affects PDFs with CMYK color spaces (common in the print world).

The plugin by-passes (as far as PDF previews are concerned) #39216, and also by-passes the related issue #39331 unsharpMaskImage in Imagick’s thumbnail_image is not compatible with CMYK JPEGs., as the preview JPEGs produced directly by Ghostscript use sRGB color spaces.

Limitations

The plugin requires the PHP function exec to be enabled on your system. So if the PHP ini setting disable_functions includes exec, the plugin won’t work. Neither will it work if the suhosin security extension is installed and exec is either not whitelisted or is blacklisted.

Also, the plugin is incompatible with the PHP ini setting safe_mode, an old (and misnamed) setting that was deprecated in PHP 5.3.0 and removed in PHP 5.4.0.

Security

The plugin uses the PHP function exec to call Ghostscript as a shell command. This has security implications as uncareful use with user supplied data (eg the upload file name or the file itself) could introduce an attack vector.

I believe these concerns are addressed here through screening of the file and its name and escaping of arguments. This belief is backed by a bounty of fifteen hundred thousand intergalactic credits to anyone who spots a security issue. Please disclose responsibly.

Performance

Unsurprisingly it’s faster. Crude benchmarking (see the script perf_vs_imagick.php) suggests it’s around 35-40% faster. However the production of the preview is only a part of the overhead of uploading a PDF (and doesn’t include producing the intermediate thumbnail sizes for instance) so any speed-up may not be that noticeable.

Size

On JPEG thumbnail size it appears to be comparable (though it depends on the PDF), maybe a bit larger on average. To mitigate this the default JPEG quality for the PDF preview has been lowered to 70 (from 82), which results in some extra “ringing” (speckles around letters) but the previews tested remain very readable. Note that this only affects the “full” PDF thumbnail – the intermediate-sized thumbnails as produced by Imagick or GD and any other non-PDF images remain at the standard JPEG quality of 82. You can use the WP filter wp_editor_set_quality to override this, for instance to restore the quality to 82 add to your theme’s “functions.php”:

function mytheme_wp_editor_set_quality( $quality, $mime_type ) { if ( 'application/pdf' === $mime_type ) { $quality = 82; } return $quality; } add_filter( 'wp_editor_set_quality', 'mytheme_wp_editor_set_quality', 10, 2 ); 

Quality

Eyeballing based on very limited data, ie anecdotally, the previews seem to be of superior definition with less artifacts (even with the JPEG quality reduced to 70), and more faithful to the original colours.

Tool

A basic administration tool to regenerate (or generate, if they previously didn’t have a preview) the previews of all PDFs uploaded to the system is included (any previously generated intermediate preview thumbnails will be removed if their dimensions differ). Note that if you have a lot of PDFs you may experience the White Screen Of Death (WSOD) if the tool exceeds the maximum execution time allowed. Note also that as the file names of the previews don’t (normally) change, you will probably have to refresh your browser to see the updated thumbnails.

As workarounds for the possible WSOD issue above, and as facilities in themselves, a “Regenerate PDF Previews” bulk action is added to the list mode of the Media Library, and a “Regenerate Preview” row action is added to each PDF entry in the list. So previews can be regenerated in batches or individually instead.

Patches

As a bonus version 1.0.2+ patches WordPress to allow linking to the preview image in “Add Media” when editing a post (#39618 Insert PDF Thumbnail into Editor). Also patches #39630 PDF Thumbnails in Media Library Don’t Fall Back to Full Size.

And

A google-cheating schoolboy French translation is supplied.

The plugin runs on WP 4.7.0 to 4.8.0, and requires Ghostscript to be installed on the server. The plugin should run on PHP 5.2.17 to 7.1, and on both Unix and Windows servers.

The project is on github.

Pricing

Starting from $0 per month.

Check Out the PDF Viewer Widget

By Common Ninja

PDF ViewerTry For Free!

App Info

Rating

Reviewers

8 reviews

Tags

pdf

Developed By

bonger

Quick & Easy

Find the Best Wordpress plugins for you

Common Ninja has a large selection of powerful Wordpress plugins that are easy to use, fully customizable, mobile-friendly and rich with features — so be sure to check them out!

Testimonial

Testimonial plugins for Wordpress

Contact Form

Contact Form plugins for Wordpress

Maps

Maps plugins for Wordpress

Translation

Translation plugins for Wordpress

Chat

Chat plugins for Wordpress

Slider

Slider plugins for Wordpress

Reviews

Reviews plugins for Wordpress

Contact

Contact plugins for Wordpress

Galleries

Galleries plugins for Wordpress

SEO

SEO plugins for Wordpress

Forms

Forms plugins for Wordpress

Comments

Comments plugins for Wordpress

Backup

Backup plugins for Wordpress

Privacy

Privacy plugins for Wordpress

Optimize

Optimize plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Social Sharing

Social Sharing plugins for Wordpress

Events Calendar

Events Calendar plugins for Wordpress

Comments

Comments plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

Social Sharing

Social Sharing plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Video Player

Video Player plugins for Wordpress

popup

popup plugins for Wordpress

SiteMap

SiteMap plugins for Wordpress

Payment

Payment plugins for Wordpress

Coming Soon

Coming Soon plugins for Wordpress

Inventory

Inventory plugins for Wordpress

Testimonials

Testimonials plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Membership

Membership plugins for Wordpress

Forms

Forms plugins for Wordpress

Analytics

Analytics plugins for Wordpress

Events Calendar

Events Calendar plugins for Wordpress

Sliders

Sliders plugins for Wordpress

Analytics

Analytics plugins for Wordpress

Reviews

Reviews plugins for Wordpress

Security

Security plugins for Wordpress

Ads

Ads plugins for Wordpress

Music Player

Music Player plugins for Wordpress

Countdown

Countdown plugins for Wordpress

Email Marketing

Email Marketing plugins for Wordpress

Membership

Membership plugins for Wordpress

Ecommerce

Ecommerce plugins for Wordpress

Customer Support

Customer Support plugins for Wordpress

Video Player

Video Player plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

Common Ninja Apps

Some of the best Common Ninja plugins for Wordpress

Browse our extensive collection of compatible plugins, and easily embed them on any website, blog, online store, e-commerce platform, or site builder.

PDF Viewer for Wordpress logo

PDF Viewer

Add a PDF viewer to your site to display documents, share product information, and give visitors easy access to helpful content in one place.

Corner Coupon Pop-up for Wordpress logo

Corner Coupon Pop-up

Add a corner coupon pop-up to highlight discounts, collect emails, and drive user engagement without interrupting browsing.

YouTube Carousel for Wordpress logo

YouTube Carousel

Show YouTube videos with a YouTube carousel that displays clips in a smooth, customizable layout to boost visibility and keep visitors engaged.

Diagrams for Wordpress logo

Diagrams

Create interactive diagrams with a diagrams widget that lets you build and customize flow charts, improve clarity, and help visitors understand complex ideas easily.

Section Builder for Wordpress logo

Section Builder

Create structured layouts with a section builder that lets you design custom website sections, customize styles, and organize content for a clearer user experience.

Video Carousel for Wordpress logo

Video Carousel

Showcase videos with a video carousel that rotates or slides clips, improves visual design, and keeps visitors watching and engaged.

Vimeo Slider for Wordpress logo

Vimeo Slider

Show Vimeo videos with a Vimeo slider that displays clips in a smooth slider to boost engagement and keep visitors watching.

Restaurant Menu Flip Cards for Wordpress logo

Restaurant Menu Flip Cards

Present dishes with restaurant menu flip cards that highlight key details, help visitors explore options easily, and support confident ordering decisions.

MP3 Player for Wordpress logo

MP3 Player

Add an MP3 Player to your website and engage visitors with music, podcasts, and spoken audio without any setup complexity.

Image Grid Slider for Wordpress logo

Image Grid Slider

Showcase visuals with an image grid slider that blends a grid layout and carousel motion to create a dynamic, customizable, mobile friendly display.

Bluesky Feed Slider for Wordpress logo

Bluesky Feed Slider

Show Bluesky posts with a Bluesky feed slider that scrolls updates and keeps content visible while keeping visitors engaged.

Pricing Slider for Wordpress logo

Pricing Slider

Use a pricing slider to show dynamic prices by quantity, help visitors compare options, and support confident purchases.

More plugins

plugins You Might Like

Discover Apps By Platform

Discover the best apps for your website

WordPress
Wix
Shopify
Weebly
Webflow
Joomla
PrestaShop
Shift4Shop
WebsiteX5
MODX
Opencart
NopCommerce

Common Ninja Search Engine

The Common Ninja Search Engine platform helps website builders find the best site widgets, apps, plugins, tools, add-ons, and extensions! Compatible with all major website building platforms - big or small - and updated regularly, our Search Engine tool provides you with the business tools your site needs!

Multiple platforms