dpiz9879 2016-10-06 16:47
浏览 119
已采纳

FPDI输出文件大小

I am using FPDF and FPDI to extract 2 pages from a pdf document that is generally about 28 pages long. The pdf files are basically a page with an image filling each page entirely and are around 35-40mb.

When using FPDI to extract the last 2 pages from the full document and create a new file, the file size of the new 2 page file remains almost the same. Any ideas why this might be?

Here is the basic code used to do the extracting:

public function extractPagesFromFile($file, $outputFileName, $numPages = 2) {
  $pageCount = $this->_fpdf->setSourceFile($file);
  if ($numPages < 0 || $numPages > $pageCount) {
    return false;
  }
  for ($pageNo = $pageCount - $numPages + 1; $pageNo < $pageCount + 1; $pageNo++) {
    $tplIdx = $this->_fpdf->ImportPage($pageNo);
    if (!isset($s)) {
      $s = $this->_fpdf->getTemplatesize($tplIdx);
    }
    $this->_fpdf->AddPage($s['w'] > $s['h'] ? 'L' : 'P', array($s['w'], $s['h']));
    $this->_fpdf->useTemplate($tplIdx);
  }

  $this->_fpdf->Output('F', $outputFileName);
  $this->_fpdf->cleanUp();
}
  • 写回答

1条回答 默认 最新

  • dongwei8729 2016-10-06 19:07
    关注

    FPDI copies all resources of a page. I guess that all images in your file are located in a single resource dictionary. Because of this all of them will be copied. This is a common issue when extracting pages from existing PDF documents. Without parsing and interpreting the pages content stream it is impossible to know which resources should be copied or not. There's no solution with/for FPDI atm.

    Anyhow we (Setasign) offer other non-free PHP components, such as the SetaPDF-Merger, that work on a lower level and for which we'd build a demo that fixes this behaviour.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!