一、打印控件:
PrintDocument:要打印的对象。
PageSetupDialog:打印设置对话框。
PrintPreviewControl:打印预览控件。
PrintPreviewDialog:打印预览对话框。
PrintDialog:打印对话框。
二、相关软件
我们的产品是基于Adobe来开发的,我们首先得知道这个功能具体是如何实现的,才好调查用我们的产品如何去实现。所以首先得知道用的是Adobe的哪个版本。
三、相关属性
1、PrintDocument.DocumentName 属性
命名空间:
程序集:
System.Drawing.dll, System.Drawing.Common.dll
打印文档时获取或设置要显示的文档名称(例如,在打印状态对话框中或在打印机队列中)。从元数据:
public string DocumentName { get; set; }
示例
下面的代码示例使用颜色打印第一页,如果打印机支持该文档,并将设置DocumentName为用户友好名称。 该示例需要创建一个PrintDocument名为printDoc
的变量, PrintPage并处理和QueryPageSettings事件。
在System.Drawing此示例System.Drawing.Printing中使用和命名空间。
private void MyButtonPrint_OnClick(object sender, System.EventArgs e)
{
// Set the printer name and ensure it is valid. If not, provide a message to the user.
printDoc.PrinterSettings.PrinterName = "\\mynetworkprinter";
if (printDoc.PrinterSettings.IsValid) {
// If the printer supports printing in color, then override the printer's default behavior.
if (printDoc.PrinterSettings.SupportsColor) {
// Set the page default's to not print in color.
printDoc.DefaultPageSettings.Color = false;
}
// Provide a friendly name, set the page number, and print the document.
printDoc.DocumentName = "My Presentation";
currentPageNumber = 1;
printDoc.Print();
}
else {
MessageBox.Show("Printer is not valid");
}
}
private void MyPrintQueryPageSettingsEvent(object sender, QueryPageSettingsEventArgs e)
{
// Determines if the printer supports printing in color.
if (printDoc.PrinterSettings.SupportsColor) {
// If the printer supports color printing, use color.
if (currentPageNumber == 1 ) {
e.PageSettings.Color = true;
}
}
}
2、PrintDocument.PrintController 属性 (System.Drawing.Printing),打印控制器
获取或设置指导打印进程的打印控制器。
命名空间: System.Drawing.Printing
程序集: System.Drawing(位于 System.Drawing.dll)
从元数据:
[System.ComponentModel.Browsable(false)]
public System.Drawing.Printing.PrintController PrintController { get; set; }
public PrintController PrintController { get; set; }
示例:
public void myPrint()
{
if (useMyPrintController == true)
{
myPrintDocument.PrintController =
new myControllerImplementation();
if (wantsStatusDialog == true)
{
myPrintDocument.PrintController =
new PrintControllerWithStatusDialog
(myPrintDocument.PrintController);
}
}
myPrintDocument.Print();
}
属性值
Type:
PrintController 指导打印进程。 默认值为的新实例 PrintControllerWithStatusDialog 类。
备注
一个打印控制器指导打印进程中有多种。 例如,若要打印文档时,需要将其转换为 Graphics 对象。 一个 PrintController 指定在为打印预览或打印文档的实际的打印机上的图像中绘制图形的位置。 一个打印控制器还可以指定是否立即打印文档或等待指定的时间间隔。
示例
下面的代码示例要求您已创建的一个实例 PrintDocument 类名为myPrintDocument。 该示例创建的新实例 PrintController 类中,将它分配给 属性myPrintDocument, ,并打印该文档。
使用 System.Drawing.Printing 和 System.Windows.Forms 对于此示例的命名空间。
public void myPrint()
{
if (useMyPrintController == true)
{
myPrintDocument.PrintController =
new myControllerImplementation();
if (wantsStatusDialog == true)
{
myPrintDocument.PrintController =
new PrintControllerWithStatusDialog
(myPrintDocument.PrintController);
}
}
myPrintDocument.Print();
}
Public Sub myPrint()
If useMyPrintController = True Then
myPrintDocument.PrintController = New myControllerImplementation()
If wantsStatusDialog = True Then
myPrintDocument.PrintController = _
New PrintControllerWithStatusDialog( _
myPrintDocument.PrintController)
End If
End If
myPrintDocument.Print()
End Sub
public:
void myPrint()
{
if ( useMyPrintController == true )
{
myPrintDocument->PrintController =
gcnew myControllerImplementation;
if ( wantsStatusDialog == true )
{
myPrintDocument->PrintController =
gcnew PrintControllerWithStatusDialog(
myPrintDocument->PrintController );
}
}
myPrintDocument->Print();
}
3、public bool IsValid { get; }
// 摘要:
// 获取一个值,该值指示是否 System.Drawing.Printing.PrinterSettings.PrinterName 属性指定有效的打印机。
//
// 返回结果:
// true 如果 System.Drawing.Printing.PrinterSettings.PrinterName 属性指定有效的打印机; 否则为 false。
public bool IsValid { get; }
IsValid 是Page的属性,用于判断页面上的验证控件是否均通过验证,如果页面上没有验证控件,则不必做这个判断了。
四、相关链接
1、System.Drawing.Printing 命名空间
https://docs.microsoft.com/zh-cn/dotnet/api/system.drawing.printing?view=netframework-4.8
2、PrinterSettings 类
五、右键菜单
contextMenuStrip1
从工具箱中找到这个控件,拖到窗体上,这是一个非可视化控件。
1、删除指定行[D]
2、提取PDF页面[E]
3、解除PDF限制[R]
4、清除PDF密码[L]
5、转换到PDF[T]
6、合并到PDF[M]
7、列出所有文件[S]
8、清空列表[P]
9、获取文件个数[N]
10、统计费用[A]
六、打印PDF需要用到的组件和驱动
1、Adobe Acrobat Reader DC
2、Foxit Reader(福昕PDF阅读器)
七、驱动程序设置
八、驱动
程序(驱动)将转化好的打印文件,按照各种打印机的不同格式发送给打印机,是应用层程序与底层打印机硬件交互的媒介。不同打印机映射到的驱动程序是不同的。