简体   繁体   English

每个操作系统MPDF不同的文件大小

[英]MPDF different file sizes per operating system

I am using mPDF and Ghostscript as a part of a larger application, where the is workflow is as this: 我将mPDF和Ghostscript用作大型应用程序的一部分,其中is工作流是这样的:

  1. A PDF is uploaded by a 3rd party software PDF是由第三方软件上传的
  2. The file is detected and converted to PDF 1.4 (via a GhostScript wrapper: https://github.com/xthiago/pdf-version-converter ) 检测到该文件并将其转换为PDF 1.4(通过GhostScript包装器: https : //github.com/xthiago/pdf-version-converter
  3. Based on the converted file a new PDF file is generated 根据转换后的文件生成一个新的PDF文件

In local env (MacOS), because the files uploaded are version 1.6, the converted file has more or less half the size of the original and the same goes for the new created one, but in production server (Ubuntu), even if the converted one has the same size as its local equivalent, the new one has 10x times more size: (eg 48MB vs 480MB) 在本地环境(MacOS)中,由于上载的文件是1.6版,因此转换后的文件大小几乎是原始文件的一半,新创建的文件大小也是如此,但是在生产服务器(Ubuntu)中,即使转换后的文件也是如此一个具有与本地相同的大小,而新的则具有10倍的大小:(例如48MB与480MB)

What might be the case for such difference? 这种差异可能是什么情况?

The code used is as this: 使用的代码如下:

$mPdf = new \Mpdf\Mpdf(array(
'dpi' => 300
));

$mPdf -> SetImportUse();
$pageCount = $mPdf -> SetSourceFile($productFileToCopy);

for ($i = 1; $i <= $pageCount; $i++) {
   $importPage = $mPdf -> ImportPage($i);
   $wh = $mPdf -> getTemplateSize($importPage);
   $orientation = $wh['w'] > $wh['h'] ? 'L' : 'P';
   $mPdf -> AddPageByArray(array(
     'orientation' => $orientation,
     'sheet-size' => array(
       $orientation === 'L' ? $wh['h'] : $wh['w'],
       $orientation === 'L' ? $wh['w'] : $wh['h'],
      ),
      'margin-left' => 0,
      'margin-right' => 0,
      'margin-top' => 0,
      'margin-bottom' => 0,
      'margin-header' => 0,
      'margin-footer' => 0,
    ));

    $mPdf -> UseTemplate($importPage);
 }

 $mPdf -> Output($productFileFinal);

Finally it's not mPDF, but Ghostscript. 最后,它不是mPDF,而是Ghostscript。

Slightly different version (9.22 vs 9.23) produces 10x bigger files under this command 稍有不同的版本(9.22与9.23)在此命令下产生的文件大10倍

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE  -dBATCH -dColorConversionStrategy=/LeaveColorUnchanged -dEncodeColorImages=false -dEncodeGrayImages=false -dEncodeMonoImages=false -dDownsampleMonoImages=false -dDownsampleGrayImages=false -dDownsampleColorImages=false -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM