HTML C# 查看器

在瀏覽器中查看 HTML 文檔,而無需 Adobe 雜技演員或使用 C# 實現自動化。

如何使用 .NET 庫查看 HTML 文件

為了查看 HTML 文件,我們將使用 [Aspose.PDF for .NET](https://products.aspose.com/pdf/net) API,這是一個功能豐富、功能強大且易於使用的文檔操作 API,適用於 net 平臺。打開 [NuGet](https://www.nuget.org/packages/aspose.pdf) 包管理器,搜索“.PDF”並安裝。您也可以從程式包管理器主控台使用以下命令。

Package Manager Console

PM > Install-Package Aspose.PDF

通過 C# 查看 HTML 文件


您需要使用 [Aspose.PDF for .NET](https://releases.aspose.com/pdf/net) 來嘗試環境中的代碼。

  1. 使用文件實例載入 HTML 。
  2. 查看生成的檔案。

C# - 用於查看 HTML 文件的示例代碼。

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

    HtmlLoadOptions options= new HtmlLoadOptions();
    Resolution resolution = new Resolution(300);
    BmpDevice imageDevice = new BmpDevice(resolution);
    Document pdfDocument= new Document(_dataDir + "test.html", 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();
        }
    }