C#获取PDF缩略图

原文链接:https://www.cnblogs.com/zhaotianff/p/17371809.html

这里主要用到mupdf库

MuPDF: The ultimate library for managing PDF documents

库是由C写的

mupdf有一个.NET的移植版本mupdf-converter

项目地址: GitHub - dwaleke/mupdf-converter: Automatically exported from code.google.com/p/mupdf-converter

mupdf-converter可以将PDF转换成Bitmap,也可以直接转换成WPF使用的BitmapSource。

使用方法如下:

1、下载 mupdf-converter Release

2、引用 MuPDF.dll,将MuPDFLib-x64.dll(MuPDFLib-x86.dll)放到运行路径下。

              int width = 0;
              int height = 0;
              int rotation = 0;
              int page = 1;
              int dpi = 96;
              MuPDFLib.RenderType RenderType = RenderType.RGB;
              bool rotateAuto = false;
              string file = @"test.pdf";
              string password = "";
 
              MuPDFLib.MuPDF pdfDoc = new MuPDFLib.MuPDF(file, password);
  
              pdfDoc.Page = page;
              Bitmap bitmap = pdfDoc.GetBitmap(width, height, dpi, dpi, rotation, RenderType,
                                           rotateAuto, false, 0);
  
              var bitmapSource = pdfDoc.GetBitmapSource(width, height, dpi, dpi, rotation, RenderType,rotateAuto, false, 0);
              pdfDoc.Dispose();  

注意:

mupdf不支持中文路径,如果有中文路径,程序会闪退。因为是P/Invoke,所以是看不到异常信息的。

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值