Trình chuyển đổi HTML cho .NET
Giới thiệu về HTML Converter for .NET
HTML Converter for .NET là một plugin mạnh mẽ cho phép các nhà phát triển để chuyển đổi tài liệu PDF sang các trang HTML. Hướng dẫn này cung cấp một cái nhìn tổng quan về các tính năng có sẵn và giải thích làm thế nào để thực hiện các nhiệm vụ phổ biến bằng cách sử dụng ví dụ mã trong .Net.
Cài đặt HTML Converter
Để bắt đầu với HTML Converter cho .NET, bạn cần cài đặt gói Aspose.Pdf NuGet. Bạn có thể làm điều này bằng cách chạy lệnh sau đây trong Console Quản lý gói NuT:
Install-Package Aspose.PDF
Thay vào đó, bạn có thể tải về DLL và thêm nó như một tham chiếu cho dự án của bạn.
Chuyển đổi PDF sang HTML
Chuyển đổi tài liệu PDF sang HTML là một trong những tính năng chính của HTML Converter. PdfHtml
lớp để tải tài liệu PDF và sau đó lưu nó như một tệp HTML.
// Specify the input and output paths for the PDF document.
var inputPath = Path.Combine(@"C:\Samples\", "sample.pdf");
var outputPath = Path.Combine(@"C:\Samples\", "sample.html");
// Create a new instance of the PdfHtml class.
var plugin = new PdfHtml();
// Create a new instance of the PdfToHtmlOptions class.
var options = new PdfToHtmlOptions(PdfToHtmlOptions.SaveDataType.FileWithEmbeddedResources);
// Add the input and output paths to the PdfToHtmlOptions.
options.AddInput(new FileDataSource(inputPath));
options.AddOutput(new FileDataSource(outputPath));
// Process the PDF to HTML conversion and get the result container.
var resultContainer = plugin.Process(options);
// Get the result from the result container.
var result = resultContainer.ResultCollection[0];
// Print the result to the console.
Console.WriteLine(result);