2012-03-08 154 views
0

我正在写一个VB.Net应用程序。我需要能够将Word或PDF文件转换为TIF格式。将PDF转换为TIFF格式

免费会很好,但我也会接受低成本。

我想示例代码如果可能的话,VB是首选的,但我也知道C#

回答

0

你可以用Atalasoft DotImage(commerial产品做到这一点 - 必须的声明:我Atalasoft工作,并写了很多的PDF代码):

// this code extracts images from the PDF - there may be multiple images per page 
public void PdfToTiff(Stream pdf, Stream tiff) 
{ 
    TiffEncoder encoder = new TiffEncoder(tiff); 

    PdfImageSource images = new PdfImageSource(pdf); 

    encoder.Save(tiff, images, null); 
} 

// this code renders each page 
public void PdfToTiff(string pathToPdf, Stream tiff) 
{ 
    TiffEncoder encoder = new TiffEncoder(tiff); 

    FileSystemImageSource images = new FileSystemImageSource(pathToPdf, true); 

    encoder.Save(tiff, images, null); 
} 

后面的例子可能是你想要的。它在一条路径上工作,因为FileSystemImageSource利用代码在带有通配符的文件系统上运行。真的,这对于这项任务来说太过分了。如果你想这样做没有你会有这样的:

public void PdfToTiff(Stream pdf, Stream tiff) 
{ 
    TiffEncoder encoder = new TiffEncoder(); 
    encoder.Append = true; 

    PdfDecoder decoder = new PdfDecoder(); 
    int pageCount = decoder.GetFrameCount(pdf); 
    for (int i=0; i < pageCount; i++) { 
     using (AtalaImage image = decoder.Read(pdf, i, null)) { 
      encoder.Save(tiff, image, null); 
     } 
    } 
} 
1

这是非常简单的imagemagick(你也必须下载ghostscript)。你只需要使用VB来运行它作为一个过程。

Dim imgmgk As New Process() 

    With imgmgk.StartInfo 
     .FileName = v_locationOfImageMagickConvert.exe 
     .UseShellExecute = False 
     .CreateNoWindow = True 
     .RedirectStandardOutput = True 
     .RedirectStandardError = True 
     .RedirectStandardInput = False 
     .Arguments = " -units PixelsPerInch " & v_pdf_filename & " -depth 16 -flatten +matte –monochrome –density 288 -compress ZIP " & v_tiff_filename 

    End With 

    imgmgk.Start() 

    Dim output As String = imgmgk.StandardOutput.ReadToEnd() 
    Dim errorMsg As String = imgmgk.StandardError.ReadToEnd() 
    imgmgk.WaitForExit() 
    imgmgk.Close() 

参数是多种多样的 - 使用imagemagick文档来查看它们是什么。你可以做一些简单的事情,只需传递pdf文件名和tiff文件名即可进行简单的转换。