
內容簡介
<h3>文章總結:</h3>
<ul>
<li>Rapls PDF Image Creator在將PDF文件上傳到WordPress媒體庫時自動生成縮略圖影像。</li>
<li>這個外掛使用ImageMagick(Imagick PHP擴展)將PDF的第一頁轉換為影像。</li>
</ul>
<h3>問題與答案:</h3>
<ol>
<li>
<strong>如何生成PDF文件的縮略圖?</strong>
<ul>
<li>將PDF文件上傳到媒體庫。</li>
<li>外掛會自動將第一頁轉換為影像。</li>
<li>該影像會被註冊為PDF的特色圖片。</li>
<li>使用短代碼或模板功能來顯示縮略圖。</li>
</ul>
</li>
<li>
<strong>外掛生成什麼樣式的文件?</strong>
<ul>
<li>my-document.pdf上傳後,外掛會創建:</li>
<li>my-document-pdf.jpg(完整封面圖像)</li>
<li>my-document-pdf-1024x768.jpg(大)</li>
<li>my-document-pdf-300x225.jpg(中)</li>
<li>my-document-pdf-150x150.jpg(縮圖)</li>
<li>根據您的主題設置添加其他大小。 </li>
</ul>
</li>
<li>
<strong>如何使用模板功能顯示PDF縮略圖?</strong>
<ul>
<li>在主題中顯示PDF縮略圖:</li>
<li>設置$ pdf_id = 123;</li>
<li>如果(rapls_pic_has_thumbnail($ pdf_id)){</li>
<li>echo rapls_pic_get_thumbnail_image($ pdf_id,'medium'); //顯示中尺寸圖像</li>
</ul>
</li>
</ol>
外掛標籤
開發者團隊
原文外掛簡介
Rapls PDF Image Creator automatically generates thumbnail images when you upload PDF files to your WordPress Media Library. The plugin uses ImageMagick (Imagick PHP extension) to convert the first page of a PDF into an image.
Key Features
Automatic Generation – Thumbnails are created instantly when PDFs are uploaded
Featured Image Support – Generated thumbnails are automatically set as the PDF’s featured image
Multiple Sizes – Images are generated in all registered WordPress image sizes
Media Library Integration – Display thumbnails instead of default PDF icons
Editor Integration – Insert PDF links with thumbnail images into your posts
Bulk Generation – Generate thumbnails for all existing PDFs at once
Flexible Output – Choose from JPEG, PNG, or WebP formats
How It Works
Upload a PDF file to the Media Library
The plugin automatically converts the first page to an image
The image is registered as the PDF’s featured image
Use shortcodes or template functions to display the thumbnail
Generated Files
When you upload my-document.pdf, the plugin creates:
my-document-pdf.jpg (Full size cover image)
my-document-pdf-1024×768.jpg (Large)
my-document-pdf-300×225.jpg (Medium)
my-document-pdf-150×150.jpg (Thumbnail)
Additional sizes based on your theme settings
Shortcodes
[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 thumbnail
Template Functions
rapls_pic_get_thumbnail_url( $pdf_id, $size ) – Get thumbnail URL
rapls_pic_get_thumbnail_id( $pdf_id ) – Get thumbnail attachment ID
rapls_pic_get_thumbnail_image( $pdf_id, $size, $attr ) – Get thumbnail HTML
rapls_pic_has_thumbnail( $pdf_id ) – Check if PDF has thumbnail
rapls_pic_generate_thumbnail( $pdf_id, $force ) – Generate thumbnail
Requirements
WordPress 5.0 or higher
PHP 7.4 or higher
ImageMagick with Imagick PHP extension and PDF support
Most shared hosting providers have ImageMagick available. Check the Status tab in plugin settings to verify your server meets the requirements.
Using Template Functions
Display a PDF thumbnail in your theme:
$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 '';
echo wp_get_attachment_image( $thumbnail_id, 'medium' );
echo '';
}
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 width
rapls_pdf_image_creator_thumbnail_max_height – Maximum height
rapls_pdf_image_creator_thumbnail_quality – Image quality (1-100)
rapls_pdf_image_creator_thumbnail_format – Output format
rapls_pdf_image_creator_thumbnail_bgcolor – Background color
rapls_pdf_image_creator_thumbnail_image_attributes – Image tag attributes
rapls_pdf_image_creator_custom_insert_html – Custom insert HTML
rapls_pdf_image_creator_hide_thumbnails_in_library – Hide in Media Library
Available Action Hooks
rapls_pdf_image_creator_before_generate – Before thumbnail generation
rapls_pdf_image_creator_after_generate – After successful generation
rapls_pdf_image_creator_generation_failed – When generation fails
