MHT Python 的文件查看器

在浏览器中查看 MHT 文档,无需使用 Adobe Acrobat 或 Python 自动化。

如何使用 Python for .NET 库查看 MHT 个文件

为了查看 MHT 文件,我们将使用 Aspose.PDF for .NET API,这是一款适用于 python-net 平台的功能丰富、强大且易于使用的文档处理 API。打开 NuGet 软件包管理器,搜索 Aspose.pdf 然后安装。你也可以使用软件包管理器控制台中的以下命令。

Python Package Manager Console

pip install aspose-pdf

通过 Python 查看 MHT 个文件


你需要 Aspose.PDF for .NET 才能在你的环境中试用代码。

1.在 MHT 中加载一个文档实例。 1.查看生成的文件。

Python-查看 MHT 文件的示例代码。

<% viewer-files.code-block.subtitle %>

    MhtLoadOptions options= new MhtLoadOptions();
    Resolution resolution = new Resolution(300);
    BmpDevice imageDevice = new BmpDevice(resolution);
    Document pdfDocument= new Document(_dataDir + "test.mhtm", options);
    for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
    {
        using (FileStream imageStream =
        new FileStream($"{_dataDir}image{pageCount}_out.{ext}", FileMode.Create))
        {
            // Convert a particular page and save the image to stream
            imageDevice.Process(pdfDocument.Pages[pageCount], imageStream);

            // Close stream
            imageStream.Close();
        }
    }