普通模式和v2都会报错
引用dll库:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Drawing.dll
D:\Files\重要\C#\ConsoleApp3\packages\PdfiumViewer.2.13.0.0\lib\net20\PdfiumViewer.dll
D:\Files\重要\C#\ConsoleApp3\packages\PdfiumViewer.Native.x86_64.v8-xfa.2018.4.8.256\Build\x64\pdfium.dll
using System.Drawing.Printing;
using PdfiumViewer;
public class Program
{
public static void Main(string[] args)
{
string pdfPath = @"qw.pdf"; // 获取 PDF 文件路径
PrintPdf(pdfPath);
}
private static void PrintPdf(string pdfPath)
{
// 加载 PDF 文档
using (var document = PdfDocument.Load(pdfPath))
{
// 创建打印文档
using (var printDocument = document.CreatePrintDocument())
{
//获取 PDF 文件的页数
int PageNum = document.PageCount;
//设置提示窗内容
printDocument.DocumentName = "正在打印 共 " + PageNum + " 页";
// 设置打印器为默认打印器
printDocument.PrinterSettings.PrinterName = new PrinterSettings().PrinterName;
// 打印文档
printDocument.Print();
}
}
}
}