WPF 使用PdfiumViewer实现PDF预览与打印

1.引用Nuget包:PdfiumViewer

2.Xaml代码,需要使用<WindowsFormsHost>标签,可能这个包是为winform设计的。

XML 复制代码
    xmlns:pdfium="clr-namespace:PdfiumViewer;assembly=PdfiumViewer"

    <WindowsFormsHost>
        <pdfium:PdfViewer x:Name="pdfViewer" Width="300" Height="300"/>
    </WindowsFormsHost>

3.后台代码,非常简单,绑定一下PDF文件路径即可。

cs 复制代码
        public PrintingPDF(string PDFPath)
        {
            InitializeComponent();

            try
            {
                var document = PdfDocument.Load(PDFPath);
                pdfViewer.Document = document;
            }
            catch (Exception ex)
            {
                
            }
        }
相关推荐
xcLeigh15 小时前
WPF进阶 | WPF 数据绑定进阶:绑定模式、转换器与验证
c#·wpf
流形填表2 天前
Pdf to forms如何实现?如何在3分钟内将PDF自动转换为Microsoft Forms
microsoft·pdf·c#
IDRSolutions_CN2 天前
什么是线性化PDF?
经验分享·pdf·软件工程·团队开发
辣香牛肉面2 天前
开源PDF分割合并工具 PDFsam Basic v5.3.0绿色版
pdf
天赐信息科技2 天前
衡水市城区小区地图)矢量高清cdr|pdf大图内容测评
pdf·贴图
SunkingYang2 天前
C#如何通过使用XpsToPdf库来转换xps为pdf文件
pdf·c#·使用方法·转换·xps·xpstopdf
辣香牛肉面3 天前
PDF 擦除工具
pdf
学与用3 天前
【deepseek实战】绿色好用,不断网
ai·c#·wpf
花千树-0103 天前
LangChain教程 - RAG - PDF解析
langchain·pdf
的不对不4 天前
WPF基础03——InitializeComponent()函数解释
windows·c#·.net·wpf