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)
            {
                
            }
        }
相关推荐
暮雪倾风2 小时前
【WPF】使用Costura.Fody将工程打包为单个EXE文件
wpf·exe·windows原生开发
咖啡の猫4 小时前
Jedis快速入门
wpf
Scout-leaf6 小时前
WPF新手村教程(五)— 附魔教学(绑定)
c#·wpf
weixin_6688 小时前
Agent 应该中 PDF 工具方案分析报告 - AI分析分享
人工智能·pdf
fjhcom8 小时前
PDF与图片互转WEB应用开发教程
前端·pdf·图片·web应用·streamlit
polaris06309 小时前
【Spring Boot 实现 PDF 导出】
spring boot·后端·pdf
南风微微吹1 天前
【2026大英赛】全国大学生英语竞赛C类历年真题试卷及答案电子版PDF(2012-2025年)
pdf·大英赛
南风微微吹1 天前
【专八】英语专业八级TEM8历年真题及答案解析电子版PDF(2009-2025年)
pdf·英语专八
西门吹-禅1 天前
【pdf 翻译免费】
pdf
数据知道1 天前
MongoDB灾难恢复计划:RTO/RPO目标下的应急响应完整方案
数据库·mongodb·wpf