关于图片:将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,它可以处理无限页面


推荐阅读

    linux脚本命令教学?

    linux脚本命令教学?,标准,数据,系统,脚本,代码,流程,官网,底部,命令,变量,lin

    linux复制命令文件?

    linux复制命令文件?,系统,文件,命令,目录,基本知识,源文件,目标,文件夹,路

    linux下文件均分命令?

    linux下文件均分命令?,管理,情况,系统,工作,信息,地址,命令,目录,单位,设备,L

    脚本linux上运行命令?

    脚本linux上运行命令?,工具,代码,时间,密码,系统,环境,名字,位置,第三,下来,t

    linux查文件数量命令?

    linux查文件数量命令?,系统,数据,电脑,命令,文件,信息,代码,对比,软件,第三,l

    linux修改脚本的命令?

    linux修改脚本的命令?,系统,密码,服务,工作,工具,环境,信息,百度,代码,脚本,

    linux命令去重文件?

    linux命令去重文件?,系统,工作,命令,信息,数据,环境,代码,文件,目录,操作,Lin

    linux脚本命令单引号?

    linux脚本命令单引号?,系统,工作,美元,地址,命令,信息,情况,标准,管理,引号,l

    linux匹配文件名命令?

    linux匹配文件名命令?,系统,时间,发行,位置,工具,软件,名称,盘后,电脑,盘中,l

    改文件名linux命令?

    改文件名linux命令?,名字,软件,文件,命令,位置,系统,文件名,目录,指令,方面,l

    linux运行脚本的命令?

    linux运行脚本的命令?,系统,工具,代码,服务,脚本,状态,密码,环境,位置,暂停,l

    linux命令文件加锁?

    linux命令文件加锁?,数据,密码,系统,设备,代码,地址,名单,信息,数字,统一,请

    linux命令下载工具?

    linux命令下载工具?,工具,网络,代理,代码,简介,位置,系统,第一,下载工具,文

    linux拼接文件命令?

    linux拼接文件命令?,文件,数据,命令,代码,时间,信息,系统,情况,管理,标准,Lin

    linux文件常用命令?

    linux文件常用命令?,工作,地址,信息,系统,命令,目录,标准,情况,管理,常用命

    文件写入linux命令?

    文件写入linux命令?,文件,命令,状态,系统,名称,时间,首次,数据,数字,内容,在l

    linux命令写满文件?

    linux命令写满文件?,地址,工作,命令,系统,管理,文件,目录,标准,电脑,信息,Lin

    文件夹排序linux命令?

    文件夹排序linux命令?,系统,数字,信息,工作,时间,命令,管理,设备,单位,工具,

    linux打开文件夹命令?

    linux打开文件夹命令?,工作,系统,信息,命令,图片,文件,管理,发行,名字,名称,