将 PDF 转换为 TIFF

Aspose.PDF for Android via Java 使得可以将 PDF 页面转换为 TIFF 图像。

TiffDevice 类 允许您将 PDF 页面转换为 TIFF 图像。此类提供了名为 Process 的方法,允许您将 PDF 文件中的所有页面转换为单个 TIFF 图像。

将 PDF 页面转换为单个 TIFF 图像

Aspose.PDF for Android via Java 解释如何将 PDF 文件中的所有页面转换为单个 TIFF 图像:

  1. 创建 Document 类的对象。
  2. 调用 Process 方法来转换文档。
  3. 要设置输出文件的属性,请使用 TiffSettings 类。

以下代码片段展示了如何将所有 PDF 页面转换为单个 TIFF 图像。

public void convertPDFtoTiffSinglePage() {
        // Open document
        try {
            document = new Document(inputStream);
        } catch (Exception e) {
            resultMessage.setText(e.getMessage());
            return;
        }

        // Create Resolution object
        Resolution resolution = new Resolution(300);

        // Create TiffSettings object
        TiffSettings tiffSettings = new TiffSettings();
        tiffSettings.setCompression(CompressionType.None);
        tiffSettings.setDepth(ColorDepth.Default);
        tiffSettings.setShape(ShapeType.Landscape);

        // Create TIFF device
        TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
        File file = new File(fileStorage, "PDF-to-TIFF.tiff");
        try {
            // Convert a particular page and save the image to stream
            tiffDevice.process(document, 1, 1, file.toString());
        }
        catch (Exception e) {
            resultMessage.setText(e.getMessage());
        }
    }

将单页转换为 TIFF 图像

Aspose.PDF for Android via Java 允许将 PDF 文件中的特定页面转换为 TIFF 图像,使用接受页码作为参数的 Process(..) 方法的重载版本进行转换。以下代码片段展示了如何将 PDF 的第一页转换为 TIFF 格式。

public void convertPDFtoTiffAllPages() {
        // Open document
        try {
            document = new Document(inputStream);
        } catch (Exception e) {
            resultMessage.setText(e.getMessage());
            return;
        }


        // Create Resolution object
        Resolution resolution = new Resolution(300);

        // Create TiffSettings object
        TiffSettings tiffSettings = new TiffSettings();
        tiffSettings.setCompression(CompressionType.None);
        tiffSettings.setDepth(ColorDepth.Default);
        tiffSettings.setShape(ShapeType.Landscape);
        tiffSettings.setSkipBlankPages(false);

        // Create TIFF device
        TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
        File file = new File(fileStorage, "AllPagesToTIFF_out.tif");
        try {
            // Convert a particular page and save the image to stream
            tiffDevice.process(document, file.toString());
        }
        catch (Exception e) {
            resultMessage.setText(e.getMessage());
        }
    }

在转换过程中使用 Bradley 算法

Aspose.PDF for Android via Java 已支持将 PDF 转换为使用 LZW 压缩的 TIFF,并且通过使用 AForge 可以进行二值化。然而有客户要求对某些图像使用 Otsu 获取阈值,因此他们也希望使用 Bradley。

public void convertPDFtoTiffBradleyBinarization() {
        //Not implemented in Aspose.PDF for Android
        throw new NotImplementedException();
    }

    public static void convertPDFtoTIFF_Pixelated() {

        //Not implemented in Aspose.PDF for Android
        throw new NotImplementedException();
    }