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. 项目2 可视化数据(第17章 使用API)

    17.1 使用Web API Web API是网站的一部分,用于与使用非常具体的URL请求特定信息的程序交互.这种请求称为API调用.请求的数据将以易于处理的格式(如JSON或CSV)返回. 17.1 ...

  2. 三、springboot集成金仓数据库

    系列导航 一.金仓数据库搭建(单机) 二.金仓数据库搭建(主从安装) 三.springboot集成金仓数据库 1.数据库中创建表 CREATE TABLE TEST_BLOCK_T ( BLOCK_I ...

  3. S3C2440移植uboot之支持NANDFLASH操作

      上一节我们移植了uboot,S3C2440移植uboot之支持NORFLASH.这节我们继续移植,支持NANDFLASH. 目录 编译报错 拷贝s3c2410_nand.c,修改宏定义支持SC32 ...

  4. 真实感渲染:WebGPU介绍和使用光栅化管线绘制一个三角形

    大家好~本课程为"真实感渲染"的线上课程,从0开始,介绍相关的图形学算法和数学基础,给出详细的数学推导.伪代码和实现代码,最终带领大家开发出基于物理的渲染器 线上课程资料: 本节课 ...

  5. 项目API请求模块封装

  6. SpringBoot RabbitMQ 实战

    RabbitMQ RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件).RabbitMQ服务器是用Erlang语言编写的,而集群和故障转移是构建在开放电信平台 ...

  7. JS单线程的理解

    一.首先需要区分几个概念: 1. 进程和线程的概念: 进程:指在系统中运行的一个应用程序,目的就是担当分配系统资源(CPU时间.内存等)的基本单位 线程:系统分配处理器时间资源的基本单元,建立在进程的 ...

  8. Liunx运维(四)-文本处理三剑客:grep、sed、awk

    文档目录: 一.grep:文本过滤工具 二.sed:字符流编辑器 三.awk:文本分析工具 ---------------------------------------分割线:正文--------- ...

  9. 使用 Woodpecker 与 Gitea 搭建纯开源的 CI 流程|极限降本

    最近开源了一个挂机冒险游戏<模拟龙生>,有热心同学不仅帮忙做优化,还连夜在给游戏加页面,泪目.详见文末小结部分. 一.前言 大家好,这里是白泽.这篇文章是<Woodpecker CI ...

  10. chorm如何静音特定网页

    如图所示,右键想要静音的网页标签,选择将这个网页静音即可