当前位置:首页> 正文

关于图片:将pdf文件转换为tiff文件的最佳方法

关于图片:将pdf文件转换为tiff文件的最佳方法

Best way to convert pdf files to tiff files

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


使用Imagemagick或更好的Ghostscript。

http://www.ibm.com/developerworks/library/l-graf2/#N101C2提供了imagemagick的示例:

1
convert foo.pdf pages-%03d.tiff

http://www.asmail.be/msg0055376363.html包含一个ghostscript示例:

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

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


从命令行使用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脚本来转换任意数量的文件...


我写了一些powershell脚本来浏览目录结构,并使用ghostscript将所有pdf文件转换为tiff文件。这是我的脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$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
    }
}

1)安装GhostScript

2)安装ImageMagick

3)创建"转换为TIFF.bat"(Windows XP,Vista,7)并使用以下行:

1
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。


使用python这就是我最终得到的

1
2
3
4
5
6
7
8
9
10
11
    import os
    os.popen(' '.join([
                       self._ghostscriptPath + 'gswin32c.exe',
                       '-q',
                       '-dNOPAUSE',
                       '-dBATCH',
                       '-r300',
                       '-sDEVICE=tiff12nc',
                       '-sPAPERSIZE=a4',
                       '-sOutputFile=%s %s' % (tifDest, pdfSource),
                       ]))

PDF Focus .Net可以通过以下方式实现:

1. PDF到TIFF

1
2
3
4
5
6
7
8
9
10
11
12
13
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转换为多页TIFF

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Convert PDF file to Multipage TIFF file

SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

string pdfPath = @"c:\Document.pdf";
string tiffPath = @"c:
esult.tiff";

f.OpenPdf(pdfPath);

if (f.PageCount > 0)
{
    f.ToMultipageTiff(tiffPath, 120) == 0)
    {
        System.Diagnostics.Process.Start(tiffPath);
    }
}


所需的ghostscript和tiffcp
在Ubuntu中测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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')

ABCPDF也可以这样做-请访问http://www.websupergoo.com/helppdf6net/default.html


也许也试试这个? PDF焦点

.Net库使您可以解决问题:)

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    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();
    }

免责声明:适用于我推荐的产品

Atalasoft有一个.NET库,可以将PDF转换为TIFF -我们是FOXIT的合作伙伴,因此PDF呈现效果非常好。


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

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


pdf2tiff怎么样? http://python.net/~gherman/pdf2tiff.html


我喜欢PDFTIFF.com将PDF转换为TIFF,它可以处理无限页面


展开全文阅读

相关内容