使用IRONPDF 如何在.NET MAUI中顯示嵌入文字的PDF Curtis Chau 更新日期:6月 22, 2025 Download IronPDF NuGet 下載 DLL 下載 Windows 安裝程式 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article This is a tutorial that will walk you through showing PDF-embedded text in .NET MAUI using IronPDF. .NET Multi-platform App UI (MAUI) simplifies multi-platform app development. With the new and improved version of Xamarin.Forms, developers can create apps for Android, iOS, macOS, and Windows with a single project. PDF files, known for preserving fonts, images, and layout, are commonly managed using this technology. The IronPDF library offers powerful PDF handling capabilities in this context. Developers can leverage the power of IronPDF to work with embedded text effortlessly, simplifying the process of generating and manipulating PDF files while adhering to default settings for consistent rendering. Understanding PDF Embedded Text and Font Embedding PDF-embedded text, or PDF fonts, are text entities embedded in a PDF file. It is crucial when it comes to consistency and accurate rendering across PDF viewer applications, including popular applications like Adobe InDesign. By embedding fonts within the PDF document, the correct fonts are preserved, regardless of the type of PDF viewer application used, or whether the specific font is installed on the viewer's device. Embedding fonts can sometimes increase the size of the PDF document, but it is crucial to maintain the original document's look and feel. The Adobe PDF settings often determine if the fonts in a PDF are embedded or not. There are different kinds of embedded fonts in a PDF document: Embedded fonts: The entire font is embedded in the document. Subset embedded fonts: Only a subset of the fonts used in the original document is embedded. No embedded fonts: No fonts are embedded in the document. In Adobe Acrobat, you can verify whether fonts are embedded by checking the document properties. By default, fonts are embedded in a PDF file. However, these settings can be changed using Adobe Acrobat Pro or other similar tools. The term 'flattened PDF' is often used in the context of PDF documents where all fonts have been embedded, making the file self-contained and ensuring it appears the same across all systems and PDF viewers. IronPDF C# IronPDF Documentation is a powerful C# PDF library that allows developers to generate, read, and edit PDF files in .NET applications. You can learn to generate PDF files from HTML with IronPDF. An interesting feature of IronPDF is the ability to work with embedded text in PDF files. The ability to embed fonts in a PDF file is crucial for preserving the document's original appearance, even when the PDF file is viewed or printed on a system that does not have access to the original fonts used in the document. Let's understand how to display embedded text in a PDF using IronPDF in .NET MAUI. Prerequisites Before starting with the tutorial, make sure you have the following requirements fulfilled: .NET MAUI: Microsoft's unified UI toolkit that allows you to create apps for Android, iOS, macOS, and Windows with a single shared codebase. You can download the .NET MAUI from the Microsoft website. Visual Studio 2022 (or later): A powerful and user-friendly Integrated Development Environment (IDE) for .NET programming. You can download Visual Studio from the Microsoft website. Ensure you have the .NET MAUI workloads installed on Visual Studio 2022. IronPDF library: This is a PDF processing library for .NET, and we will use it to interact with the PDF files. You can install IronPDF via NuGet, which is a package manager for the Microsoft development platform. An Adobe PDF file: For the sake of this tutorial, we will need a PDF file. Create a .NET MAUI App Follow these steps to create a new .NET MAUI App: Launch Visual Studio 2022: After launching, navigate to File > New > Project. In the project template window, select .NET MAUI App and then click on Next. Create a .NET MAUI App in Visual Studio Name your project: In the next window, you'll need to give your project a name. Let's name it IronPDF_Read_and_View. Choose a location to save your project and then click Next. Configure the project Select Framework: Select .NET Framework from the drop-down list. Select the latest .NET Framework for a smooth process and click the "Create" button. .NET Framework selection Install IronPDF After creating the .NET MAUI App, the next step is to install the IronPDF library. Here's how you can do that: Open the NuGet Package Manager: Navigate to Tools > NuGet Package Manager > Manage NuGet Packages for Solution. Navigate to NuGet Package Manager Search for IronPDF: In the opened window, click on Browse and type IronPdf in the search box. Search for IronPDF in NuGet Package Manager UI Install IronPDF: Once you see IronPDF in the search results, click on it. Make sure that the checkbox for your project in the right panel is checked and then click on Install. Accept any prompts for permissions or terms of usage that appear during the installation process. You can also install IronPDF using the NuGet Package Manager Console by using the following command: Install-Package IronPdf Building the User Interface Now let's go ahead and build the user interface (UI) for this application. The MainPage.xaml file will serve as the landing page. It will have a button to open the PDF file, and labels to show the selected file's name and its content. Let's proceed with creating the user interface: Open the MainPage.xaml file: This file contains the layout of the main page. You can find this file under the Pages folder in the Solution Explorer. Define the Layout: We are going to use a <ScrollView> control which allows the user to scroll through the contents of the page when it cannot fit entirely on the screen. Inside the ScrollView, we will use a <StackLayout> for stacking our controls vertically. Inside the StackLayout, we have three <Frame> controls. Each Frame is used to hold a distinct section of our page, providing a neat and organized appearance. Add Controls: The first Frame has a <VerticalStackLayout> which holds a Label and a Button. The Label displays the application name, and the Button allows the user to open a PDF file. The Clicked attribute is assigned the method OpenAndReadFile which will be defined later in the code-behind file. <VerticalStackLayout Spacing="25" Padding="30,0" VerticalOptions="Center"> <Label Text="IronPDF MAUI Application" SemanticProperties.HeadingLevel="Level1" SemanticProperties.Description="IronPDF MAUI Application" FontSize="30" HorizontalOptions="Center" FontAttributes="Bold" /> <Button x:Name="openFileBtn" Text="Open PDF File" SemanticProperties.Hint="Open PDF File" Clicked="OpenAndReadFile" HorizontalOptions="Center" /> </VerticalStackLayout> <VerticalStackLayout Spacing="25" Padding="30,0" VerticalOptions="Center"> <Label Text="IronPDF MAUI Application" SemanticProperties.HeadingLevel="Level1" SemanticProperties.Description="IronPDF MAUI Application" FontSize="30" HorizontalOptions="Center" FontAttributes="Bold" /> <Button x:Name="openFileBtn" Text="Open PDF File" SemanticProperties.Hint="Open PDF File" Clicked="OpenAndReadFile" HorizontalOptions="Center" /> </VerticalStackLayout> XML The second Frame has a <HorizontalStackLayout> which holds two Labels. The first Label is for displaying the static text "Selected File Name:", and the second Label named fileName displays the name of the selected file. <HorizontalStackLayout Spacing="25" Padding="30,0" VerticalOptions="Center"> <Label Text="Selected File Name: " SemanticProperties.HeadingLevel="Level2" SemanticProperties.Description="Selected File Name" FontSize="18" HorizontalOptions="Center" FontAttributes="Bold" /> <Label x:Name="fileName" Text="" SemanticProperties.HeadingLevel="Level3" SemanticProperties.Description="Selected File Name" FontSize="18" HorizontalOptions="Center" /> </HorizontalStackLayout> <HorizontalStackLayout Spacing="25" Padding="30,0" VerticalOptions="Center"> <Label Text="Selected File Name: " SemanticProperties.HeadingLevel="Level2" SemanticProperties.Description="Selected File Name" FontSize="18" HorizontalOptions="Center" FontAttributes="Bold" /> <Label x:Name="fileName" Text="" SemanticProperties.HeadingLevel="Level3" SemanticProperties.Description="Selected File Name" FontSize="18" HorizontalOptions="Center" /> </HorizontalStackLayout> XML The third Frame has a <VerticalStackLayout> which holds two Labels. The first Label displays the static text "PDF Content", and the second Label named content displays the content of the PDF file. <VerticalStackLayout> <Label Text="PDF Content" SemanticProperties.HeadingLevel="Level2" FontSize="25" FontAttributes="Bold" HorizontalOptions="Center" /> <Label x:Name="content" FontSize="18" HorizontalTextAlignment="Start" /> </VerticalStackLayout> <VerticalStackLayout> <Label Text="PDF Content" SemanticProperties.HeadingLevel="Level2" FontSize="25" FontAttributes="Bold" HorizontalOptions="Center" /> <Label x:Name="content" FontSize="18" HorizontalTextAlignment="Start" /> </VerticalStackLayout> XML Your final MainPage.xaml should look something like this: <?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="IronPDF_Read_and_View.MainPage"> <ScrollView> <StackLayout> <Frame> <VerticalStackLayout Spacing="25" Padding="30,0" VerticalOptions="Center"> <Label Text="IronPDF MAUI Application" SemanticProperties.HeadingLevel="Level1" SemanticProperties.Description="IronPDF MAUI Application" FontSize="30" HorizontalOptions="Center" FontAttributes="Bold" /> <Button x:Name="openFileBtn" Text="Open PDF File" SemanticProperties.Hint="Open PDF File" Clicked="OpenAndReadFile" HorizontalOptions="Center" /> </VerticalStackLayout> </Frame> <Frame> <HorizontalStackLayout Spacing="25" Padding="30,0" VerticalOptions="Center"> <Label Text="Selected File Name: " SemanticProperties.HeadingLevel="Level2" SemanticProperties.Description="Selected File Name" FontSize="18" HorizontalOptions="Center" FontAttributes="Bold" /> <Label x:Name="fileName" Text="" SemanticProperties.HeadingLevel="Level3" SemanticProperties.Description="Selected File Name" FontSize="18" HorizontalOptions="Center" /> </HorizontalStackLayout> </Frame> <Frame> <VerticalStackLayout> <Label Text="PDF Content" SemanticProperties.HeadingLevel="Level2" FontSize="25" FontAttributes="Bold" HorizontalOptions="Center" /> <Label x:Name="content" FontSize="18" HorizontalTextAlignment="Start" /> </VerticalStackLayout> </Frame> </StackLayout> </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="IronPDF_Read_and_View.MainPage"> <ScrollView> <StackLayout> <Frame> <VerticalStackLayout Spacing="25" Padding="30,0" VerticalOptions="Center"> <Label Text="IronPDF MAUI Application" SemanticProperties.HeadingLevel="Level1" SemanticProperties.Description="IronPDF MAUI Application" FontSize="30" HorizontalOptions="Center" FontAttributes="Bold" /> <Button x:Name="openFileBtn" Text="Open PDF File" SemanticProperties.Hint="Open PDF File" Clicked="OpenAndReadFile" HorizontalOptions="Center" /> </VerticalStackLayout> </Frame> <Frame> <HorizontalStackLayout Spacing="25" Padding="30,0" VerticalOptions="Center"> <Label Text="Selected File Name: " SemanticProperties.HeadingLevel="Level2" SemanticProperties.Description="Selected File Name" FontSize="18" HorizontalOptions="Center" FontAttributes="Bold" /> <Label x:Name="fileName" Text="" SemanticProperties.HeadingLevel="Level3" SemanticProperties.Description="Selected File Name" FontSize="18" HorizontalOptions="Center" /> </HorizontalStackLayout> </Frame> <Frame> <VerticalStackLayout> <Label Text="PDF Content" SemanticProperties.HeadingLevel="Level2" FontSize="25" FontAttributes="Bold" HorizontalOptions="Center" /> <Label x:Name="content" FontSize="18" HorizontalTextAlignment="Start" /> </VerticalStackLayout> </Frame> </StackLayout> </ScrollView> </ContentPage> XML When users press the "Open PDF File" button, it will trigger the OpenAndReadFile method. This method will be defined in our MainPage.xaml.cs (code-behind) file. Our labels, fileName, and content, will show the file name of the selected PDF file and the content of the PDF file respectively. The Code Behind MainPage.xaml.cs The logic of the application resides in the MainPage.xaml.cs file, also known as the code-behind file. Here, we define the OpenAndReadFile method which is responsible for opening the file picker, allowing the user to select a PDF file, extracting the content of the selected PDF file, and displaying it on the UI. Open MainPage.xaml.cs: Find this file in the Solution Explorer under the Pages folder. This is where we'll add our method. Add the filePath field: At the top of the MainPage class, declare a string field named filePath. We will use this field to store the path of the selected file. string filePath = string.Empty; string filePath = string.Empty; IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel Initialize Components: In the MainPage constructor, call the InitializeComponent method. This method is called automatically to initialize the page and its controls. public MainPage() { InitializeComponent(); } public MainPage() { InitializeComponent(); } IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel Implement the OpenAndReadFile method: This method is marked as async because we're going to use the await keyword inside it. The FilePicker.PickAsync method is used to open the file picker. When the user selects a file, the file name is stored in the fileName label, and the file path in the filePath field. The IronPDF library is used to open the PDF document and extract all text from it. The extracted text is then assigned to the content label. private async void OpenAndReadFile(object sender, EventArgs e) { FileResult result = await FilePicker.PickAsync(); fileName.Text = result.FileName; filePath = result.FullPath; IronPdf.License.LicenseKey = "Your-License-Key"; // Read PDF File var document = PdfDocument.FromFile(filePath); var pdfContent = document.ExtractAllText(); content.Text = pdfContent; } private async void OpenAndReadFile(object sender, EventArgs e) { FileResult result = await FilePicker.PickAsync(); fileName.Text = result.FileName; filePath = result.FullPath; IronPdf.License.LicenseKey = "Your-License-Key"; // Read PDF File var document = PdfDocument.FromFile(filePath); var pdfContent = document.ExtractAllText(); content.Text = pdfContent; } Private Async Sub OpenAndReadFile(ByVal sender As Object, ByVal e As EventArgs) Dim result As FileResult = Await FilePicker.PickAsync() fileName.Text = result.FileName filePath = result.FullPath IronPdf.License.LicenseKey = "Your-License-Key" ' Read PDF File Dim document = PdfDocument.FromFile(filePath) Dim pdfContent = document.ExtractAllText() content.Text = pdfContent End Sub $vbLabelText $csharpLabel The OpenAndReadFile method is now complete. It will be triggered when the user clicks on the Open PDF File button. You need to replace "Your-License-Key" with your actual IronPDF license key. Here is the complete code: using IronPdf; public partial class MainPage : ContentPage { string filePath = string.Empty; public MainPage() { InitializeComponent(); } private async void OpenAndReadFile(object sender, EventArgs e) { FileResult result = await FilePicker.PickAsync(); fileName.Text = result.FileName; filePath = result.FullPath; IronPdf.License.LicenseKey = "Your-License-Key"; // Read PDF File var document = PdfDocument.FromFile(filePath); var pdfContent = document.ExtractAllText(); content.Text = pdfContent; } } using IronPdf; public partial class MainPage : ContentPage { string filePath = string.Empty; public MainPage() { InitializeComponent(); } private async void OpenAndReadFile(object sender, EventArgs e) { FileResult result = await FilePicker.PickAsync(); fileName.Text = result.FileName; filePath = result.FullPath; IronPdf.License.LicenseKey = "Your-License-Key"; // Read PDF File var document = PdfDocument.FromFile(filePath); var pdfContent = document.ExtractAllText(); content.Text = pdfContent; } } Imports IronPdf Partial Public Class MainPage Inherits ContentPage Private filePath As String = String.Empty Public Sub New() InitializeComponent() End Sub Private Async Sub OpenAndReadFile(ByVal sender As Object, ByVal e As EventArgs) Dim result As FileResult = Await FilePicker.PickAsync() fileName.Text = result.FileName filePath = result.FullPath IronPdf.License.LicenseKey = "Your-License-Key" ' Read PDF File Dim document = PdfDocument.FromFile(filePath) Dim pdfContent = document.ExtractAllText() content.Text = pdfContent End Sub End Class $vbLabelText $csharpLabel Running the Application Now that we have successfully set up the UI and defined the behavior of the application, it's time to see our application in action! Start the Application: To run the application, you can either press F5 on your keyboard or click on the green 'Start Debugging' button in the toolbar at the top of Visual Studio. Ensure that the right target device or emulator is selected in the dropdown menu next to the 'Start Debugging' button. Use the Application: Once the application launches, you will see a screen with the title "IronPDF MAUI Application" and a button labeled "Open PDF File". The UI of the IronPDF MAUI Application Open a PDF File: Click on the "Open PDF File" button. This will open a file picker, allowing you to browse and select a PDF file from your device or emulator. File Selection Dialog View the Content: Upon selecting a PDF file, the file name will be displayed under "Selected File Name:", and the content of the selected PDF file will be displayed under "PDF Content". Display PDF content from selected PDF file Please note that if the selected PDF file is very large, it might take a few seconds to extract and display the text. Also, remember that the format of the extracted text may not match exactly with the original layout of the PDF file, as the ExtractAllText method details extract the embedded text content. Conclusion This tutorial demonstrated how to build a .NET MAUI application using the IronPDF library to extract and display the text content from a PDF file. This project is a great example of how powerful and versatile .NET MAUI and the IronPDF library are when working with PDF files in your applications. In addition to extracting texts and images in PDF files, the IronPDF library also supports a wide range of functionalities including interacting with PDF forms, dividing PDF files, rasterizing PDF pages to images, authentication behind HTML login forms, customizing headers and footers in PDF documents as well as supporting CSS files for pixel-perfect PDF files. IronPDF is a commercial product with robust functionality for PDF manipulation, and it offers a free trial of IronPDF for you to test out its capabilities. If you find the product beneficial for your development needs and decide to use it for production, license plans start from $799. 常見問題解答 如何在.NET MAUI應用程式中顯示PDF嵌入文字? 若要在 .NET MAUI 應用程式中顯示 PDF 嵌入文本,可以使用 IronPDF 庫。 IronPDF 讓您可以從 PDF 檔案中提取文字並在應用程式中呈現。您需要在 .NET MAUI 中設定使用者介面,以便使用者選擇和顯示 PDF 內容。 為什麼在 PDF 文件中嵌入字體很重要? 在 PDF 文件中嵌入字體非常重要,因為它可以確保文件在不同的系統和 PDF 檢視器中的外觀保持一致,無論使用者的裝置上是否安裝了字型。 如何在.NET MAUI專案中安裝IronPDF? 若要在 .NET MAUI 專案中安裝 IronPDF,請使用 Visual Studio 的 NuGet 套件管理器。搜尋 IronPDF 並將其安裝到您的專案中。或者,您可以使用 NuGet 套件管理器控制台,並執行以下命令: Install-Package IronPdf 。 在.NET MAUI應用程式中使用IronPDF有哪些好處? IronPDF 為 .NET MAUI 應用程式提供了許多優勢,包括提取和渲染 PDF 文字、管理嵌入式字體以及確保跨平台的高品質 PDF 渲染。它還提供了一套強大的 PDF 處理功能,並支援跨平台開發。 IronPDF 能否從任何 PDF 文件中提取文字? 是的,IronPDF 可以從 PDF 文件中提取文字。但是,提取的文字格式可能與原始 PDF 佈局略有不同,具體取決於 PDF 的建立方式。 設定 .NET MAUI 應用程式來處理 PDF 檔案需要哪些步驟? 要配置一個用於處理 PDF 的 .NET MAUI 應用程序,需要安裝 .NET MAUI 和 Visual Studio 以及必要的工作負載,透過 NuGet 整合 IronPDF 庫,並開發一個與 PDF 文件互動的使用者介面。該過程還包括編寫 C# 程式碼來提取和顯示 PDF 內容。 IronPDF是否有免費版本可供開發使用? IronPDF 提供免費試用版,方便開發者測試其各項功能。對於生產環境應用,我們提供多種授權方案,以滿足不同需求。 IronPDF 可以實現哪些類型的 PDF 操作? 使用 IronPDF,您可以執行各種 PDF 操作,包括文字擷取、與 PDF 表單互動、分割 PDF、將 PDF 頁面轉換為圖像以及自訂文件頁首和頁尾。 IronPDF 是否支援 .NET 10?我能否將其與 .NET 10 MAUI 專案一起使用? 是的-IronPDF 完全相容 .NET 10。它支援 .NET 10 MAUI 項目,無需任何自訂變通方案即可立即利用 .NET 10 的效能改進和語言特性。 IronPDF 同時支援 .NET 9、8、7、6、5、Core、Standard 和 Framework 版本,以及 .NET 10。 (ironpdf.com) 在資源有限的裝置(例如 iOS 或 Android)上使用 MAUI 中的 IronPDF 的 ExtractAllText 功能處理大型 PDF 時,是否有任何限製或已知問題? IronPDF 的ExtractAllText雖然能很好地處理標準 PDF 文件,但在行動裝置上從超大型文件中提取嵌入文字時速度會變慢,並且會佔用大量記憶體。開發者應考慮對大型文件實現分頁或分塊提取,並確保設備有足夠的記憶體。此外,為了確保 UI 的回應速度,可能需要在背景執行緒中使用,以避免阻塞 MAUI 應用的主執行緒。 (以上內容基於 .NET MAUI 的一般最佳實務以及 IronPDF 對 PDF 擷取的處理方式。) Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 相關文章 發表日期 11月 13, 2025 如何在 C# 中合併兩個 PDF 位元組數組 使用 IronPDF 在 C# 中合併兩個 PDF 位元組數組。學習如何透過簡單的程式碼範例,將來自位元組數組、記憶體流和資料庫的多個 PDF 文件合併在一起。 閱讀更多 發表日期 11月 13, 2025 如何在 ASP.NET MVC 中創建 PDF 檢視器 為 ASP.NET MVC 應用程式構建一個強大的 PDF 檢視器。顯示 PDF 文件,將視圖轉換為 PDF,使用 IronPDF 添加互動功能。 閱讀更多 發表日期 11月 13, 2025 如何建立 .NET HTML 轉 PDF 轉換器 學習如何在.NET中使用IronPDF將HTML轉換為PDF。 閱讀更多 如何在 ASP.NET Core 中顯示 PDF 文件如何在C#中將PDF轉換為PNG
發表日期 11月 13, 2025 如何在 C# 中合併兩個 PDF 位元組數組 使用 IronPDF 在 C# 中合併兩個 PDF 位元組數組。學習如何透過簡單的程式碼範例,將來自位元組數組、記憶體流和資料庫的多個 PDF 文件合併在一起。 閱讀更多
發表日期 11月 13, 2025 如何在 ASP.NET MVC 中創建 PDF 檢視器 為 ASP.NET MVC 應用程式構建一個強大的 PDF 檢視器。顯示 PDF 文件,將視圖轉換為 PDF,使用 IronPDF 添加互動功能。 閱讀更多