打印文件教程

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronPrint 是一个功能强大的打印库,旨在帮助 .NET C# 开发人员将打印功能集成到他们的应用程序中。IronPrint 具有广泛的兼容性,横跨 Windows、macOS、iOS 和 Android 平台,可在各种操作系统中稳定可靠地运行。无论您是为桌面环境、苹果公司的 macOS 生态系统,还是为 iOS 和 Android 等移动平台创建应用程序,IronPrint 都能简化打印功能的实现,为您在 .NET C# 环境中的所有打印需求提供多功能、用户友好的解决方案。

目录

适用于的C# NuGet库

安装使用 NuGet

Install-Package IronPrint
适用于的C# NuGet库

安装使用 NuGet

Install-Package IronPrint
Java PDF JAR

下载 DLL

下载DLL

手动安装到你的项目中

开始在您的项目中使用IronPDF,并立即获取免费试用。

第一步:
green arrow pointer

查看 IronPrintNuget 用于快速安装和部署。它有超过800万次下载,正在使用C#改变。

适用于的C# NuGet库 nuget.org/packages/IronPrint/
Install-Package IronPrint

打印文档

无声打印

无缝打印文档,无需显示打印对话框。打印设置可直接在代码中完成。

:path=/static-assets/print/content-code-examples/tutorials/print-document-print-silently.cs
using IronPrint;

// Print the document
Printer.Print("newDoc.pdf");
Imports IronPrint

' Print the document
Printer.Print("newDoc.pdf")
VB   C#

使用对话框打印

在显示打印设置对话框时启动打印过程。这样用户就可以交互式地自定义打印选项。

:path=/static-assets/print/content-code-examples/tutorials/print-document-print-with-dialog.cs
using IronPrint;

// Show print dialog
Printer.ShowPrintDialog("newDoc.pdf");
Imports IronPrint

' Show print dialog
Printer.ShowPrintDialog("newDoc.pdf")
VB   C#

应用打印设置

以编程方式调整打印设置以满足特定要求。本节提供了通过代码微调打印配置的功能。

:path=/static-assets/print/content-code-examples/tutorials/print-document-apply-print-setting.cs
using IronPrint;

// Configure print setting
PrintSettings printSettings = new PrintSettings();
printSettings.Dpi = 150;
printSettings.NumberOfCopies = 2;
printSettings.PaperOrientation = PaperOrientation.Portrait;

// Print the document
Printer.Print("newDoc.pdf", printSettings);
Imports IronPrint

' Configure print setting
Private printSettings As New PrintSettings()
printSettings.Dpi = 150
printSettings.NumberOfCopies = 2
printSettings.PaperOrientation = PaperOrientation.Portrait

' Print the document
Printer.Print("newDoc.pdf", printSettings)
VB   C#

获取打印机信息

获取打印机名称

访问所有可用打印机的列表。获取系统中安装的打印机名称,以便在应用程序中提供信息或动态选择打印机。

:path=/static-assets/print/content-code-examples/tutorials/print-document-get-printer-names.cs
using IronPrint;
using System;
using System.Collections.Generic;

// Retrieve printers' name
List<string> printersName = Printer.GetPrinterNames();

foreach (var printer in printersName)
{
    Console.WriteLine(printer);
}
Imports IronPrint
Imports System
Imports System.Collections.Generic

' Retrieve printers' name
Private printersName As List(Of String) = Printer.GetPrinterNames()

For Each printer In printersName
	Console.WriteLine(printer)
Next printer
VB   C#