| 开发者 | |
|---|---|
| 更新时间 | 2026年9月28日 11:33 |
my-document.pdf, the plugin creates:
[rapls_pdf_thumbnail id="123"] - Display thumbnail image[rapls_pdf_thumbnail_url id="123"] - Output thumbnail URL[rapls_pdf_clickable_thumbnail id="123"] - Thumbnail linked to PDF[rapls_pdf_download_link id="123"] - Download link with thumbnailrapls_pic_get_thumbnail_url( $pdf_id, $size ) - Get thumbnail URLrapls_pic_get_thumbnail_id( $pdf_id ) - Get thumbnail attachment IDrapls_pic_get_thumbnail_image( $pdf_id, $size, $attr ) - Get thumbnail HTMLrapls_pic_has_thumbnail( $pdf_id ) - Check if PDF has thumbnailrapls_pic_generate_thumbnail( $pdf_id, $force ) - Generate thumbnailrapls-pdf-image-creator folder to /wp-content/plugins/$pdf_id = 123; if ( rapls_pic_has_thumbnail( $pdf_id ) ) { echo rapls_pic_get_thumbnail_image( $pdf_id, 'medium' ); }
Link thumbnail to PDF file:
$pdf_id = 123; if ( $thumbnail_id = get_post_thumbnail_id( $pdf_id ) ) { echo '<a href="' . esc_url( wp_get_attachment_url( $pdf_id ) ) . '" target="_blank">'; echo wp_get_attachment_image( $thumbnail_id, 'medium' ); echo '</a>'; }
Display All PDFs Attached to a Post
`
$pdfs = get_posts( array(
'post_type' => 'attachment',
'post_mime_type' => 'application/pdf',
'post_parent' => get_the_ID(),
'posts_per_page' => -1,
) );
foreach ( $pdfs as $pdf ) {
if ( rapls_pic_has_thumbnail( $pdf->ID ) ) {
printf(
'%s',
esc_url( wp_get_attachment_url( $pdf->ID ) ),
rapls_pic_get_thumbnail_image( $pdf->ID, 'thumbnail' )
);
}
}
`
Available Filter Hooks
rapls_pdf_image_creator_thumbnail_page - PDF page to use (default: 0)rapls_pdf_image_creator_thumbnail_max_width - Maximum widthrapls_pdf_image_creator_thumbnail_max_height - Maximum heightrapls_pdf_image_creator_thumbnail_resolution - Rendering resolution in DPI (default: 150)rapls_pdf_image_creator_thumbnail_quality - Image quality (1-100)rapls_pdf_image_creator_thumbnail_format - Output formatrapls_pdf_image_creator_thumbnail_bgcolor - Background colorrapls_pdf_image_creator_thumbnail_image_attributes - Image tag attributesrapls_pdf_image_creator_custom_insert_html - Custom insert HTMLrapls_pdf_image_creator_hide_thumbnails_in_library - Hide in Media Libraryrapls_pdf_image_creator_policy_paths - ImageMagick policy.xml paths to search when diagnosing blocked PDF supportrapls_pdf_image_creator_color_conversion - auto (default), icc or naive. naive restores the pre-1.1.0 colorsrapls_pdf_image_creator_icc_paths - Array of absolute paths to search, per profile type (srgb / cmyk)rapls_pdf_image_creator_rendering_intent - An Imagick::RENDERINGINTENT_* value (default: relative colorimetric)rapls_pdf_image_creator_flatten_background - Background transparency is flattened onto (default: the configured background, or white for JPEG)add_filter( 'rapls_pdf_image_creator_icc_paths', function( $paths, $type ) { if ( 'cmyk' === $type ) { return array( '/srv/icc/JapanColor2011Coated.icc' ); } return $paths; }, 10, 2 );
Available Action Hooks
rapls_pdf_image_creator_before_generate - Before thumbnail generationrapls_pdf_image_creator_after_generate - After successful generationrapls_pdf_image_creator_generation_failed - When generation failsA full guide with setup instructions, the fix for the infamous "black thumbnail" problem (CMYK / PDF/X), and real-world usage tips:
You need ImageMagick with the Imagick PHP extension and PDF support. Most shared hosting providers have this available. Contact your hosting provider if you need to enable it.
Go to Settings > Rapls PDF Image Creator > Status tab. The plugin will show whether ImageMagick is available and properly configured. For detailed troubleshooting including common server setup issues, see the setup guide.
Check Settings > Rapls PDF Image Creator > Status. If it reports ImageMagick 6, that is the cause.
ImageMagick 6 can render a PDF it judges to be CMYK through Ghostscript's bmpsep8 device, which writes a separation BMP that ImageMagick's own BMP reader cannot decode. Depending on the exact ImageMagick and Ghostscript versions, the read either fails outright or returns an empty raster — which becomes a blank white thumbnail. ImageMagick 7 uses a different device and is unaffected.
Not every ImageMagick 6 build is affected: on Xserver's 6.9.13-25 a CMYK page renders correctly. Since 1.3.2 the Status tab renders a test page and reports what this server actually does, rather than warning on the version number.
The plugin cannot work around this, because ImageMagick picks the device from the PDF's own content and no Imagick API call overrides it. Ask your hosting provider to upgrade to ImageMagick 7, or to change the ps:cmyk delegate in delegates.xml from bmpsep8 to pamcmyk32.
RGB PDFs are not affected, which is why only some of your PDFs fail.
If the PDF uses CMYK colours and no ICC profile is available on your server, the plugin falls back to a simple arithmetic conversion, which exaggerates greens and blues. Check Settings > Rapls PDF Image Creator > Status to see whether ICC colour management is active. Installing a CMYK profile on the server, or pointing the rapls_pdf_image_creator_icc_paths filter at one, restores accurate colours.
Thumbnails are not regenerated automatically, because regenerating every PDF on a large site during an update is not something a plugin should decide to do. Go to Settings > Rapls PDF Image Creator > Bulk Generate and regenerate them.
If you would rather keep the previous colours, pin the old behaviour:
add_filter( 'rapls_pdf_image_creator_color_conversion', function() { return 'naive'; } );
Yes. Go to Settings > Rapls PDF Image Creator > Bulk Generate tab to scan and generate thumbnails for all existing PDFs.
Those two settings only scale the rendered page down. They never enlarge it. The size the page is rendered at comes from Rendering Resolution instead, which was fixed at 150 DPI before version 1.2.0 — an A4 page at 150 DPI is about 1240x1754 pixels, and no maximum above that could produce anything bigger. Raise Rendering Resolution (Settings > Rapls PDF Image Creator > Image Settings) and the rendered page grows with it; the maximum dimensions then cap the result as before. Bear in mind that memory use during generation grows with the square of the resolution, so raise it in steps if your server is small.
Go to Tools > Site Health. The "PDF thumbnail generation" test says whether this server can render PDFs, and if not, what to ask your hosting provider for. The same report is on the Status tab of the plugin's settings page, and Site Health > Info has a Rapls PDF Image Creator section you can copy into a support request. There are two different server problems, and they need different requests:
policy.xml that denies the PDF coder, a precaution left over from a 2018 Ghostscript vulnerability. Ask your host to give the PDF coder read rights. The plugin shows the path of the file responsible.JPEG, PNG, and WebP. Configure your preferred format in the Image Settings tab.
By default, yes. To keep generated images as regular attachments, enable "Keep Images on Uninstall" in Display Settings before uninstalling.
Yes. Use the rapls_pdf_image_creator_thumbnail_page filter:
add_filter( 'rapls_pdf_image_creator_thumbnail_page', function( $page, $pdf_id ) { return 1; // Use second page (0-indexed) }, 10, 2 );
Without code, you can set the page for the whole site in Settings > Rapls PDF Image Creator > Page Number (0 is the first page).
Go to Settings > Rapls PDF Image Creator > Insert Settings. Choose from Image only, Title link, or Custom HTML with placeholders like {thumbnail}, {pdf_url}, {pdf_title}.
The plugin itself never runs Ghostscript. ImageMagick does, though: it passes PDFs to Ghostscript to read them, so ImageMagick's PDF support only works if Ghostscript is installed on the server. You don't have to check this by hand. The Status tab (Settings > Rapls PDF Image Creator > Status) tells you whether PDFs can be rendered on your server.
Two causes of black thumbnails have been fixed: PDF/X-1:2001 files (1.0.9), and transparent areas (1.1.0), which are now flattened onto the background colour you choose before the image is saved. If you choose a transparent background with JPEG output, white is used instead, because JPEG cannot store transparency. Thumbnails made before an update are not changed automatically, so regenerate an old black thumbnail before assuming the problem is still there.
Yes. Settings > Rapls PDF Image Creator > Rendering Resolution sets the DPI the page is rendered at, from 72 to 600 (150 by default). Raising it gives a larger, sharper thumbnail: Max Width and Max Height only scale the rendered page down, never up. Higher values use more memory while the thumbnail is being made.
rapls_pdf_image_creator_before_resize runs on the rendered page after transparency is flattened and before it is resized. The conversion options now also carry attachment_id and source_path, so a listener can tell which attachment it is looking atrapls_pdf_image_creator_generation_failed now fires on every failure rather than only on a conversion error, and passes a machine-readable code and the engine result as third and fourth arguments. Existing two-argument listeners are unaffectedbmpsep8 is the one that produces blank thumbnails, pamcmyk32 is fine. It turns "some ImageMagick 6 builds" into a request your host can act ondefault_cmyk.icc is now searched for. Any server that can render a PDF has Ghostscript on it, so this is the one CMYK profile present almost everywhere — on a server with no colour profiles at all, finding it moves the conversion from the arithmetic fallback to real colour management. Measured on a mixed CMYK/RGB brochure that is a 32 delta-E difference: the greens stop coming out fluorescent<!-- --> as active. The 1.3.1 changelog said this was fixed; the fix went into the standalone probe in tools/ and never reached the copy that ships. Hosting providers usually unblock PDF by commenting the deny rule out rather than deleting it, so an already-unblocked server could have the wrong policy file named in the explanationImagick::queryFormats('PDF') reports which coders were compiled in, not whether the security policy permits them — verified on ImageMagick 7.1.1, where a policy.xml denying the PDF coder still leaves PDF in queryFormats while reading one throws NotAuthorized. On such a server 1.3.0 reported "PDF thumbnails can be generated" and then failed silently on the first upload, which is the exact problem 1.3.0 set out to solveNotAuthorized means the policy; a Ghostscript failure means the delegate. The result is cached for 12 hours and re-checked when the ImageMagick version changes<!-- --> as active. Hosting providers usually unblock PDF by commenting the deny rule out rather than deleting it, so an already-fixed server could be reported as still blockedrapls_pdf_image_creator_policy_paths, for builds that keep policy.xml somewhere unusualrapls_pdf_image_creator_thumbnail_resolution, for setting the DPI per attachmentrapls_pdf_image_creator_icc_paths, rapls_pdf_image_creator_rendering_intent, rapls_pdf_image_creator_color_conversion and rapls_pdf_image_creator_flatten_backgroundrapls_pdf_image_creator_color_conversion filter