将 PDF 转换为 TIFF 格式

问题描述 投票:0回答:4

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

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

如果可能的话,我想要示例代码,VB 更好,但我也知道 c#

vb.net pdf tiff
4个回答
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 文件名即可进行简单转换。


0
投票

您可以使用 Atalasoft DotImage(商业产品 - 强制性免责声明:我在 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);
        }
    }
}

0
投票

我发现有很多产品可以做到这一点。有些需要付费,有些则免费。

我使用黑冰http://www.blackice.com/Printer%20Drivers/Tiff%20Printer%20Drivers.htm。这个价格大约是 40 美元,比较实惠。不过我没买这个。

我最终使用了一款名为 MyMorph 的免费软件。


0
投票

您可以使用 Aspose.Pdf dotnet 包。这是示例代码:

public byte[] ConvertPdfToTiff(byte[] sourcePdfDoc)
{
    var license = new Aspose.Pdf.License();
    license.SetLicense("Aspose.Pdf.lic");

    // Load PDF with an instance of Document                        
    var document = new Aspose.Pdf.Document(new MemoryStream(sourcePdfDoc));

    // Create an object of tiffDevice
    var renderer = new Aspose.Pdf.Devices.TiffDevice();

    // Convert a particular page and save the image in TIFF format
    using (var m = new MemoryStream())
    {
        renderer.Process(document, m);
        m.Position = 0;
        return m.ToArray();
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.