在實際環境中測試
在生產環境中測試無浮水印。
在任何需要的地方都能運作。
QR碼,即快速反應碼,已經在我們的數位時代中變得無處不在。它們將信息存儲在白色背景上的黑色方格矩陣中,可以使用智慧型手機或專用的QR碼閱讀器掃描。這些使用.NET條碼DLL生成的QR碼/條形碼被應用於各種用途,包括產品標籤、行動支付和行銷材料。打印QR碼對於無縫集成實體與數位互動至關重要。
在本文中,我們將首先使用C#生成QR碼。 IronQR, QR code 生成器 庫,然後使用 轉換為 PDF IronPDF, 最後使用 C# 列印具有 QR 碼圖片的像素完美文檔 IronPrint 圖書館
创建一个 Visual Studio 项目
安装 IronQR、IronPDF 和 IronPrint 库
使用 QrWriter.Write 创建 QR 码()**方法
使用 SaveAs 方法將生成的 QR 碼保存為圖像
使用 IronPDF 的 ImageToPdfConverter 創建 PDF 文件
使用 IronPrint 調整 PrinterSettings
IronPrint由...開發 Iron Software,是一個強大的 .NET 列印庫,提供一組多功能的工具來處理 C# 中的列印任務。它支援各種環境,包括 Windows、macOS、Android 和 iOS。在本文中,我們將探索如何利用 IronPrint 和 IronQR 及 IronPDF,在 C# 控制台應用程序中創建 QR 碼,以及轉換和列印 QR 碼。
IronPrint 專門為列印相關功能設計的專用類別和方法,主要特點包括:
在深入了解使用C#創建控制台應用程式以列印QR碼的步驟之前,請確保你已具備以下先決條件:
Visual Studio: 安裝Microsoft Visual Studio,這是一個功能強大的C#集成開發環境。你可以從其官方網站下載。 網站.
IronQR Library: 這個庫對生成QR碼非常重要。使用NuGet Console 或直接從官方網站安裝。 IronQR NuGet 網站。
IronPDF Library: IronPDF 將被用於將生成的QR碼條形碼圖像轉換為PDF。使用相同的NuGet安裝方法進行安裝。
依照以下步驟在 Visual Studio 中設置一個 C# 主控台應用程式:
請按照以下步驟安裝必要的庫:
在 Visual Studio 專案中,通過工具菜單或解決方案資源管理器打開 NuGet 套件管理器控制台或 NuGet 套件管理器。
安裝 IronQR 二維碼庫:
Install-Package IronQR
安裝 IronPDF PDF 庫:
Install-Package IronPdf
Install-Package IronPrint
讓我們逐步說明使用IronQR、IronPDF和IronPrint創建QR碼、將QR碼轉換為PDF,並最終列印QR碼生成器輸出的過程。
在 Program.cs 文件的頂部,我們將包括對所需庫的引用。這確保庫已安裝並可供使用。
// Reference to libraries
using IronPrint; // Library for printing functionalities
using IronPdf; // Library for PDF handling
using IronQr; // Library for QR code generation
using IronSoftware.Drawing; // Library for image processing
// Reference to libraries
using IronPrint; // Library for printing functionalities
using IronPdf; // Library for PDF handling
using IronQr; // Library for QR code generation
using IronSoftware.Drawing; // Library for image processing
' Reference to libraries
Imports IronPrint ' Library for printing functionalities
Imports IronPdf ' Library for PDF handling
Imports IronQr ' Library for QR code generation
Imports IronSoftware.Drawing ' Library for image processing
在這一步中,首先我們將 生成 QR 碼 使用 IronQR 然後將其另存為圖像,如以下程式碼範例所示:
// Code to create a QR code using IronQR
QrCode myQr = QrWriter.Write("Hello IronPrint!"); // Generate a QR code with the message
AnyBitmap qrImage = myQr.Save(); // Save QR code as an image
qrImage.SaveAs("assets/qr.png"); // Save the png image file to the "assets" folder
// Code to create a QR code using IronQR
QrCode myQr = QrWriter.Write("Hello IronPrint!"); // Generate a QR code with the message
AnyBitmap qrImage = myQr.Save(); // Save QR code as an image
qrImage.SaveAs("assets/qr.png"); // Save the png image file to the "assets" folder
' Code to create a QR code using IronQR
Dim myQr As QrCode = QrWriter.Write("Hello IronPrint!") ' Generate a QR code with the message
Dim qrImage As AnyBitmap = myQr.Save() ' Save QR code as an image
qrImage.SaveAs("assets/qr.png") ' Save the png image file to the "assets" folder
在這段程式碼中:
這是QR碼輸出:
接下來,我們將轉換 QR 碼 圖像轉PDF 使用 IronPDF. PDF保留了文件的格式,適合分享和打印。在這裡,每個圖像文件將被放置在單獨的PDF文件頁面上。
// Code to convert QR Image to PDF using IronPDF
var imageFiles = Directory.EnumerateFiles("assets").Where(f => f.EndsWith(".jpg")
f.EndsWith(".png")); // Reading QR codes image files
// Convert the QR code images to a PDF and save it
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs("assets/composite.pdf");
// Code to convert QR Image to PDF using IronPDF
var imageFiles = Directory.EnumerateFiles("assets").Where(f => f.EndsWith(".jpg")
f.EndsWith(".png")); // Reading QR codes image files
// Convert the QR code images to a PDF and save it
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs("assets/composite.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
在此程式碼片段中:
這是輸出的結果:
最後,我們將使用 IronPrint - 一個多功能的列印庫 列印生成的PDF 使用打印機設定。
// Code for Printing using IronPrint
// Get available printer names
List<string> printerNames = Printer.GetPrinterNames();
// Create print settings object
PrintSettings printerSettings = new PrintSettings();
foreach(string printerName in printerNames)
{
// Set desired printer name
if(printerName.Equals("Microsoft Print to PDF"))
printerSettings.PrinterName = printerName;
}
//Configure print setting
printerSettings.PaperSize = PaperSize.A4; // Set paper size
Margins margins = new Margins(30,10); // Set paper margins
printerSettings.PaperMargins = margins; // Apply margins
Printer.Print("assets/composite.pdf", printerSettings); // Print the PDF
// Code for Printing using IronPrint
// Get available printer names
List<string> printerNames = Printer.GetPrinterNames();
// Create print settings object
PrintSettings printerSettings = new PrintSettings();
foreach(string printerName in printerNames)
{
// Set desired printer name
if(printerName.Equals("Microsoft Print to PDF"))
printerSettings.PrinterName = printerName;
}
//Configure print setting
printerSettings.PaperSize = PaperSize.A4; // Set paper size
Margins margins = new Margins(30,10); // Set paper margins
printerSettings.PaperMargins = margins; // Apply margins
Printer.Print("assets/composite.pdf", printerSettings); // Print the PDF
' Code for Printing using IronPrint
' Get available printer names
Dim printerNames As List(Of String) = Printer.GetPrinterNames()
' Create print settings object
Dim printerSettings As New PrintSettings()
For Each printerName As String In printerNames
' Set desired printer name
If printerName.Equals("Microsoft Print to PDF") Then
printerSettings.PrinterName = printerName
End If
Next printerName
'Configure print setting
printerSettings.PaperSize = PaperSize.A4 ' Set paper size
Dim margins As New Margins(30,10) ' Set paper margins
printerSettings.PaperMargins = margins ' Apply margins
Printer.Print("assets/composite.pdf", printerSettings) ' Print the PDF
在這段程式碼片段中:
這是打印文件的輸出。這顯示了圖像將如何被打印:
將文件打印到實體打印機變得更加容易 IronPrint. 要獲得更多的控制來列印,您可以使用 ShowPrintDialog() 方法。如需有關如何高效列印的更多資訊,請訪問此 文檔 頁面。
IronPrint 專為 .NET 應用程式設計的強大列印庫。和主要處理 PDF 相關任務的 IronPDF 以及微軟的一般列印機制不同,IronPrint 提供了一組專門的類別和方法,針對列印過程進行精細控制。
使用 IronPrint,開發人員可以利用:
IronPrint 提供非同步功能,防止列印操作阻塞執行緒並提高性能。
IronPrint 中專用的 Printer 類別允許列印各種檔案類型,提供超越標準列印的靈活性。
IronPrint 支援多個平台,包括 Windows、Android、iOS 和 macOS,適用於各種應用環境。
開發者可以透過 PrintSettings 類別精細控制列印設定,包括紙張大小、方向、DPI、份數等。
總之,結合 IronPrint, IronQR,和 IronPDF 提供了一套強大的解決方案,用於在C#中創建、轉換和打印QR碼。異步打印的優勢、多樣化的打印選項以及跨平台支持,使得IronPrint成為開發人員的寶貴工具。按照本指南中的詳細步驟,您可以生成QR碼條形碼,並且可以無縫集成它們的打印到您的C#應用程式中,彌合物理和數字互動之間的鴻溝。