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)
            {
                
            }
        }
相关推荐
2601_967760787 小时前
2026年PDF压缩与页码添加工具技术实测:性能、算法与本地化适配深度对比
算法·pdf
weixin_4508135314 小时前
pdf文档转为markdown文档
linux·pdf
慧都小妮子15 小时前
用 Python 批量把 PDF 参考文献排成 MLA 格式:Spire.Doc for Python 实战
python·pdf·c#·spire.doc·mla格式·参考文献排版·pdf批量处理
FuckPatience18 小时前
WPF 窗体唤醒,判断是否已存在,存在则弹出
wpf
weixin_4935036718 小时前
商会系统里的在线文件预览:PDF/Word/Excel 三种实现与选型(Node + 前端实战)
pdf·word·excel
程序员清风20 小时前
从单体应用到微服务:后端系统拆分的基本方法
微服务·架构·wpf
ygwelcome20 小时前
视频收割机-VideoHarvester架构功能介绍
pdf·音视频
2601_9677607821 小时前
PDF转图片分辨率怎么选?几款工具实测
pdf
runningshark1 天前
Lecture: Simple Present vs Present Continuous PDF
pdf
weixin_416667962 天前
Stirling-PDF是一款完全开源免费、本地部署的全能PDF处理工具
pdf