跳至页脚内容
使用IRONPDF
如何在 .NET Maui 中查看 PDF 文件

在.NET MAUI中使用IronPDF创建PDF文件

.NET 多平台应用 UI (.NET MAUI) 是一个用于使用 C# 和 XAML 创建原生移动和桌面应用的跨平台框架。 您可以使用 .NET MAUI 在 Android、iOS、macOS 和 Windows 上使用单个代码库进行操作。 .NET MAUI 是开源的,是对 Xamarin Forms 的改进。 UI 控件从头开始重写以提高性能和可扩展性。 此外,它已从移动平台扩展到包括桌面用例。 如果您曾经使用 Xamarin Forms 来创建跨平台用户界面,那么您会发现 .NET MAUI 框架与它有很多共同之处。

但是,也存在一些差异。 您可以使用 .NET MAUI 框架在单个项目中构建多平台应用,但如果需要,可以添加特定平台的代码和资源。 .NET MAUI 的主要目标之一是允许您尽可能多地在单个代码库中编写应用逻辑和 UI 布局。 .NET MAUI 将支持所有平台,并支持现有的 MVVM 和 XAML 模式。

.NET MAUI 允许开发人员在各种平台上工作,如移动开发和 Windows 平台。

IronPDF特性

IronPDF 是一个强大的 PDF 转换器,可以处理几乎任何浏览器可以处理的任务。 为开发人员提供的 .NET 库,使创建、读取和操作 PDF 文件变得简单。 IronPDF 使用 Google Chrome 引擎将 HTML 转换为 PDF 文件。 IronPDF 支持包括 HTML、ASPX、将 Razor 页转换为 PDF 及 MVC 视图在内的其他 Web 技术。 IronPDF 支持 Microsoft .NET 应用程序(包括 ASP.NET Web 应用程序和传统的 Windows 应用程序)。 IronPDF 还可以用来制作吸引人的 PDF 文档。

IronPDF 可以从包含 JavaScript 和 CSS 的 HTML 文件创建 PDF 文件

Not only can convert HTML files to PDF with IronPDF, but you can also convert image files to PDF.

IronPDF can help to create interactive PDF documents, fill out and submit interactive forms with IronPDF, merge and split PDF documents, extract text and images from PDFs from PDF documents, search text in PDF documents, rasterize PDF pages to images, convert PDF to HTML, and print PDF documents using IronPrint.

IronPDF 可以从网址生成文档。 对于 HTML 后面的登录,使用 IronPDF 进行登录表单,它还允许使用自定义网络登录凭据、用户代理、代理、cookie、HTTP 头和表单变量。

IronPDF 是一个可以读取和填写 PDF 文档的库,并能够从文档中提取图像。 It allows us to add headers and footers to PDF files, text, photos, bookmarks for easier navigation, watermarks, and more to documents. 它还允许我们在新文档或现有文档中合并和拆分页面。 IronPDF 可以无需 Acrobat 查看器将文档转换为 PDF 对象。 也可以将 CSS 文件转换为 PDF 文档,CSS 媒体类型文件可以转换为文档。

class="hsg-featured-snippet">

如何在 .NET MAUI 中创建 PDF 文件

  1. 在 Visual Studio 中创建新的 .NET MAUI PDF 项目
  2. 使用 NuGet 安装 IronPDF 库
  3. 设计 .NET MAUI 内容页的 UI
  4. 使用 ChromePdfRenderer.RenderHtmlAsPdf 方法生成 PDF 文件
  5. 使用特定平台代码将 PDF 文件保存到用户设备。

在 Visual Studio 中创建新项目

首先,使用 Visual Studio Code 和 Visual Studio 创建一个项目。 在使用 Visual Studio Code 时,必须使用命令行工具安装项目类型模板。

打开 Microsoft Visual Studio 软件并进入文件菜单。 选择“新项目”,在新项目窗口中选择“.NET MAUI 应用程序”。本文将使用 .NET MAUI 应用程序生成 PDF 文档并将其保存到适当位置。

使用 IronPDF 在 .NET MAUI 中创建 PDF 文件,图 1:在 Visual Studio 中创建新项目 在 Visual Studio 中创建新项目

输入项目名称,并在相应的文本框中选择文件路径。 然后,点击下面截图中的创建按钮。

使用 IronPDF 在 .NET MAUI 中创建 PDF 文件,图 2:配置项目 配置项目

Visual Studio 项目现在将按照 .NET MAUI App 平台生成所选应用程序的结构。 现在它将打开 MainPage.cs 文件以添加代码并构建/运行应用程序。

使用 IronPDF 在 .NET MAUI 中创建 PDF 文件,图 3:将代码添加到 MainPage.cs 文件中 将代码添加到 MainPage.cs 文件中

接下来,安装库以测试代码。

安装IronPDF库

IronPDF库可以通过四种方式下载和安装。

这些是:

  • 使用 Visual Studio。
  • 使用Visual Studio命令行。
  • 从NuGet网站直接下载。
  • 从IronPDF网站直接下载。

使用Visual Studio

Visual Studio软件提供NuGet包管理器选项直接将包安装到解决方案。 下面的截图显示了如何打开NuGet包管理器。

使用 IronPDF 在 .NET MAUI 中创建 PDF 文件,图 4:导航至使用 NuGet 包管理器 UI 导航至 NuGet 包管理器 UI

这提供了一个搜索框,用于从 NuGet 网站显示包列表。在 NuGet 包管理器中,搜索关键字“IronPDF”,如下图所示。

使用 IronPDF 在 .NET MAUI 中创建 PDF 文件,图 5:从 NuGet 包管理器 UI 选择 IronPdf 包 来自 NuGet 包管理器 UI 的 IronPDF 包

如上图所示,列出了相关搜索项,选择第一个选项以将包安装到解决方案中。 它将安装在所有 .NET MAUI 应用平台上,例如 Android、iOS 和 Windows 平台。

使用Visual Studio命令行

在 Visual Studio 中,进入工具 > NuGet 包管理器 > 包管理器控制台

在包管理器控制台标签中输入以下行:

Install-Package IronPdf

现在,包将下载/安装到当前项目的所有 .NET MAUI 平台上,并准备好使用。

使用 IronPDF 在 .NET MAUI 中创建 PDF 文件,图 6:在包管理控制台中安装包 在包管理控制台中安装包

从NuGet网站直接下载

第三种方式是通过访问此IronPDF NuGet 存储库页面直接从他们的网站下载 NuGet 包。

  • 从右手边菜单中选择下载包选项。
  • 双击下载后的包。 它将自动安装。
  • 重新加载解决方案,包应该可以在您的项目中使用。

从IronPDF网站直接下载

直接从他们的网站下载最新的 IronPDF ZIP 包。下载后,按照以下步骤将包添加到您的项目中。

  • 右键单击解决方案窗口中项目的依赖项选项。
  • 选择特定平台,然后选择选项引用并浏览下载的参考资料位置。
  • 单击确定添加引用。

您还需要添加对所有 .NET MAUI 支持平台的引用。

使用 IronPDF 在 .NET MAUI 应用上创建 PDF

创建项目后,会有一个自动生成的文件,名为 MainPage.xaml。 这是放置 .NET MAUI 应用程序 UI 的地方。

请参考以下代码。

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MAUI_PDF.MainPage"
            >

    <ScrollView>
        <VerticalStackLayout
            Spacing="25"
            Padding="30,0"
            VerticalOptions="Center">

            <Image
                Source="dotnet_bot.png"
                SemanticProperties.Description="Cute .NET bot waving hi to you!"
                HeightRequest="200"
                HorizontalOptions="Center" />

            <Label
                Text="Welcome to IronPDF!"
                SemanticProperties.HeadingLevel="Level1"
                FontSize="32"
                HorizontalOptions="Center" />

            <Button
                x:Name="PdfBtn"
                Text="Click me to generate PDF"
                SemanticProperties.Hint="Click button to generate PDF"
                Clicked="GeneratePDF"
                HorizontalOptions="Center" />
        </VerticalStackLayout>
    </ScrollView>

</ContentPage>
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MAUI_PDF.MainPage"
            >

    <ScrollView>
        <VerticalStackLayout
            Spacing="25"
            Padding="30,0"
            VerticalOptions="Center">

            <Image
                Source="dotnet_bot.png"
                SemanticProperties.Description="Cute .NET bot waving hi to you!"
                HeightRequest="200"
                HorizontalOptions="Center" />

            <Label
                Text="Welcome to IronPDF!"
                SemanticProperties.HeadingLevel="Level1"
                FontSize="32"
                HorizontalOptions="Center" />

            <Button
                x:Name="PdfBtn"
                Text="Click me to generate PDF"
                SemanticProperties.Hint="Click button to generate PDF"
                Clicked="GeneratePDF"
                HorizontalOptions="Center" />
        </VerticalStackLayout>
    </ScrollView>

</ContentPage>
XML

一旦将上述代码添加到 MainPage.xaml 文件中,打开 MainPage.xaml.cs 文件,并在 MainPage 类中包含以下方法:

private void GeneratePDF(object sender, EventArgs e)
{
    ChromePdfRenderer renderer = new ChromePdfRenderer();
    var doc = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF!</h1> <p>I'm using IronPDF MAUI!</p>");

    // Saves the memory stream as file.
    SaveService saveService = new SaveService();
    saveService.SaveAndView("IronPDF HTML string.pdf", "application/pdf", doc.Stream);
}
private void GeneratePDF(object sender, EventArgs e)
{
    ChromePdfRenderer renderer = new ChromePdfRenderer();
    var doc = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF!</h1> <p>I'm using IronPDF MAUI!</p>");

    // Saves the memory stream as file.
    SaveService saveService = new SaveService();
    saveService.SaveAndView("IronPDF HTML string.pdf", "application/pdf", doc.Stream);
}
Private Sub GeneratePDF(ByVal sender As Object, ByVal e As EventArgs)
	Dim renderer As New ChromePdfRenderer()
	Dim doc = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF!</h1> <p>I'm using IronPDF MAUI!</p>")

	' Saves the memory stream as file.
	Dim saveService As New SaveService()
	saveService.SaveAndView("IronPDF HTML string.pdf", "application/pdf", doc.Stream)
End Sub
$vbLabelText   $csharpLabel

GeneratePDF 方法生成一个包含文本“Hello, IronPDF!...”的新 PDF 文档,并将其保存在用户计算机上的指定位置。

In the method above, a new ChromePdfRenderer object is created and invokes the RenderHtmlAsPdf method to produce a new PDF document containing the words "Hello IronPDF! ...从一段 HTML 标记中。接下来,将文件保存在用户设备上的任务委派给一个名为 SaveService 的独立类。将在下一步中创建此类。

完整的 MainPage.xaml.cs 文件如下。 请确保文件内容与下面显示的一致,然后再继续进行下一步:

// Change the namespace as desired, but make sure that all source files use this same namespace,
// or there will be errors!
namespace MAUI_IronPDF;    

// This namespace is required to make use of IronPDF functionality
using IronPdf;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void GeneratePDF(object sender, EventArgs e)
    {
        ChromePdfRenderer renderer = new ChromePdfRenderer();
        var doc = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF!</h1> <p>I'm using IronPDF MAUI!</p>");
        // Saves the memory stream as file.
        SaveService saveService = new SaveService();
        saveService.SaveAndView("IronPDF HTML string.pdf", "application/pdf", doc.Stream);
    }
}
// Change the namespace as desired, but make sure that all source files use this same namespace,
// or there will be errors!
namespace MAUI_IronPDF;    

// This namespace is required to make use of IronPDF functionality
using IronPdf;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void GeneratePDF(object sender, EventArgs e)
    {
        ChromePdfRenderer renderer = new ChromePdfRenderer();
        var doc = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF!</h1> <p>I'm using IronPDF MAUI!</p>");
        // Saves the memory stream as file.
        SaveService saveService = new SaveService();
        saveService.SaveAndView("IronPDF HTML string.pdf", "application/pdf", doc.Stream);
    }
}
Imports IronPdf

' Change the namespace as desired, but make sure that all source files use this same namespace,
' or there will be errors!
Namespace MAUI_IronPDF

	' This namespace is required to make use of IronPDF functionality

	Partial Public Class MainPage
		Inherits ContentPage

		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub GeneratePDF(ByVal sender As Object, ByVal e As EventArgs)
			Dim renderer As New ChromePdfRenderer()
			Dim doc = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF!</h1> <p>I'm using IronPDF MAUI!</p>")
			' Saves the memory stream as file.
			Dim saveService As New SaveService()
			saveService.SaveAndView("IronPDF HTML string.pdf", "application/pdf", doc.Stream)
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

现在,在项目的根目录中创建一个名为 SaveService.cs 的新类文件,并添加以下源代码:

// Change the namespace as desired, but make sure that all source files use this same namespace,
// or there will be errors!
namespace MAUI_IronPDF
{
    // SaveService partial class declaration ... this allows a layer of abstraction
    // as we implement the save file details specially for each platform on which this app will
    // operate! 
    public partial class SaveService
    {
        public void SaveAndView(string filename, string contentType, MemoryStream stream)
        {
            SaveFile(filename, contentType, stream);
        }

        // Additional partial files will provide implementations for this method specifically.
        partial void SaveFile(string filename, string contentType, MemoryStream stream);
    }
}
// Change the namespace as desired, but make sure that all source files use this same namespace,
// or there will be errors!
namespace MAUI_IronPDF
{
    // SaveService partial class declaration ... this allows a layer of abstraction
    // as we implement the save file details specially for each platform on which this app will
    // operate! 
    public partial class SaveService
    {
        public void SaveAndView(string filename, string contentType, MemoryStream stream)
        {
            SaveFile(filename, contentType, stream);
        }

        // Additional partial files will provide implementations for this method specifically.
        partial void SaveFile(string filename, string contentType, MemoryStream stream);
    }
}
' Change the namespace as desired, but make sure that all source files use this same namespace,
' or there will be errors!
Namespace MAUI_IronPDF
	' SaveService partial class declaration ... this allows a layer of abstraction
	' as we implement the save file details specially for each platform on which this app will
	' operate! 
	Partial Public Class SaveService
		Public Sub SaveAndView(ByVal filename As String, ByVal contentType As String, ByVal stream As MemoryStream)
			SaveFile(filename, contentType, stream)
		End Sub

		' Additional partial files will provide implementations for this method specifically.
		Partial Private Sub SaveFile(ByVal filename As String, ByVal contentType As String, ByVal stream As MemoryStream)
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

由于在用户设备上保存内容的实现细节因平台(Windows、Android、macOS 等)而异,因此必须针对每种设备类型编写特定平台的代码,而应用程序将支持这些设备类型。 为了实现这一点,我们将 SaveService 定义为一个部分类(用于抽象目的),其中包含一个称为SaveAndView的部分方法。 接下来,此方法的实现将在 Solutions Explorer 中的 Platforms 文件夹中嵌套的一个或多个文件夹中定义在一个单独的 SaveService.cs 部分类中(请参见下图):

使用 IronPDF 在 .NET MAUI 中创建 PDF 文件,图 7:实现跨平台的文件夹结构 实现跨平台的文件夹结构

为了简单起见,本教程将仅为 Windows 平台定义上述部分文件。 在 Windows 平台文件夹下创建一个新的 SaveService.cs 文件,其中包含以下代码:

using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.UI.Popups;

namespace MAUI_IronPDF;

public partial class SaveService
{
    async partial void SaveFile(string filename, string contentType, MemoryStream stream)
    {
        StorageFile stFile;
        string extension = Path.GetExtension(filename);
        // Gets process windows handle to open the dialog in application process.
        IntPtr windowHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
        if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
        {
            // Creates file save picker to save a file.
            FileSavePicker savePicker = new();
            savePicker.DefaultFileExtension = ".pdf";
            savePicker.SuggestedFileName = filename;
            // Saves the file as PDF file.
            savePicker.FileTypeChoices.Add("PDF", new List<string>() { ".pdf" });

            WinRT.Interop.InitializeWithWindow.Initialize(savePicker, windowHandle);
            stFile = await savePicker.PickSaveFileAsync();
        }
        else
        {
            StorageFolder local = ApplicationData.Current.LocalFolder;
            stFile = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
        }
        if (stFile != null)
        {
            using (IRandomAccessStream zipStream = await stFile.OpenAsync(FileAccessMode.ReadWrite))
            {
                // Writes compressed data from memory to file.
                using Stream outstream = zipStream.AsStreamForWrite();
                outstream.SetLength(0);
                // Saves the stream as file.
                byte [] buffer = stream.ToArray();
                outstream.Write(buffer, 0, buffer.Length);
                outstream.Flush();
            }
            // Create message dialog box.
            MessageDialog msgDialog = new("Do you want to view the document?", "File has been created successfully");
            UICommand yesCmd = new("Yes");
            msgDialog.Commands.Add(yesCmd);
            UICommand noCmd = new("No");
            msgDialog.Commands.Add(noCmd);

            WinRT.Interop.InitializeWithWindow.Initialize(msgDialog, windowHandle);

            // Showing a dialog box.
            IUICommand cmd = await msgDialog.ShowAsync();
            if (cmd.Label == yesCmd.Label)
            {
                // Launch the saved file.
                await Windows.System.Launcher.LaunchFileAsync(stFile);
            }
        }
    }
}
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.UI.Popups;

namespace MAUI_IronPDF;

public partial class SaveService
{
    async partial void SaveFile(string filename, string contentType, MemoryStream stream)
    {
        StorageFile stFile;
        string extension = Path.GetExtension(filename);
        // Gets process windows handle to open the dialog in application process.
        IntPtr windowHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
        if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
        {
            // Creates file save picker to save a file.
            FileSavePicker savePicker = new();
            savePicker.DefaultFileExtension = ".pdf";
            savePicker.SuggestedFileName = filename;
            // Saves the file as PDF file.
            savePicker.FileTypeChoices.Add("PDF", new List<string>() { ".pdf" });

            WinRT.Interop.InitializeWithWindow.Initialize(savePicker, windowHandle);
            stFile = await savePicker.PickSaveFileAsync();
        }
        else
        {
            StorageFolder local = ApplicationData.Current.LocalFolder;
            stFile = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
        }
        if (stFile != null)
        {
            using (IRandomAccessStream zipStream = await stFile.OpenAsync(FileAccessMode.ReadWrite))
            {
                // Writes compressed data from memory to file.
                using Stream outstream = zipStream.AsStreamForWrite();
                outstream.SetLength(0);
                // Saves the stream as file.
                byte [] buffer = stream.ToArray();
                outstream.Write(buffer, 0, buffer.Length);
                outstream.Flush();
            }
            // Create message dialog box.
            MessageDialog msgDialog = new("Do you want to view the document?", "File has been created successfully");
            UICommand yesCmd = new("Yes");
            msgDialog.Commands.Add(yesCmd);
            UICommand noCmd = new("No");
            msgDialog.Commands.Add(noCmd);

            WinRT.Interop.InitializeWithWindow.Initialize(msgDialog, windowHandle);

            // Showing a dialog box.
            IUICommand cmd = await msgDialog.ShowAsync();
            if (cmd.Label == yesCmd.Label)
            {
                // Launch the saved file.
                await Windows.System.Launcher.LaunchFileAsync(stFile);
            }
        }
    }
}
Imports Windows.Storage
Imports Windows.Storage.Pickers
Imports Windows.Storage.Streams
Imports Windows.UI.Popups

Namespace MAUI_IronPDF

	Partial Public Class SaveService
		Private Async Sub SaveFile(ByVal filename As String, ByVal contentType As String, ByVal stream As MemoryStream)
			Dim stFile As StorageFile
			Dim extension As String = Path.GetExtension(filename)
			' Gets process windows handle to open the dialog in application process.
			Dim windowHandle As IntPtr = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle
			If Not Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons") Then
				' Creates file save picker to save a file.
				Dim savePicker As New FileSavePicker()
				savePicker.DefaultFileExtension = ".pdf"
				savePicker.SuggestedFileName = filename
				' Saves the file as PDF file.
				savePicker.FileTypeChoices.Add("PDF", New List(Of String)() From {".pdf"})

				WinRT.Interop.InitializeWithWindow.Initialize(savePicker, windowHandle)
				stFile = Await savePicker.PickSaveFileAsync()
			Else
				Dim local As StorageFolder = ApplicationData.Current.LocalFolder
				stFile = Await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting)
			End If
			If stFile IsNot Nothing Then
				Using zipStream As IRandomAccessStream = Await stFile.OpenAsync(FileAccessMode.ReadWrite)
					' Writes compressed data from memory to file.
					Using outstream As Stream = zipStream.AsStreamForWrite()
						outstream.SetLength(0)
						' Saves the stream as file.
						Dim buffer() As Byte = stream.ToArray()
						outstream.Write(buffer, 0, buffer.Length)
						outstream.Flush()
					End Using
				End Using
				' Create message dialog box.
				Dim msgDialog As New MessageDialog("Do you want to view the document?", "File has been created successfully")
				Dim yesCmd As New UICommand("Yes")
				msgDialog.Commands.Add(yesCmd)
				Dim noCmd As New UICommand("No")
				msgDialog.Commands.Add(noCmd)

				WinRT.Interop.InitializeWithWindow.Initialize(msgDialog, windowHandle)

				' Showing a dialog box.
				Dim cmd As IUICommand = Await msgDialog.ShowAsync()
				If cmd.Label = yesCmd.Label Then
					' Launch the saved file.
					Await Windows.System.Launcher.LaunchFileAsync(stFile)
				End If
			End If
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

构建并运行 MAUI 应用程序。 将出现一个窗口,包含如下所示的界面:

使用 IronPDF 在 .NET MAUI 中创建 PDF 文件,图 8:MAUI 应用的 UI MAUI 应用的 UI

点击 "Generate PDF" 按钮。 经过几秒钟,会出现一个弹出窗口以选择生成的 PDF 文件的位置。

使用 IronPDF 在 .NET MAUI 中创建 PDF 文件,图 9:选择位置保存 PDF 文件 选择位置保存 PDF 文件

结论

IronPDF 是最常用的 PDF 转换库之一,允许您生成、读取、编辑和格式化 PDF。 IronPDF 库提供了许多优势和功能,包括一个浏览器引擎,帮助将给定 URL 转换为 PDF 文件,允许您向 HTML 字符串添加 CSS 并将其转换为 PDF 文件,同样可以填写 PDF 表单。 IronPDF 的所有功能都包含在一个库中。

IronPDF 提供多种价格结构。 IronPDF 的基本价格从 $799 开始。 产品支持和更新也可以通过支付一年的费用来获得。 可以通过购买附加组件获取免版税的重新分发覆盖范围。

总之,推荐使用 IronPDF,因为它为使用 PDF 的开发人员提供了出色的性能和大量功能。 它支持 .NET MAUI 等通用平台。 它还提供优秀的支持和文档,允许您充分利用 IronPDF 库的广泛功能及其众多功能。

常见问题解答

如何在 .NET MAUI 应用程序中生成 PDF 文件?

要在 .NET MAUI 应用程序中生成 PDF 文件,可以使用 IronPDF。首先在 Visual Studio 中设置 .NET MAUI 项目,通过 NuGet 安装 IronPDF,并使用 ChromePdfRenderer.RenderHtmlAsPdf 方法将 HTML 内容转换为 PDF 文档。

什么使 .NET MAUI 适合跨平台应用程序开发?

.NET MAUI 是跨平台应用程序开发的理想选择,因为它允许开发人员使用 C# 和 XAML 为 Android、iOS、macOS 和 Windows 创建本地移动和桌面应用程序,从单一代码库出发。

IronPDF 如何在 PDF 转换中处理 HTML、CSS 和 JavaScript?

IronPDF 使用 Google Chrome 引擎准确地以 PDF 格式呈现 HTML、CSS 和 JavaScript,确保在转换网页时不会丢失格式。

在 .NET MAUI 应用程序中,如何在不同平台上保存 PDF 文件?

在使用 IronPDF 的 .NET MAUI 应用程序中,使用 SaveService 类来保存 PDF 文件。它包括特定于平台的实现来处理 Windows 和 Android 等操作系统上的文件保存。

IronPDF for .NET 应用程序中有哪些高级功能可用?

IronPDF 提供高级功能,如创建交互式 PDF、填写和提交表单、合并和拆分文档、提取文本和图像以及添加页眉、页脚和水印。

如何在 Visual Studio 中将 IronPDF 集成到 .NET MAUI 项目中?

要将 IronPDF 集成到 .NET MAUI 项目中,请使用 Visual Studio 中的 NuGet 包管理器。搜索 'IronPDF' 并安装到您的项目中以开始生成和管理 PDF。

IronPDF 能否在 .NET MAUI 应用程序中将网页 URL 转换为 PDF?

是的,IronPDF 可以通过其网页渲染功能将网页 URL 转换为 PDF,准确捕获 HTML、CSS 和 JavaScript 内容并以 PDF 格式呈现。

XAML 在设计 .NET MAUI 应用程序的用户界面中的作用是什么?

XAML 在 .NET MAUI 中用于设计应用程序的用户界面。它允许开发人员创建响应式且视觉上吸引人的布局,这些布局能够无缝地在多个平台上工作。

在 .NET MAUI 项目中使用 IronPDF 的好处是什么?

IronPDF 提供易于使用、大量文档、性能和处理各种 PDF 任务的能力,成为开发人员处理 .NET MAUI 项目中的 PDF 时的可靠选择。

IronPDF 是否完全兼容 .NET 10?兼容 .NET 10 能带来哪些优势?

是的,IronPDF 完全兼容 .NET 10,并开箱即用地支持 .NET 9、8、7、6、Core、Standard 和 Framework 版本。将 IronPDF 与 .NET 10 结合使用,您可以充分利用性能改进,例如减少堆分配、改进 JIT/运行时行为以及新的 C# 语言特性,从而使 PDF 的生成和处理更加快速高效。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。