我需要在我們的cgi之一中調用Ghostscript來將PDF文件轉換爲PNG圖像。此CGI具有在請求中的經編碼的流的PDF然後對其進行解碼,像如何使用CGI請求到Ghostscript
my $PDF_ENCODED = $q->param('PDF_ENCODED'); my $PDF_DECODED = decode_base64($PDF_ENCODED);
,它會通過調用「GS」命令產生在盤上一個PNG圖像。
我的問題是我不知道如何管$ PDF_DECODED到gs命令行。我試過
system("$PDF_DECODED | gs -dNOPAUSE -q -r300 -sDEVICE=png16m -dBATCH -sOutputFile=/tmp/ghostscript/new-test.png-")
但它不工作。
謝謝。
再次感謝golimar和simbabque。 它正在與
$SIG{PIPE} = 'IGNORE'; open(FH, "| gs -dNOPAUSE -q -r300 -sDEVICE=png16m -dBATCH -sOutputFile=/tmp/ghostscript/new-test.png -") or die "can't fork: $!"; print FH "$PDF_DECODED\n" or die "can't write: $!"; close FH or die "can't close: status=$?";
存在一個Ghostscript庫的API:http://p3rl.org/GSAPI,這個比'gs'二進制文件更加高效,並且有點小錯誤。 – daxim
感謝Ghostscript庫,稍後會進行檢查。 – user200340