跳過到頁腳內容
.NET幫助

.NET MAUI Blazor for (PDF,EXCEL,OCR,BARCODE,QR Code)

.NET 多平台應用程式 UI (.NET MAUI) 包括 BlazorWebView 控制項,允許開發人員在 Visual Studio 中將 MAUI Blazor 伺服器應用程式整合到 .NET MAUI 專案中。 這些 Blazor 混合應用程式稱為 .NET MAUI Blazor 應用程式,使混合應用程式得以與平台特定功能整合,並呈現網頁 UI(使用者界面)控制項。 這些 .NET MAUI Blazor 應用程式是跨平台的,因為 .NET MAUI 是一個跨平台框架,不需要平台特定代碼。 我們可以在 Android 設備/Android 模擬器、iOS、macOS、Mac Catalyst 和 Windows 作業系統上使用 .NET MAUI 應用程式。

BlazorWebView 控制項可以添加到 .NET MAUI 原生應用程式的任何頁面,並指向 MAUI Blazor 網頁應用程式的根目錄。 .NET MAUI Blazor 網頁應用程式的 Razor 組件將在 .NET 進程中本地運行,並通過嵌入式網頁視圖控制項呈現網頁 UI 組件。 MAUI Blazor 混合應用程式、桌面應用程式或 Windows 窗體可以在 .NET MAUI 支持的所有不同平台上使用,包括瀏覽器沙盒。

IronPDF: A .NET PDF Library

class="content-img-align-center"> .NET MAUI Blazor for (PDF,EXCEL,OCR,BARCODE,QR Code) - Figure 1: IronPDF

class="content__image-caption">IronPDF

作为 C# 开发人员,您知道拥有适合工作的工具的重要性。 這就是 IronPDF 的用武之地。 強大的 .NET 類庫使開發 PDF 處理應用程式變得容易,通過跨平台 API 使用 .NET Core 和 .NET 技術。IronPDF 使用 .NET Chromium 引擎將 HTML 頁面(以代碼或 URL 形式)轉換為 PDF 文件,消除了對複雜 API 和手動設計工作的需求。 它支持標準網頁文檔,如 HTML、ASPX、JS、CSS 和圖像。

兼容 Blazor 和 .NET MAUI

IronPDF 可以輕鬆集成到使用 Blazor 組件和 .NET MAUI 框架構建的應用程序中,為開發人員提供了一系列用於創建和操縱 PDF 文檔的功能。 這些功能包括從 HTML、XML 和其他文件格式生成 PDF 的能力,以及通過添加或修改文本、圖像和其他 .NET MAUI 工作負載元素來編輯現有 PDF 的能力。

创建 .NET MAUI Blazor 应用的步骤

按照以下步骤在 Visual Studio 中创建 .NET MAUI 应用。

步骤 1:打开 Visual Studio

打开最新版本的 Visual Studio 并启用开发者模式。 建议使用最新版本的 Visual Studio。

步骤 2:搜索 .NET Blazor

现在点击创建新项目按钮并搜索 .NET MAUI Blazor 模板。 从搜索结果中选择“.NET MAUI Blazor App”并点击下一步按钮。

class="content-img-align-center"> .NET MAUI Blazor for (PDF,EXCEL,OCR,BARCODE,QR Code) - Figure 2: Search .NET MAUI Blazor App

class="content__image-caption">Creating a Visual Studio .NET MAUI Application

步骤 3:设置项目名称

为项目给出适当的名称并点击下一步按钮。

步骤 4:.NET 框架

选择 .NET 目标框架。 推荐最新框架以实现流畅的工作。 选择框架后,点击创建按钮。

通过遵循上述步骤,将创建 .NET MAUI Blazor 应用程序。

class="content-img-align-center"> .NET MAUI Blazor for (PDF,EXCEL,OCR,BARCODE,QR Code) - Figure 3: Search .NET MAUI Blazor App

class="content__image-caption">Creating a Visual Studio .NET MAUI Application

让我们看看如何使用这个根 Blazor 组件项目为 IronPDF。

导出 Blazor 内容为 PDF

我们可以很容易地使用以下代码将 Blazor 内容转换为 PDF。

首先打开 Index.razor 文件,并将代码替换为以下代码:

@page "/"
<!-- Input to take HTML content and button to trigger PDF generation -->
<input @bind="InputValue" placeholder="Enter HTML content" />
<button @onclick="SubmitHTML">Render HTML</button>

@code {
    // Property to bind input value
    private string InputValue { get; set; }

    // Async method to render HTML as PDF and save
    private async Task SubmitHTML()
    {
        // Create an instance of ChromePdfRenderer
        var renderer = new IronPdf.ChromePdfRenderer();

        // Render the HTML input value as a PDF document
        var doc = renderer.RenderHtmlAsPdf(InputValue);

        // Save the document as 'Test.pdf' on the local file system
        doc.SaveAs("Test.pdf");
    }
}
@page "/"
<!-- Input to take HTML content and button to trigger PDF generation -->
<input @bind="InputValue" placeholder="Enter HTML content" />
<button @onclick="SubmitHTML">Render HTML</button>

@code {
    // Property to bind input value
    private string InputValue { get; set; }

    // Async method to render HTML as PDF and save
    private async Task SubmitHTML()
    {
        // Create an instance of ChromePdfRenderer
        var renderer = new IronPdf.ChromePdfRenderer();

        // Render the HTML input value as a PDF document
        var doc = renderer.RenderHtmlAsPdf(InputValue);

        // Save the document as 'Test.pdf' on the local file system
        doc.SaveAs("Test.pdf");
    }
}
'INSTANT VB TODO TASK: The following line could not be converted:
page "/" <!-- Input [to] take HTML content [and] button [to] trigger PDF generation -- > <input bind="InputValue" placeholder="Enter HTML content" /> <button onclick="SubmitHTML"> Render HTML</button> code
If True Then
	' Property to bind input value
	private String InputValue {get;set;}

	' Async method to render HTML as PDF and save
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
'	private async Task SubmitHTML()
'	{
'		' Create an instance of ChromePdfRenderer
'		var renderer = New IronPdf.ChromePdfRenderer();
'
'		' Render the HTML input value as a PDF document
'		var doc = renderer.RenderHtmlAsPdf(InputValue);
'
'		' Save the document as 'Test.pdf' on the local file system
'		doc.SaveAs("Test.pdf");
'	}
End If
$vbLabelText   $csharpLabel

此代码有助于将生成的 PDF 文件下载到本地机器。这样我们就可以使用 IronPDF 而不需要任何外部库将 Blazor 内容转换为 PDF 文件。

class="content-img-align-center"> .NET MAUI Blazor for (PDF,EXCEL,OCR,BARCODE,QR Code) - Figure 4: Blazor Content to PDF

class="content__image-caption">Generating a PDF using .NET MAUI Blazor

我们将在文本框中输入以下 HTML:

<!DOCTYPE html>
<html>
  <head>
    <link href='https://fonts.googleapis.com/css2?family=Popin&display=swap' rel='stylesheet'>
    <style>
      /* Add CSS styles for the invoice here */
      body{
        font-family: 'Popin', cursive;
      }
      .invoice {
        width: 80%;
        margin: 0 auto;
        border: 1px solid #ccc;
        padding: 20px;
        background-color: #f5f5f5;
        color: #333;
      }
      .invoice h1 {
        text-align: center;
      }
      .invoice .invoice-info {
        display: flex;
        justify-content: space-between;
        margin-bottom: 20px;
      }
      .invoice .invoice-info div {
        width: 45%;
      }
      .invoice table {
        width: 100%;
        border-collapse: collapse;
      }
      .invoice table th, .invoice table td {
        border: 1px solid #ccc;
        padding: 10px;
      }
      .invoice table th {
        text-align: left;
        background-color: #f5f5f5;
      }
      .invoice table td {
        text-align: right;
      }
      .invoice table td.total {
        font-weight: bold;
      }
    </style>
  </head>
  <body>
    <div class="invoice">
      <h1>Invoice</h1>
      <div class="invoice-info">
        <div>
          <p><strong>From:</strong></p>
          <p>Your Company Name</p>
          <p>123 Main St</p>
          <p>City, State ZIP</p>
        </div>
        <div>
          <p><strong>To:</strong></p>
          <p>Customer Name</p>
          <p>456 Park Ave</p>
          <p>City, State ZIP</p>
        </div>
      </div>
      <table>
        <thead>
          <tr>
            <th>Product</th>
            <th>Quantity</th>
            <th>Price</th>
            <th>Total</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Product 1</td>
            <td>1</td>
            <td>$10.00</td>
            <td>$10.00</td>
          </tr>
          <tr>
            <td>Product 2</td>
            <td>2</td>
            <td>$5.00</td>
            <td>$10.00</td>
          </tr>
          <tr>
            <td colspan="3" class="total">Total:</td>
            <td class="total">$20.00</td>
          </tr>
        </tbody>
      </table>
    </div>
  </body>
</html>
<!DOCTYPE html>
<html>
  <head>
    <link href='https://fonts.googleapis.com/css2?family=Popin&display=swap' rel='stylesheet'>
    <style>
      /* Add CSS styles for the invoice here */
      body{
        font-family: 'Popin', cursive;
      }
      .invoice {
        width: 80%;
        margin: 0 auto;
        border: 1px solid #ccc;
        padding: 20px;
        background-color: #f5f5f5;
        color: #333;
      }
      .invoice h1 {
        text-align: center;
      }
      .invoice .invoice-info {
        display: flex;
        justify-content: space-between;
        margin-bottom: 20px;
      }
      .invoice .invoice-info div {
        width: 45%;
      }
      .invoice table {
        width: 100%;
        border-collapse: collapse;
      }
      .invoice table th, .invoice table td {
        border: 1px solid #ccc;
        padding: 10px;
      }
      .invoice table th {
        text-align: left;
        background-color: #f5f5f5;
      }
      .invoice table td {
        text-align: right;
      }
      .invoice table td.total {
        font-weight: bold;
      }
    </style>
  </head>
  <body>
    <div class="invoice">
      <h1>Invoice</h1>
      <div class="invoice-info">
        <div>
          <p><strong>From:</strong></p>
          <p>Your Company Name</p>
          <p>123 Main St</p>
          <p>City, State ZIP</p>
        </div>
        <div>
          <p><strong>To:</strong></p>
          <p>Customer Name</p>
          <p>456 Park Ave</p>
          <p>City, State ZIP</p>
        </div>
      </div>
      <table>
        <thead>
          <tr>
            <th>Product</th>
            <th>Quantity</th>
            <th>Price</th>
            <th>Total</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Product 1</td>
            <td>1</td>
            <td>$10.00</td>
            <td>$10.00</td>
          </tr>
          <tr>
            <td>Product 2</td>
            <td>2</td>
            <td>$5.00</td>
            <td>$10.00</td>
          </tr>
          <tr>
            <td colspan="3" class="total">Total:</td>
            <td class="total">$20.00</td>
          </tr>
        </tbody>
      </table>
    </div>
  </body>
</html>
HTML

MAUI Blazor 应用程序生成如下所示的输出。

class="content-img-align-center"> .NET MAUI Blazor for (PDF,EXCEL,OCR,BARCODE,QR Code) - Figure 5: PDF Output

class="content__image-caption">Generating a PDF using .NET MAUI Blazor

Get more information about IronPDF with Blazor PDF creation tutorials and .NET MAUI applications.

IronXL

class="content-img-align-center"> .NET MAUI Blazor for (PDF,EXCEL,OCR,BARCODE,QR Code) - Figure 6: IronXL

class="content__image-caption">IronXL

IronXL 是一个 .NET 库,允许开发人员在 C# 中读取、编辑和创建 Excel 电子表格。 它不需要安装 Microsoft Excel 并支持包括 Android、iOS、macOS、Windows 计算机和 Azure 在内的所有平台。 它提供了一系列功能,如从各种格式加载和编辑数据,将数据保存和导出到各种格式,并使用 System.Data 对象,处理公式、数据排序和单元格样式。 此外,它可作为 NuGet 包使用,并在其网站和 GitHub 存储库中提供文档和示例。

IronXL 支持 .NET MAUI 和 Blazor,允许用户从各种来源访问或获取数据,包括 Excel 电子表格、Web 或 Azure 服务和其他应用程序。 借助 IronXL 对 .NET MAUI 和 Blazor 的支持,开发人员可以使用最强大的工具在 iOS、macOS、Windows 和 Android 设备上开发引人入胜的用户界面。

让我们看看 IronXL 的示例代码:

using IronXL;
using IronXL.Formatting;
using IronXL.Formatting.Enums;
using IronXL.Styles;

// Load an existing Excel workbook
WorkBook workbook = WorkBook.Load("test.xlsx");
WorkSheet sheet = workbook.DefaultWorkSheet;

// Create a specific conditional formatting rule for cells with values less than 8
ConditionalFormattingRule rule = sheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.LessThan, "8");

// Set different style options for the rule
rule.FontFormatting.IsBold = true; // Bold text
rule.FontFormatting.FontColor = "#123456"; // Custom font color
rule.BorderFormatting.RightBorderColor = "#ffffff"; // Right border color
rule.BorderFormatting.RightBorderType = BorderType.Thick; // Right border thickness
rule.PatternFormatting.BackgroundColor = "#54bdd9"; // Background color
rule.PatternFormatting.FillPattern = FillPattern.Diamonds; // Fill pattern

// Add the formatting rule to the specified cell range
sheet.ConditionalFormatting.AddConditionalFormatting("A3:A8", rule);

// Create another conditional formatting rule for values between 7 and 10
ConditionalFormattingRule rule1 = sheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.Between, "7", "10");

// Set additional style options for the new rule
rule1.FontFormatting.IsItalic = true; // Italic text
rule1.FontFormatting.UnderlineType = FontUnderlineType.Single; // Single underline

// Add this formatting rule to a different range of cells
sheet.ConditionalFormatting.AddConditionalFormatting("A3:A9", rule1);

// Save the workbook with the applied conditional formatting
workbook.SaveAs("ApplyConditionalFormatting.xlsx");
using IronXL;
using IronXL.Formatting;
using IronXL.Formatting.Enums;
using IronXL.Styles;

// Load an existing Excel workbook
WorkBook workbook = WorkBook.Load("test.xlsx");
WorkSheet sheet = workbook.DefaultWorkSheet;

// Create a specific conditional formatting rule for cells with values less than 8
ConditionalFormattingRule rule = sheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.LessThan, "8");

// Set different style options for the rule
rule.FontFormatting.IsBold = true; // Bold text
rule.FontFormatting.FontColor = "#123456"; // Custom font color
rule.BorderFormatting.RightBorderColor = "#ffffff"; // Right border color
rule.BorderFormatting.RightBorderType = BorderType.Thick; // Right border thickness
rule.PatternFormatting.BackgroundColor = "#54bdd9"; // Background color
rule.PatternFormatting.FillPattern = FillPattern.Diamonds; // Fill pattern

// Add the formatting rule to the specified cell range
sheet.ConditionalFormatting.AddConditionalFormatting("A3:A8", rule);

// Create another conditional formatting rule for values between 7 and 10
ConditionalFormattingRule rule1 = sheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.Between, "7", "10");

// Set additional style options for the new rule
rule1.FontFormatting.IsItalic = true; // Italic text
rule1.FontFormatting.UnderlineType = FontUnderlineType.Single; // Single underline

// Add this formatting rule to a different range of cells
sheet.ConditionalFormatting.AddConditionalFormatting("A3:A9", rule1);

// Save the workbook with the applied conditional formatting
workbook.SaveAs("ApplyConditionalFormatting.xlsx");
Imports IronXL
Imports IronXL.Formatting
Imports IronXL.Formatting.Enums
Imports IronXL.Styles

' Load an existing Excel workbook
Private workbook As WorkBook = WorkBook.Load("test.xlsx")
Private sheet As WorkSheet = workbook.DefaultWorkSheet

' Create a specific conditional formatting rule for cells with values less than 8
Private rule As ConditionalFormattingRule = sheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.LessThan, "8")

' Set different style options for the rule
rule.FontFormatting.IsBold = True ' Bold text
rule.FontFormatting.FontColor = "#123456" ' Custom font color
rule.BorderFormatting.RightBorderColor = "#ffffff" ' Right border color
rule.BorderFormatting.RightBorderType = BorderType.Thick ' Right border thickness
rule.PatternFormatting.BackgroundColor = "#54bdd9" ' Background color
rule.PatternFormatting.FillPattern = FillPattern.Diamonds ' Fill pattern

' Add the formatting rule to the specified cell range
sheet.ConditionalFormatting.AddConditionalFormatting("A3:A8", rule)

' Create another conditional formatting rule for values between 7 and 10
Dim rule1 As ConditionalFormattingRule = sheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.Between, "7", "10")

' Set additional style options for the new rule
rule1.FontFormatting.IsItalic = True ' Italic text
rule1.FontFormatting.UnderlineType = FontUnderlineType.Single ' Single underline

' Add this formatting rule to a different range of cells
sheet.ConditionalFormatting.AddConditionalFormatting("A3:A9", rule1)

' Save the workbook with the applied conditional formatting
workbook.SaveAs("ApplyConditionalFormatting.xlsx")
$vbLabelText   $csharpLabel

上面的代码可以帮助您打开已经存在的 Excel 文件并对不同的单元格范围应用条件格式。 通过以下 Excel 条件格式教程获取有关 IronXL 的更多教程。

IronOCR

class="content-img-align-center"> .NET MAUI Blazor for (PDF,EXCEL,OCR,BARCODE,QR Code) - Figure 7: IronOCR

class="content__image-caption">IronOCR

IronOCR 是 C# 开发人员中广泛使用的 OCR 工具,它为将 OCR 功能集成到 C# 应用程序中提供了简单的 API。 它可以有效地从多种来源中提取文本,例如扫描文档、PDF 和图像,使用高级机器学习算法准确识别即便是失真或难以阅读的文本。 IronOCR 为 C# 开发人员提供了一系列自定义选项,包括调整识别文本的语言、字体和字符集、预测集合的能力以及预处理图像以提高 OCR 准确性。 这些自定义功能允许开发人员针对其特定需求优化 IronOCR 的性能。

IronOCR 是一个强大的 OCR 识别库,支持 .NET MAUI 和 Blazor。 借助 IronOCR,开发人员可以快速在任何平台上创建应用程序,而无需担心扫描、读取和写入大量文本数据的复杂性。 没有其他 OCR 软件能为用户提供如此多的开发工具且简单易用的集成。

看一下 IronOCR 示例,演示了如何使用 IronOCR 从 PDF 文件中提取文本。

using IronOcr;

var ocrTesseract = new IronTesseract();

using (var ocrInput = new OcrInput())
{
    // OCR the entire document
    ocrInput.AddPdf("example.pdf", "password");

    // Alternatively OCR selected page numbers
    ocrInput.AddPdfPages("example.pdf", new[] { 1, 2, 3 }, "password");

    var ocrResult = ocrTesseract.Read(ocrInput);
    Console.WriteLine(ocrResult.Text);
}
using IronOcr;

var ocrTesseract = new IronTesseract();

using (var ocrInput = new OcrInput())
{
    // OCR the entire document
    ocrInput.AddPdf("example.pdf", "password");

    // Alternatively OCR selected page numbers
    ocrInput.AddPdfPages("example.pdf", new[] { 1, 2, 3 }, "password");

    var ocrResult = ocrTesseract.Read(ocrInput);
    Console.WriteLine(ocrResult.Text);
}
Imports IronOcr

Private ocrTesseract = New IronTesseract()

Using ocrInput As New OcrInput()
	' OCR the entire document
	ocrInput.AddPdf("example.pdf", "password")

	' Alternatively OCR selected page numbers
	ocrInput.AddPdfPages("example.pdf", { 1, 2, 3 }, "password")

	Dim ocrResult = ocrTesseract.Read(ocrInput)
	Console.WriteLine(ocrResult.Text)
End Using
$vbLabelText   $csharpLabel

通过访问此 .NET MAUI OCR 教程 了解更多有关如何在 .NET MAUI 中使用 IronOCR 的教程。

通过以下 PDF OCR 教程 获取有关 IronOCR 的更多教程。

IronBarcode

class="content-img-align-center"> .NET MAUI Blazor for (PDF,EXCEL,OCR,BARCODE,QR Code) - Figure 8: IronBarcode

class="content__image-caption">IronBarcode

class="hsg-featured-snippet">

如何在 .NET Maui 中创建条码扫描器

  1. 下载用于在 Maui 中创建条码扫描器的 C# 库
  2. 利用 Read 方法从 PDF 和图像中扫描条码
  3. 支持多种条码格式,包括 QR 码、代码 39、代码 128 等
  4. 将 C# 库轻松集成到现有 .NET MAUI 和 Blazor 项目中
  5. 将预处理应用于不完美的图像

IronBarcode 是一个 C# 库,使开发人员能够轻松地为其 C# 应用程序添加条码读取和写入功能。 此库对于从事涉及条码扫描或生成的项目(如库存管理系统或點对点销售系统)的开发人员特别有用。 IronBarcode 的一项关键功能是其能够读取和写入多种条码格式,包括 QR 码、代码 39、代码 128 等许多其他格式。 这意味着开发人员可以根据其项目的需求使用它来处理各种不同类型的条码。

IronBarcode 支持 .NET MAUI 和 Blazor,这两个流行的框架被开发人员用于构建现代跨平台应用程序。 这一点对开发人员有利,因为它允许他们轻松将 IronBarcode 强大的条码生成和扫描功能集成到 .NET MAUI 和 Blazor 项目中。

以下代码示例展示了您可以如何使用 IronBarcode 读取多种类型的条码。 这是一个非常简单易懂的过程。

using IronBarCode;
using IronSoftware.Drawing;

// Reading a barcode is easy with IronBarcode.
// Read from a File, Bitmap, Image, or Stream:

var resultFromFile = BarcodeReader.Read(@"file/barcode.png"); // From a file

var resultFromBitMap = BarcodeReader.Read(new Bitmap("barcode.bmp")); // From a bitmap

var resultFromAnyBitmap = BarcodeReader.Read(new AnyBitmap("barcode.bmp")); // From AnyBitmap

var resultFromImage = BarcodeReader.Read(Image.FromFile("barcode.jpg")); // From an image

var resultFromStream = BarcodeReader.Read(myStream); // From a stream

// PDFs are more intricate and must be read using ReadPdf:
var resultFromPdf = BarcodeReader.ReadPdf(@"file/mydocument.pdf");
using IronBarCode;
using IronSoftware.Drawing;

// Reading a barcode is easy with IronBarcode.
// Read from a File, Bitmap, Image, or Stream:

var resultFromFile = BarcodeReader.Read(@"file/barcode.png"); // From a file

var resultFromBitMap = BarcodeReader.Read(new Bitmap("barcode.bmp")); // From a bitmap

var resultFromAnyBitmap = BarcodeReader.Read(new AnyBitmap("barcode.bmp")); // From AnyBitmap

var resultFromImage = BarcodeReader.Read(Image.FromFile("barcode.jpg")); // From an image

var resultFromStream = BarcodeReader.Read(myStream); // From a stream

// PDFs are more intricate and must be read using ReadPdf:
var resultFromPdf = BarcodeReader.ReadPdf(@"file/mydocument.pdf");
Imports IronBarCode
Imports IronSoftware.Drawing

' Reading a barcode is easy with IronBarcode.
' Read from a File, Bitmap, Image, or Stream:

Private resultFromFile = BarcodeReader.Read("file/barcode.png") ' From a file

Private resultFromBitMap = BarcodeReader.Read(New Bitmap("barcode.bmp")) ' From a bitmap

Private resultFromAnyBitmap = BarcodeReader.Read(New AnyBitmap("barcode.bmp")) ' From AnyBitmap

Private resultFromImage = BarcodeReader.Read(Image.FromFile("barcode.jpg")) ' From an image

Private resultFromStream = BarcodeReader.Read(myStream) ' From a stream

' PDFs are more intricate and must be read using ReadPdf:
Private resultFromPdf = BarcodeReader.ReadPdf("file/mydocument.pdf")
$vbLabelText   $csharpLabel

通过访问此 .NET MAUI 条码扫描器教程 获取更多有关如何在 .NET Maui 中使用 IronBarcode 的教程。

通过以下 条码扫描器阅读器教程 获取更多 IronBarcode 的用例和教程。

IronDrawing

class="content-img-align-center"> .NET MAUI Blazor for (PDF,EXCEL,OCR,BARCODE,QR Code) - Figure 9: IronDrawing

class="content__image-caption">IronDrawing

IronDrawing 是一个免费的開源庫,為需要創建使用圖形、圖像和字體的跨平台應用程式的 .NET 開發人員提供了解決方案。 它充当不同图形库之间的桥梁,让开发人员可以在代码中使用单一一致的格式,同时仍然可以使用他们所选的底层库。IronDrawing 兼容 .NET 框架 4.6.2 及更新版本,包括 .NET 5、6 和 7。

IronDrawing 由 Iron Software 開發和維護,為一支經驗豐富的 .NET 開發團隊,致力於 .NET 的成長与成功。 他們創建 IronDrawing 的目的是使类库和 NuGet 開發更容易,帮助 NuGet 生態系统繁榮发展。

开发 IronDrawing 的原因

IronDrawing 是針對微軟宣布的重大變更而開發的,根據該變更System.Drawing.Common 只會在 Windows 平台上受支持。 該變更對於需要跨平台庫開發者是個問題,因為他們需要重新構建其庫以支持非 Windows 使用者,例如 Android 與 iOS。 IronDrawing 被创建为一种中间格式,在不同图形库之间进行转换,使开发人员更容易过渡到出现的新图形标准。

IronDrawing 的特色

IronDrawing 提供多种功能以协助开发人员进行其工作,包括AnyBitmap,一个通用兼容的Bitmap类,能够转换为各种其他 Bitmap 实现。 Color,一个通用兼容的Color类。 CropRectangle,一个通用兼容的 Rectangle 类。 以及 AnyFont,一个通用兼容的 Font 类。 它还提供了这些类与不同图形库中其对应部分之间的隐式转换,使它们之间的转换更为容易。 您可以从 NuGet 网站获得它。

IronDrawing 支持几乎所有 .NET 模板,包括 .NET MAUI 和 Blazor。 其平台独立的特性使其易于用于多种应用,范围从 Windows 桌面到移动端或基于 Web 的项目。

开源的好处

IronDrawing 是一个开源库。 任何人都可以从 GitHub 存储库 中访问代码,这比以往任何时候都更容易地定制和修改此库以更好地适应个别项目和需求。 不仅如此,公开代码还鼓励开发人员进行合作,他们可以在彼此的想法之上构建和分享。 IronDrawing C# 库的可能性是无限的 - 所以去看看 GitHub 并开始探索吧!

看看 IronDrawing 的代码示例从多种文件格式生成 AnyBitmap

using IronSoftware.Drawing;

AnyBitmap bitmap;

// Generate AnyBitmap using filepath
bitmap = AnyBitmap.FromFile(@"FILE_PATH");
bitmap.SaveAs("output.bmp");

// Generate AnyBitmap from bytes
byte[] bytes = File.ReadAllBytes(@"FILE_PATH");
bitmap = AnyBitmap.FromBytes(bytes);
bitmap.SaveAs("result.bmp"); 

// Generate AnyBitmap from memory stream
byte[] bytes = File.ReadAllBytes(@"FILE_PATH");
MemoryStream ms = new MemoryStream(bytes);
bitmap = AnyBitmap.FromStream(ms);
bitmap.SaveAs("output.bmp");  

// Generate AnyBitmap from Uri
Uri uri = new Uri("URI_PATH");
bitmap = AnyBitmap.FromUri(uri);
bitmap.SaveAs("uriImage.bmp"); 

// Generate AnyBitmap file from SVG file
bitmap = AnyBitmap.FromFile(@"FILE_PATH.svg");
bitmap.SaveAs("result.bmp"); 
using IronSoftware.Drawing;

AnyBitmap bitmap;

// Generate AnyBitmap using filepath
bitmap = AnyBitmap.FromFile(@"FILE_PATH");
bitmap.SaveAs("output.bmp");

// Generate AnyBitmap from bytes
byte[] bytes = File.ReadAllBytes(@"FILE_PATH");
bitmap = AnyBitmap.FromBytes(bytes);
bitmap.SaveAs("result.bmp"); 

// Generate AnyBitmap from memory stream
byte[] bytes = File.ReadAllBytes(@"FILE_PATH");
MemoryStream ms = new MemoryStream(bytes);
bitmap = AnyBitmap.FromStream(ms);
bitmap.SaveAs("output.bmp");  

// Generate AnyBitmap from Uri
Uri uri = new Uri("URI_PATH");
bitmap = AnyBitmap.FromUri(uri);
bitmap.SaveAs("uriImage.bmp"); 

// Generate AnyBitmap file from SVG file
bitmap = AnyBitmap.FromFile(@"FILE_PATH.svg");
bitmap.SaveAs("result.bmp"); 
Imports IronSoftware.Drawing

Private bitmap As AnyBitmap

' Generate AnyBitmap using filepath
bitmap = AnyBitmap.FromFile("FILE_PATH")
bitmap.SaveAs("output.bmp")

' Generate AnyBitmap from bytes
Dim bytes() As Byte = File.ReadAllBytes("FILE_PATH")
bitmap = AnyBitmap.FromBytes(bytes)
bitmap.SaveAs("result.bmp")

' Generate AnyBitmap from memory stream
Dim bytes() As Byte = File.ReadAllBytes("FILE_PATH")
Dim ms As New MemoryStream(bytes)
bitmap = AnyBitmap.FromStream(ms)
bitmap.SaveAs("output.bmp")

' Generate AnyBitmap from Uri
Dim uri As New Uri("URI_PATH")
bitmap = AnyBitmap.FromUri(uri)
bitmap.SaveAs("uriImage.bmp")

' Generate AnyBitmap file from SVG file
bitmap = AnyBitmap.FromFile("FILE_PATH.svg")
bitmap.SaveAs("result.bmp")
$vbLabelText   $csharpLabel

IronDrawing 使用多种方法将文件从路径转换为位图。您可以看到 IronDrawing 使用内存流将文件转换为 BMP,这在基于服务器的应用程序中非常有用。 类似地,您可以使用 SVG 文件生成 BMP。

class="content-img-align-center"> .NET MAUI Blazor for (PDF,EXCEL,OCR,BARCODE,QR Code) - Figure 10: BMP File

class="content__image-caption">A Bitmap file generated from the IronDrawing open-source library

定价

Iron Software 提供了一套五种软件产品,称为 Iron Suite。该套件包括 IronPDF、IronXL、IronOCR、IronWebscraper 和 IronBarcode,它们分别是用于与 PDF、电子表格、图像、网络抓取和条码交互的工具。

这些产品的单价从 $799 起,但 Iron Software 提供特别的套装价格,套装价格从 1498 美元起。Iron Suite 是那些需要处理多种文件类型并需要自动化处理、分析和转换它们的人的好解决方案。

結論

总的来说,.NET MAUI 是一个用于构建跨平台桌面和移动应用程序的框架。 在文章中,我们讨论了多个库,如 IronPDF、IronXL、IronBarcode、IronOCR 和 IronDrawing,它们提供了创建和处理 PDF 文件、读写 Excel 文件、生成和扫描条码、光学字符识别和绘图及操作图形的各种功能。

在这些库中,IronDrawing 是一个强大的工具,能够让开发人员在他们的 .NET 应用中创建和编辑矢量图形。 它提供了广泛的功能且易于使用,成为 .NET MAUI 框架宝贵的补充。 总体而言,.NET MAUI 和这些库的组合为开发人员提供了一个多功能工具包,可用于构建现代、功能丰富的跨平台应用程序。

常見問題解答

如何將 PDF 功能整合到 .NET MAUI 應用程式中?

您可以使用 IronPDF 來整合 PDF 功能,這使您能夠使用 .NET Chromium 引擎將 HTML 轉換為 PDF。此整合支持在您的 .NET MAUI 應用程式中創建和操作 PDF 文件。

在 .NET MAUI 專案中使用 Excel 資料庫有什麼優勢?

在您的 .NET MAUI 專案中使用 IronXL 允許您操作 Excel 試算表而無需安裝 Microsoft Excel。它支持在 Android、iOS、macOS 和 Windows 平台上讀取、編輯和創建試算表。

IronOCR 如何在 .NET MAUI 應用中增強文本擷取能力?

IronOCR 在 .NET MAUI 應用中提供了先進的 OCR 功能,允許從掃描文檔、PDF 和圖像中準確提取文本。它使用機器學習算法並為語言和字體提供自定義化選項。

在 .NET MAUI 和 Blazor 應用中可以實現什麼樣的條碼功能?

IronBarcode 可以整合到 .NET MAUI 和 Blazor 應用中,添加條碼讀取和寫入功能。它支持多種條碼格式,包括 QR 碼和 Code 128,適合於如庫存管理等應用。

IronDrawing 如何有助於跨平台圖形開發?

IronDrawing 是一個用於創建跨平台圖形應用的免費開源資料庫。它提供了一個一致的圖形格式,填補了 Microsoft 在 System.Drawing.Common 支援變更後留下的空白。

BlazorWebView 在 .NET MAUI 應用中有什麼作用?

BlazorWebView 是 .NET MAUI 中的一個控件,允許開發者將 MAUI Blazor 伺服器應用程式整合到 .NET MAUI 項目中。它通過在本地應用中渲染網頁 UI 控件來促進跨平台應用的創建。

如何使用 .NET MAUI 實現跨平台開發?

使用 .NET MAUI 實現跨平台開發可以通過其框架來構建在 Android、iOS、macOS 和 Windows 平台上運行的應用程式。通過 BlazorWebView 的整合,它進一步增強了這一功能,允許使用網頁 UI 控件。

.NET MAUI 在現代應用開發中有什麼關鍵功能?

.NET MAUI 提供了用於構建具備本機效能的跨平台應用的框架。關鍵功能包括整合 BlazorWebView 以用於網頁 UI 控件,並與 IronPDF、IronXL、IronOCR、IronBarcode 和 IronDrawing 資料庫的兼容性以增強功能。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。