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.

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

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失