-1

我使用 php 和 ghostscript 将 pdf 转换为图像并显示

<?php
if(empty($_GET['page'])) die;
$numPage=$_GET['page'];
header('Content-type:image/jpeg');
system("gs ".
"-dNOPAUSE ".
"-sDEVICE=jpeg ".
"-dFirstPage={$numPage} ".
"-dLastPage={$numPage} ".
"-sOutputFile=%stdout ".
"-dJPEGQ=90 ".
"-r100x100 ".
"-q file.pdf ".
"-c quit");
?>

谢谢你的回答

4

1 回答 1

0
  1. 使用passthru而不是system
    根据PHP 手册 This function[passthru()] should be used in place of exec() or system() when the output from the Unix command is binary data which needs to be passed directly back to the browser.

  2. 更改%stdout-
    gs 手册页

    You can also send output to stdout for piping with the switch

            -sOutputFile=-
    

下面的代码应该修复它。

<?php

if(empty($_GET['page'])) die;

$numPage=$_GET['page'];

header('Content-type:image/jpeg');

passthru("gs ".
"-dNOPAUSE ".
"-sDEVICE=jpeg ".
"-dFirstPage={$numPage} ".
"-dLastPage={$numPage} ".
"-sOutputFile=- ".
"-dJPEGQ=90 ".
"-r100x100 ".
"-q file.pdf ".
"-c quit");

?>
于 2013-02-02T16:41:00.603 回答