打印文档教程

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#环境中实现打印功能的过程,为您的所有打印需求提供了多功能且用户友好的解决方案。

开始使用 IronPrint

立即在您的项目中开始使用IronPrint,并享受免费试用。

第一步:
green arrow pointer


目录

打印文档

无声打印

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

: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#