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包装器--快速入门的更多相关文章

  1. 一个免费的、跨平台的、开源音频编辑器Audacity

    Audacity 是一个免费的开源程序,用于编辑音频录制.它可在多个平台(windows/linux)上运行.Audacity 基于 GUI,是一个具有多种选项的强大程序.它支持您录制各种类型的声音. ...

  2. Caf.CMS是一个免费的、 开源,功能齐全的CMS

    Caf.CMS(疯狂蚂蚁CMS) 是一个免费的. 开源,功能全面的CMS(内容管理系统).定位CMS也有点狭义呢,因为Caf.CMS是基于国外SmartStore.NET 开源商城源码的基础上改造而成 ...

  3. 搭建一个免费的,无限流量的Blog----github Pages和Jekyll入门

    喜欢写Blog的人,会经历三个阶段. 第一阶段,刚接触Blog,觉得很新鲜,试着选择一个免费空间来写. 第二阶段,发现免费空间限制太多,就自己购买域名和空间,搭建独立博客. 第三阶段,觉得独立博客的管 ...

  4. 分享一个免费SSL证书申请网站,给网站开启https协议 | 张戈博客

    这些天,由于公司的业务需求,接触到了ssl证书和https协议.博客前几篇文章也分享了在WEB服务器上安装SSL证书,为网站开启https协议的教程,感兴趣的童鞋可以前往查看相关文章: <Lin ...

  5. 一个免费的自动化跨平台测试JavaScript的工具——BrowserSwarm

    BrowserSwarm是一个免费工具,能够自动化跨平台测试JavaScript.

  6. IETester是一个免费的Web浏览器调试工具

    功能简介 IETester是一个免费的Web浏览器调试工具,可以模拟出不同的js引擎来帮助程序员设计效果统一的代码.IETester可以在独立的标签页中开启IE5.5.IE6.IE7以及最I新的IE8 ...

  7. 搭建一个免费的,无限流量的Blog----github Pages和Jekyll入门[zz]

    喜欢写Blog的人,会经历三个阶段. 第一阶段,刚接触Blog,觉得很新鲜,试着选择一个免费空间来写. 第二阶段,发现免费空间限制太多,就自己购买域名和空间,搭建独立博客. 第三阶段,觉得独立博客的管 ...

  8. 一个免费ss网站的数据爬取过程

    一个免费ss网站的数据爬取过程 Apr 14, 2019 引言 爬虫整体概况 主要功能方法 绕过DDOS保护(Cloudflare) post中参数a,b,c的解析 post中参数a,b,c的解析 p ...

  9. 【ghost初级教程】 怎么搭建一个免费的ghost博客

    ghost博客系统无疑是这个月最火热的话题之一,这个号称”只为博客“的系统,早在项目开始之初就受到了众人的关注.它使用了当前最火热node.js技术,10月14日发布了V0.3.3版本.江湖传言它将是 ...

  10. 搭建一个免费的,无限流量的Blog----github Pages和Jekyll入门(转)

    转自:http://www.ruanyifeng.com/blog/2012/08/blogging_with_jekyll.html 喜欢写Blog的人,会经历三个阶段. 第一阶段,刚接触Blog, ...

随机推荐

  1. OJ中的语言选项里G++ 与 C++的区别

    概念上: C++是一门计算机编程语言,而G++则是C++的编译器. GCC和G++都是GUN的编译器,cc是Unix系统的C Compiler,而gcc则是GNU Compiler Collectio ...

  2. Codeforces Round #618 (Div. 2) A~E

    原作者为 RioTian@cnblogs, 本作品采用 CC 4.0 BY 进行许可,转载请注明出处. 1300A. Non-zero 题意:给你一个数组,每次操作你可以使其中任意元素的值+1,问最少 ...

  3. C#设计模式16——中介者模式的写法

    是什么: 中介者模式是一种行为型设计模式,它定义了一个中介者对象来封装一系列对象之间的交互.中介者模式可以使得对象间的交互更加松耦合,避免了对象之间的直接依赖,从而使系统更加灵活.易于扩展和维护. 为 ...

  4. mybatis plus 主键策略

    博主原创,转载请注明出处: mybatis plus 对实体类映射表的主键做了注解支持,该注解为 @TableId ,如果不使用该注解,mybatis plus 默认主键生成的策略是内部封装的雪花算法 ...

  5. 【C/C++】知识点笔记

    1 - 联合体内嵌结构体初始化赋值 union { struct { int i; float f; char *p; }; int o; } obj3 = { 1, 2.2, "sk&qu ...

  6. JMS微服务架构 - 关于事务提交失败,自动重新提交的机制

    用JMS编写的微服务,由调用端决定了各个微服务执行时,是否需要保持事务的一致性. 也就是RemoteClient在调用微服务方法前,先调用BeginTransaction明确后面所调用的微服务需要保持 ...

  7. Git-历史版本切换-log-reset

  8. [转帖]MySQL如何进行索引重建操作?

    MySQL如何进行索引重建操作? - 潇湘隐者 - 博客园 (cnblogs.com) 在MySQL数据库中,没有类似于SQL Server数据库或Oracle数据库中索引重建的语法(ALTER IN ...

  9. [转帖]数据库连接池选型 Druid vs HikariCP性能对比

    这里主要比较HikariCP 和阿里的Druid springboot 现在官方默认的数据库连接池是 HikariCP,HikariCP的性能从测试的数据上来看也是最高的. 先来看下这个著名的issu ...

  10. [转帖]Web技术(六):QUIC 是如何解决TCP 性能瓶颈的?

    文章目录 一.QUIC 如何解决TCP的队头阻塞问题? 1.1 TCP 为何会有队头阻塞问题 1.2 QUIC 如何解决队头阻塞问题 1.3 QUIC 没有队头阻塞的多路复用 二.QUIC 如何优化T ...