【发布时间】:2017-05-27 04:57:57
【问题描述】:
我有一本书叫php_5_for_dummies.pdf。
它的总页数是 5。
我想在不同的 div 中显示每个 PDF 页面内容。
示例:应该这样显示:
<div class='1'>Content of pdf page 1 </div><div class='2'>Content of pdf page 2 </div><div class='3'>Content of pdf page 3 </div><div class='4'>Content of pdf page 4 </div><div class='5'>Content of pdf page 5 </div>
到目前为止,我已经完成了。
function pdf_page_no($filepath){
$fp = @fopen(preg_replace("/\[(.*?)\]/i", "",$filepath),"r");
$max=0;
while(!feof($fp)) {
$line = fgets($fp,255);
if (preg_match('/\/Count [0-9]+/', $line, $matches)){
preg_match('/[0-9]+/',$matches[0], $matches2);
if ($max<$matches2[0]) $max=$matches2[0];
}
}
fclose($fp);
if($max==0){
$im = new imagick($filepath);
$max=$im->getNumberImages();
}
return $max;
}
$filename = "php_5_for_dummies.pdf";
$total_page_no = pdf_page_no($filename);
for ( $i=0 ; $i >= $total_page_no; $i++ ) {
echo "<div class='{$i}'>";
// here should display the content from page 1 of pdf
echo "</div>";
}
【问题讨论】:
-
到目前为止你做了什么?
-
我只能提取页码。来自pdf
-
你试过的代码可以分享吗?
-
到目前为止我已经添加了我的代码。
-
不!我只能显示页面编号和循环页面而不是内容