【问题标题】:Best way to convert pdf files to tiff files [closed]将 pdf 文件转换为 tiff 文件的最佳方法 [关闭]
【发布时间】:2010-09-09 16:24:18
【问题描述】:

我有大约 1000 个 pdf 文件,我需要将它们转换为 300 dpi 的 tiff 文件。做这个的最好方式是什么?如果有可以编写脚本的 SDK 或其他东西或工具,那将是理想的。

【问题讨论】:

  • 这是我使用的解决方案:[Pdf to Tiff using Xpdf's pdftoppm and LibTIFF's ppm2tiff and tiffcp (optional, only if multipage)][1] [1]: stackoverflow.com/a/12868254/551460
  • 任何带有完整源代码示例的最终解决方案?也许使用 powershell 脚本..
  • @Kiquenet 我发布了一个使用 powershell 的解决方案。请看下面...
  • 使用 Ghrostscript 作为gs -q -dNOPAUSE -r300x300 -sDEVICE=tiff24nc -sOutputFile=output.tif input.pdf -c quit(在 Windows 上的命令是 gswin32c)生成 300x300 dpi 和 24 位彩色图像
  • 将 PDF 文件转换为 TIFF 文件的最佳方法?确定:使用pdftoppm,如下:mkdir images && pdftoppm -tiff -r 300 mypdf.pdf images/pg。有关详细信息、用法和更多信息,请参见此处:askubuntu.com/questions/150100/…

标签: pdf image tiff


【解决方案1】:

使用 python 这就是我最终的结果

import os
os.popen(' '.join([
                   self._ghostscriptPath + 'gswin32c.exe', 
                   '-q',
                   '-dNOPAUSE',
                   '-dBATCH',
                   '-r300',
                   '-sDEVICE=tiff12nc',
                   '-sPAPERSIZE=a4',
                   '-sOutputFile=%s %s' % (tifDest, pdfSource),
                   ]))

【讨论】:

  • 一般情况下,您会希望为此使用子流程。 os.popen 被认为已弃用。语法几乎相同。
【解决方案2】:

https://pypi.org/project/pdf2tiff/

您还可以使用 pdf2ps、ps2image,然后使用其他实用程序将生成的图像转换为 tiff(我记得 'paul' [paul - 另一种图像查看器(显示 PNG、TIFF、GIF、JPG 等])

【讨论】:

    【解决方案3】:

    使用 Imagemagick,或者更好的 Ghostscript。

    http://www.ibm.com/developerworks/library/l-graf2/#N101C2 有一个 imagemagick 的例子:

    convert foo.pdf pages-%03d.tiff
    

    http://www.asmail.be/msg0055376363.html 有一个 ghostscript 的例子:

    gs -q -dNOPAUSE -sDEVICE=tiffg4 -sOutputFile=a.tif foo.pdf -c quit
    

    我会安装 ghostscript 并阅读 gs 的手册页以查看需要哪些确切选项并进行实验。

    【讨论】:

    • ghostscript 工作得非常好,据我了解 imagemagick 正在重用 ghostscript 进行 pdf 操作。这是正确的吗?
    • 这是我听到的,但我不是 ImageMagick 内部的专家;)
    • imagemagick 能正确处理多页 pdf --> tiff 吗?
    • 哇,ghostscript 真的需要清理它的命令行界面了!
    • imagemagick 在没有配置的情况下运行良好。我无法正确配置 ghostscript 以获得高分辨率彩色图像。
    【解决方案4】:

    PDF Focus .Net 可以这样做:

    1. PDF 转 TIFF

    SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();    
    
    string pdfPath = @"c:\My.pdf";
    
    string imageFolder = @"c:\images\";
    
    f.OpenPdf(pdfPath);
    
    if (f.PageCount > 0)
    {
        //Save all PDF pages to image folder as tiff images, 200 dpi
        int result = f.ToImage(imageFolder, "page",System.Drawing.Imaging.ImageFormat.Tiff, 200);
    }
    

    2. PDF to Multipage-TIFF

    //Convert PDF file to Multipage TIFF file
    
    SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
    
    string pdfPath = @"c:\Document.pdf";
    string tiffPath = @"c:\Result.tiff";
    
    f.OpenPdf(pdfPath);
    
    if (f.PageCount > 0)
    {
        f.ToMultipageTiff(tiffPath, 120) == 0)
        {
            System.Diagnostics.Process.Start(tiffPath);
        }
    }   
    

    【讨论】:

      【解决方案5】:

      也许也试试这个? PDF Focus

      这个 .Net 库可以让您解决问题 :)

      此代码将有所帮助(在 C# 中将 1000 个 PDF 文件转换为 300-dpi TIFF 文件):

          SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
      
          string[] pdfFiles = Directory.GetFiles(@"d:\Folder with 1000 pdfs\", "*.pdf");
          string folderWithTiffs = @"d:\Folder with TIFFs\";
      
          foreach (string pdffile in pdfFiles)
          {
              f.OpenPdf(pdffile);
      
              if (f.PageCount > 0)
              {
                  //save all pages to tiff files with 300 dpi
                  f.ToImage(folderWithTiffs, Path.GetFileNameWithoutExtension(pdffile), System.Drawing.Imaging.ImageFormat.Tiff, 300);
              }
              f.ClosePdf();
          }
      

      【讨论】:

        【解决方案6】:

        必需的 ghostscript 和 tiffcp 在 Ubuntu 中测试

        import os
        
        def pdf2tiff(source, destination):
            idx = destination.rindex('.')
            destination = destination[:idx]
            args = [
            '-q', '-dNOPAUSE', '-dBATCH',
            '-sDEVICE=tiffg4',
            '-r600', '-sPAPERSIZE=a4',
            '-sOutputFile=' + destination + '__%03d.tiff'
            ]
            gs_cmd = 'gs ' + ' '.join(args) +' '+ source
            os.system(gs_cmd)
            args = [destination + '__*.tiff', destination + '.tiff' ]
            tiffcp_cmd = 'tiffcp  ' + ' '.join(args)
            os.system(tiffcp_cmd)
            args = [destination + '__*.tiff']
            rm_cmd = 'rm  ' + ' '.join(args)
            os.system(rm_cmd)    
        pdf2tiff('abc.pdf', 'abc.tiff')
        

        【讨论】:

          【解决方案7】:

          1) 安装 GhostScript

          2) 安装 ImageMagick

          3) 创建“Convert-to-TIFF.bat”(Windows XP、Vista、7)并使用以下行:

          for %%f in (%*) DO "C:\Program Files\ImageMagick-6.6.4-Q16\convert.exe" -density 300 -compress lzw %%f %%f.tiff
          

          将任意数量的单页 PDF 文件拖到此文件上,会将它们转换为 300 DPI 的压缩 TIFF。

          【讨论】:

          • GhostScript 是必需的吗?如果我只安装 ImageMagick ?
          • 这非常有效。非常感谢。
          • 我们如何将颜色更改为灰度或任何其他类似颜色?它还在保存时重复文件名。我在 Windows 10 上使用它
          【解决方案8】:

          我编写了一个小 powershell 脚本来遍历目录结构并使用 ghostscript 将所有 pdf 文件转换为 tiff 文件。这是我的脚本:

          $tool = 'C:\Program Files\gs\gs8.63\bin\gswin32c.exe'
          $pdfs = get-childitem . -recurse | where {$_.Extension -match "pdf"}
          
          foreach($pdf in $pdfs)
          {
          
              $tiff = $pdf.FullName.split('.')[0] + '.tiff'
              if(test-path $tiff)
              {
                  "tiff file already exists " + $tiff
              }
              else        
              {   
                  'Processing ' + $pdf.Name        
                  $param = "-sOutputFile=$tiff"
                  & $tool -q -dNOPAUSE -sDEVICE=tiffg4 $param -r300 $pdf.FullName -c quit
              }
          }
          

          【讨论】:

          • 7 年后,这仍然很有帮助!我只会添加一个没有 PowerShell 经验的人,您需要: 1. 编辑 $tool 值以匹配系统上的路径和版本。 2. 打开 PowerShell 并 cd 到存储 PDF 的目录。 3. 将代码粘贴到 PowerShell 窗口中。我需要按几次 Enter 才能运行它。谢谢 gyurisc
          【解决方案9】:

          我喜欢PDFTIFF.com到convert PDF to TIFF,它可以处理无限的页面

          【讨论】:

            【解决方案10】:

            免责声明:为我推荐的产品工作

            Atalasoft 有一个.NET 库,可以convert PDF to TIFF -- 我们是FOXIT 的合作伙伴,所以PDF 渲染非常好。

            【讨论】:

              【解决方案11】:

              从命令行使用 GhostScript,我过去使用过以下内容:

              在 Windows 上:

              gswin32c -dNOPAUSE -q -g300x300 -sDEVICE=tiffg4 -dBATCH -sOutputFile=output_file_name.tif input_file_name.pdf

              在 *nix 上:

              gs -dNOPAUSE -q -g300x300 -sDEVICE=tiffg4 -dBATCH -sOutputFile=output_file_name.tif input_file_name.pdf

              对于大量文件,可以使用简单的批处理/shell 脚本来转换任意数量的文件...

              【讨论】:

              • +1。有用的命令。但是我的彩色图形以黑白输出。知道为什么吗?
              • -sDEVICE=tiffg4 是黑白传真压缩模型。见:pages.cs.wisc.edu/~ghost/doc/AFPL/8.00/Devices.htm#TIFF
              • 大多数时候,您希望将 pdf 转换为 300x300 dpi,而不是 300x300 大小的 TIFF 图像。为此,将-g开关替换为-rgswin32c -dNOPAUSE -q -r300x300 ...
              • 谢谢@HairyFotr。对于其他访问者,您应该使用 -sDEVICE=tiff24nc 用于 24 位 RGB,或使用 -sDEVICE=tiff12nc 用于 12 位(每个通道分别为 8/4 位)。
              【解决方案12】:

              ABCPDF 也可以这样做——查看http://www.websupergoo.com/helppdf6net/default.html

              【讨论】:

                【解决方案13】:

                【讨论】:

                • 这还不能处理多页 tiff,所以不幸的是,这不适合我。不过感谢您的建议。
                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2011-04-03
                • 2011-08-29
                • 2011-03-31
                • 2012-08-03
                • 2020-11-16
                • 2017-08-22
                相关资源
                最近更新 更多