Pdfium.Net.Free 一个免费的Pdfium的 .net包装器--快速入门
Pdfium.Net.Free 支持
.NETFramework 4.0
.NETFramework 4.5
.NETStandard 2.0
可以和PdfiumViewer.Free共同使用预览pdf,也可以直接引用Pdfium.Net.Free 操作pdf,解决部分.NetCore 调用的问题,Pdfium.Net.Free封装了现有Pdfium的函数,实现了部分操作pdf的功能,部分功能等待后续~~
项目地址:
Pdfium.Net:https://github.com/1000374/Pdfium.Net
PdfiumViewer:https://github.com/1000374/PdfiumViewer
打开PDF:
- var pathPdf = "./Pdfium.NetTests/resources/about_blank.pdf";
- using (var doc = PdfDocument.Load(new MemoryStream(File.ReadAllBytes(pathPdf))))
- {
}
创建PDF 添加页面:
- using (var doc = PdfDocument.CreateNew())
- {
- doc.Pages.Add(612, 792);
- }
添加文字:
- using (var doc = PdfDocument.CreateNew())
- {
- var fontPath = @"c:\Windows\fonts\simhei.ttf";
- doc.LoadFont(fontPath);
- var cSharpString = "!you ok 这是第一句。 这是第二行。a you ok";
- var page = doc.Pages.Add(612, 792);
- page.AddString(cSharpString, 10, 50, 12, Color.Black);
- doc.Save("./Pdfium.NetTests/AddString.pdf");
- }
添加水印:
- using (var doc = PdfDocument.CreateNew())
- {
- doc.Pages.Add(612, 792);
- var fontPath = @"c:\Windows\fonts\simhei.ttf";
- var cSharpString = "我是水印";
- doc.LoadFont(fontPath, true, cSharpString);
- doc.WaterMark(cSharpString, 20, Color.FromArgb(50, 255, 0, 0), totleHeight: 120);
- doc.Save("./Pdfium.NetTests/WaterMark.pdf");
- }
添加图片:
- using (var doc = PdfDocument.CreateNew())
- {
- var imagePath = "./Pdfium.NetTests/resources/mona_lisa.jpg";
- var page = doc.Pages.Add(612, 792);
- var stream = new MemoryStream(File.ReadAllBytes(imagePath));
- page.AddImage(stream, 50, 100);
- doc.Save("./Pdfium.NetTests/AddImage.pdf");
- }
pdf每一页转成图片:
- var pathPdf = "./Pdfium.NetTests/resources/annotation_highlight_long_content.pdf";
- using (var doc = PdfDocument.Load(new MemoryStream(File.ReadAllBytes(pathPdf))))
- for (int i = 0; i < doc.PageCount; i++)
- {
- using (var image = doc.Pages[i].Render((int)doc.Pages[i].Width * 4 / 3, (int)doc.Pages[i].Height * 4 / 3, 96, 96, FpdfRotation.Rotate0, Wrapper.RenderFlags.Annotations | Wrapper.RenderFlags.CorrectFromDpi))
- {
- }
- }
pdf页局部转成图片:
- var pathPdf = "./Pdfium.NetTests/resources/annotation_highlight_long_content.pdf";
- using (var doc = PdfDocument.Load(new MemoryStream(File.ReadAllBytes(pathPdf))))
- for (int i = 0; i < doc.PageCount; i++)
- {
- using (var image = doc.Pages[i].Render(
- (int)doc.Pages[i].Width,
- (int)doc.Pages[i].Height,
- 16, // x of the top/left of clipping rectangle
- 283, // y of the top/left point of clipping rectangle
- 555, // width of clipping reactangle
- 316, // height of clipping reactangle
- 0,//DPIx
- 0,//DPIy
- FpdfRotation.Rotate0, // no rotation
- RenderFlags.None // no render flags
- ))
- {
- }
- }
获取PDF内文字:
- var pathPdf = "./Pdfium.NetTests/resources/text_render_mode.pdf";
- using (var doc = PdfDocument.Load(new MemoryStream(File.ReadAllBytes(pathPdf))))
- {
- var text = doc.Pages[0].GetPdfText();
- }
获取PDF指定区域的文字:
- //page: 0,x: 235,y: 238,x1: 327,y1: 287 Text: fill
- var pathPdf = "./Pdfium.NetTests/resources/text_render_mode.pdf";
- using (var doc = PdfDocument.Load(new MemoryStream(File.ReadAllBytes(pathPdf))))
- {
- var text = doc.Pages[0].GetBoundedText(235, 238, 327, 287);
- }
拆分pdf:
- var pathPdf = "./Pdfium.NetTests/resources/viewer_ref.pdf";
- using (var doc = PdfDocument.Load(new MemoryStream(File.ReadAllBytes(pathPdf))))
- {
- for (int i = 0; i < doc.PageCount; i++)
- {
- var doci = doc.GetPDFPage(i);//可多页拆分
- }
- }
合并pdf:
- var pathPdf = "./Pdfium.NetTests/resources/viewer_ref.pdf";
- using (var doc = PdfDocument.Load(new MemoryStream(File.ReadAllBytes(pathPdf))))
- using (var doc1 = PdfDocument.Load(new MemoryStream(File.ReadAllBytes(pathPdf))))
- {
- doc.MergePDF(doc1);
- }
插入pdf:
- var pathPdf = "./Pdfium.NetTests/resources/viewer_ref.pdf";
- var pathPdf1 = "./Pdfium.NetTests/resources/zero_length_stream.pdf";
- using (var doc = PdfDocument.Load(new MemoryStream(File.ReadAllBytes(pathPdf))))
- using (var doc1 = PdfDocument.Load(new MemoryStream(File.ReadAllBytes(pathPdf1))))
- {
- doc.ImportPage(doc1, 1);
- var w = doc1.Pages[0].Width;
- var w1 = doc.Pages[1].Width;
- }
多页pdf合并成1页:
- var pathPdf = "./Pdfium.NetTests/resources/rectangles_multi_pages.pdf";
- using (var doc = PdfDocument.Load(new MemoryStream(File.ReadAllBytes(pathPdf))))
- {
- using (var doc1 = doc.ImportNPagesToOne(612 * 2, 792))
- }
打印:
- var printer = new PdfPrinter("Microsoft Print To PDF");
- //printer.Print(fileName);
- printer.Print(fileName, documentName: "with name");
Pdfium.Net.Free 一个免费的Pdfium的 .net包装器--快速入门的更多相关文章
- 一个免费的、跨平台的、开源音频编辑器Audacity
Audacity 是一个免费的开源程序,用于编辑音频录制.它可在多个平台(windows/linux)上运行.Audacity 基于 GUI,是一个具有多种选项的强大程序.它支持您录制各种类型的声音. ...
- Caf.CMS是一个免费的、 开源,功能齐全的CMS
Caf.CMS(疯狂蚂蚁CMS) 是一个免费的. 开源,功能全面的CMS(内容管理系统).定位CMS也有点狭义呢,因为Caf.CMS是基于国外SmartStore.NET 开源商城源码的基础上改造而成 ...
- 搭建一个免费的,无限流量的Blog----github Pages和Jekyll入门
喜欢写Blog的人,会经历三个阶段. 第一阶段,刚接触Blog,觉得很新鲜,试着选择一个免费空间来写. 第二阶段,发现免费空间限制太多,就自己购买域名和空间,搭建独立博客. 第三阶段,觉得独立博客的管 ...
- 分享一个免费SSL证书申请网站,给网站开启https协议 | 张戈博客
这些天,由于公司的业务需求,接触到了ssl证书和https协议.博客前几篇文章也分享了在WEB服务器上安装SSL证书,为网站开启https协议的教程,感兴趣的童鞋可以前往查看相关文章: <Lin ...
- 一个免费的自动化跨平台测试JavaScript的工具——BrowserSwarm
BrowserSwarm是一个免费工具,能够自动化跨平台测试JavaScript.
- IETester是一个免费的Web浏览器调试工具
功能简介 IETester是一个免费的Web浏览器调试工具,可以模拟出不同的js引擎来帮助程序员设计效果统一的代码.IETester可以在独立的标签页中开启IE5.5.IE6.IE7以及最I新的IE8 ...
- 搭建一个免费的,无限流量的Blog----github Pages和Jekyll入门[zz]
喜欢写Blog的人,会经历三个阶段. 第一阶段,刚接触Blog,觉得很新鲜,试着选择一个免费空间来写. 第二阶段,发现免费空间限制太多,就自己购买域名和空间,搭建独立博客. 第三阶段,觉得独立博客的管 ...
- 一个免费ss网站的数据爬取过程
一个免费ss网站的数据爬取过程 Apr 14, 2019 引言 爬虫整体概况 主要功能方法 绕过DDOS保护(Cloudflare) post中参数a,b,c的解析 post中参数a,b,c的解析 p ...
- 【ghost初级教程】 怎么搭建一个免费的ghost博客
ghost博客系统无疑是这个月最火热的话题之一,这个号称”只为博客“的系统,早在项目开始之初就受到了众人的关注.它使用了当前最火热node.js技术,10月14日发布了V0.3.3版本.江湖传言它将是 ...
- 搭建一个免费的,无限流量的Blog----github Pages和Jekyll入门(转)
转自:http://www.ruanyifeng.com/blog/2012/08/blogging_with_jekyll.html 喜欢写Blog的人,会经历三个阶段. 第一阶段,刚接触Blog, ...
随机推荐
- springboot项目统一封装返回值和异常处理(方式一)
为什么要统一返回值: 在我们做后端应用的时候,前后端分离的情况下,我们经常会定义一个数据格式,通常会包含code,message,data这三个必不可少的信息来方便我们的交流,下面我们直接来看代码pa ...
- SpringCloud学习 系列四、微服务中心 Eureka介绍及创建一个Eureka中心服务
系列导航 SpringCloud学习 系列一. 前言-为什么要学习微服务 SpringCloud学习 系列二. 简介 SpringCloud学习 系列三. 创建一个没有使用springCloud的服务 ...
- Liunx运维(四)-文本处理三剑客:grep、sed、awk
文档目录: 一.grep:文本过滤工具 二.sed:字符流编辑器 三.awk:文本分析工具 ---------------------------------------分割线:正文--------- ...
- 每天学五分钟 Liunx 111 | 存储篇:NFS
NFS NFS(Network File System,网络文件系统),它可以通过网络让不同操作系统,不同机器共享彼此的文件. NFS 分为服务端和客户端.服务端提供共享的文件目录,客户端将该目录挂载 ...
- VUEX 使用学习六 : modules
转载请注明出处: 当Store中存放了非常多非常大的共享数据对象时,应用会变的非常的复杂,Store对象也会非常臃肿,所以Vuex提供了一个Module模块来分隔Store.通过对Vuex中的Stor ...
- spring--AOP通知类型有哪些
Spring AOP(Aspect-Oriented Programming,面向切面编程)提供了五种类型的通知(advice),这些通知定义了切面(aspect)是在目标对象的方法执行的哪个点被应用 ...
- HttpClient获取不到最新的系统代理
默认情况下,HttpClient是默认采用系统代理,但是,如果你在程序运行过程中,手动修改系统代理,对于HttpClient是无效的,它依然会用老的代理去访问. 解决方法 使用下面的代码,你可以自己实 ...
- restful-接口风格
- 2.4G+MCU低功耗二合一芯片SI24R03
2.4G+MCU低功耗二合一芯片SI24R03 1 简介 Si24R03 是一款高度集成的低功耗 SOC 芯片,其集成了基于 RISC-V 核的低功耗 MCU 和 工作在 2.4GHz ISM 频段的 ...
- [转帖]k8s(1.28.2)部署ingress-nginx-controller(1.9.0)
1.部署ingress-nginx-controller 继在三台虚拟机部署k8s后,需要部署ingress-nginx-controller,才能使设置的ingress规则生效. 1.1下载yaml ...