{"id":2665,"date":"2023-08-30T23:57:27","date_gmt":"2023-08-30T15:57:27","guid":{"rendered":"https:\/\/www.tra56.com\/?p=2665"},"modified":"2023-08-30T23:57:27","modified_gmt":"2023-08-30T15:57:27","slug":"2665","status":"publish","type":"post","link":"https:\/\/www.tra56.com\/2665.html","title":{"rendered":"\u7528php\u628apdf\u8f6c\u6362\u6210\u56fe\u7247"},"content":{"rendered":"
\u6839\u636e\u62a5\u9519\u628a\u56fe\u7247\u6269\u5c55\u88c5\u4e0a\uff0copen_basedir\u8981\u8bbe\u7f6e\u4e00\u4e0b<\/span><\/span><\/strong><\/p>\n pdf\u8f6c\u6362\u6210jpg\/jpeg\u56fe\u7247<\/p>\n<\/ul>\n pdf\u8f6c\u6362\u6210png\u56fe\u7247<\/span><\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" \u6839\u636e\u62a5\u9519\u628a\u56fe\u7247\u6269\u5c55\u88c5\u4e0a\uff0copen_basedir\u8981\u8bbe\u7f6e\u4e00\u4e0b pdf\u8f6c\u6362\u6210jpg\/jpeg\u56fe\u7247 <?php […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,92],"tags":[],"class_list":["post-2665","post","type-post","status-publish","format-standard","hentry","category-php","category-phpcode"],"_links":{"self":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/2665"}],"collection":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/comments?post=2665"}],"version-history":[{"count":1,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/2665\/revisions"}],"predecessor-version":[{"id":2666,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/2665\/revisions\/2666"}],"wp:attachment":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media?parent=2665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/categories?post=2665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/tags?post=2665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<?php\r\n\/\/ PDF \u6587\u4ef6\u8def\u5f84\r\n$pdf_file = '.\/example.pdf';\r\n \r\n\/\/ \u521b\u5efa Imagick \u5bf9\u8c61\r\n$imagick = new Imagick($pdf_file);\r\n \r\n\/\/ \u8bbe\u7f6e\u5206\u8fa8\u7387\uff08\u53ef\u9009\uff09\r\n$imagick->setResolution(300, 300);\r\n \r\n\/\/ \u8bfb\u53d6 PDF \u6587\u4ef6\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u56fe\u7247\r\n$imagick->readImage($pdf_file);\r\n \r\n\/\/ \u521b\u5efa\u767d\u8272\u80cc\u666f\r\n$background = new Imagick();\r\n$background->newImage($imagick->getImageWidth(), $imagick->getImageHeight(), 'white');\r\n \r\n\/\/ \u5c06\u56fe\u50cf\u4e0e\u80cc\u666f\u5408\u5e76\r\n$background->compositeImage($imagick, Imagick::COMPOSITE_OVER, 0, 0);\r\n \r\n \r\n\/\/ \u5c06\u6bcf\u4e00\u9875\u56fe\u7247\u4fdd\u5b58\u4e3a\u6587\u4ef6\r\nforeach ($background as $page) {\r\n \/\/ \u8bbe\u7f6e\u8f93\u51fa\u6587\u4ef6\u540d\r\n $output_file = '\/www\/wwwroot\/test.xixishidi.cn\/page'.(array_search($page, iterator_to_array($page))+1).'.jpeg';\r\n \r\n \/\/ \u4fdd\u5b58\u4e3a PNG \u683c\u5f0f\r\n $page->setImageFormat('jpeg');\r\n \r\n \/\/ \u4fdd\u5b58\u4e3a\u6587\u4ef6\r\n $page->writeImage($output_file);\r\n}\r\n \r\n\/\/ \u91ca\u653e Imagick \u5bf9\u8c61\r\n$imagick->clear();\r\n$imagick->destroy();\r\n?><\/pre>\n
<?php\r\n\/\/ PDF \u6587\u4ef6\u8def\u5f84\r\n$pdf_file = '.\/example.pdf';\r\n \r\n\/\/ \u521b\u5efa Imagick \u5bf9\u8c61\r\n$imagick = new Imagick($pdf_file);\r\n \r\n\/\/ \u8bbe\u7f6e\u5206\u8fa8\u7387\uff08\u53ef\u9009\uff09\r\n$imagick->setResolution(300, 300);\r\n \r\n\/\/ \u8bfb\u53d6 PDF \u6587\u4ef6\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u56fe\u7247\r\n$imagick->readImage($pdf_file);\r\n \r\n \r\n\/\/ \u5c06\u6bcf\u4e00\u9875\u56fe\u7247\u4fdd\u5b58\u4e3a\u6587\u4ef6\r\nforeach ($imagick as $page) {\r\n \/\/ \u8bbe\u7f6e\u8f93\u51fa\u6587\u4ef6\u540d\r\n $output_file = '\/www\/wwwroot\/test.xixishidi.cn\/page'.(array_search($page, iterator_to_array($page))+1).'.png';\r\n \r\n \/\/ \u4fdd\u5b58\u4e3a PNG \u683c\u5f0f\r\n $page->setImageFormat('png');\r\n \r\n \/\/ \u4fdd\u5b58\u4e3a\u6587\u4ef6\r\n $page->writeImage($output_file);\r\n}\r\n \r\n\/\/ \u91ca\u653e Imagick \u5bf9\u8c61\r\n$imagick->clear();\r\n$imagick->destroy();\r\n?><\/pre>\n