#include "fpdfview.h"
#include <iostream>
#include <string>
#include <string.h>
// #include "opencv2/opencv.hpp"
const char* icudt64_dat ="/data2/jesse/work/pdfium/repo/icudtl.dat2";
int main(int argc, char* argv[]) { // FPDF_InitLibrary();
const char* fonts[] = {
"../fonts/",
NULL
};
FPDF_LIBRARY_CONFIG config;
config.m_pUserFontPaths = fonts;
config.version = ;
config.m_pIsolate = NULL;
config.m_v8EmbedderSlot = ;
FPDF_InitLibraryWithConfig(&config);
char* path = "../sample/test.pdf";
if (argc > ) {
path = argv[];
} FPDF_DOCUMENT doc = FPDF_LoadDocument(path, );
if (doc) {
int page_count = FPDF_GetPageCount(doc);
std::cout << "page count " << page_count << std::endl;
for (int p = ; p < page_count; p++) {
FPDF_PAGE page = FPDF_LoadPage(doc, p);
if (page) {
// 物理尺寸 每英寸72点
double pwidth = FPDF_GetPageWidth(page);
double pheight = FPDF_GetPageHeight(page);
// 150ppi 下的像素尺寸
int width = (int)(pwidth)* / ;
int height = (int)(pheight)* / ;
std::cout << "\t" << p << " (" << width << "," << height << ")" << std::endl;
// BGRx/BGRA 4通道
FPDF_BITMAP bmp = FPDFBitmap_Create(width, height, );
// BGR 3通道
// FPDF_BITMAP bmp = FPDFBitmap_CreateEx(width, height, FPDFBitmap_BGR,NULL,0);
uint8_t* ptr = (uint8_t*)FPDFBitmap_GetBuffer(bmp);
//设置画板白色背景
memset(ptr,,width*height*);
FPDF_RenderPageBitmap(bmp, page, , , width, height, , );
std::string name = "page" + std::to_string(p) + ".ppm";
FILE* fp = fopen(name.c_str(), "wb");
fprintf(fp, "P6\n%d %d\n255\n", width, height); uint8_t* dst = (uint8_t*)malloc(width * height * );
uint8_t* dptr = dst;
for (int y = ; y < height; y++) {
for (int x = ; x < width; x++) {// BGR->RGB
*dst++ = (ptr[]);// * ptr[3] + 255 * (255 - ptr[3])) / 255;
*dst++ = (ptr[]);// * ptr[3] + 255 * (255 - ptr[3])) / 255;
*dst++ = (ptr[]);// * ptr[3] + 255 * (255 - ptr[3])) / 255;
ptr += ;
}
}
fwrite(dptr, width * , height, fp);
fclose(fp);
free(dptr);
FPDFBitmap_Destroy(bmp);
FPDF_ClosePage(page);
}
}
FPDF_CloseDocument(doc);
} FPDF_DestroyLibrary();
return ;
}

https://github.com/xinyu391/pdfium_with_cmake/blob/74baec0ae113f9deeaccd9a556c1fefa69df6425/demo.cpp

pdfium ppm demo的更多相关文章

  1. PDFium 渲染

    PDFium 是 Chromium 的 PDF 渲染引擎,许可协议为 BSD 3-Clause.不同于 Mozilla 基于 HTML5 的 PDF.js,PDFium 是基于 Foxit Softw ...

  2. 通过一个demo了解Redux

    TodoList小demo 效果展示 项目地址 (单向)数据流 数据流是我们的行为与响应的抽象:使用数据流能帮我们明确了行为对应的响应,这和react的状态可预测的思想是不谋而合的. 常见的数据流框架 ...

  3. 很多人很想知道怎么扫一扫二维码就能打开网站,就能添加联系人,就能链接wifi,今天说下这些格式,明天做个demo

    有些功能部分手机不能使用,网站,通讯录,wifi基本上每个手机都可以使用. 在看之前你可以扫一扫下面几个二维码先看看效果: 1.二维码生成 网址 (URL) 包含网址的 二维码生成 是大家平时最常接触 ...

  4. 在线浏览PDF之PDF.JS (附demo)

    平台之大势何人能挡? 带着你的Net飞奔吧!:http://www.cnblogs.com/dunitian/p/4822808.html#skill 下载地址:http://mozilla.gith ...

  5. 【微框架】Maven +SpringBoot 集成 阿里大鱼 短信接口详解与Demo

    Maven+springboot+阿里大于短信验证服务 纠结点:Maven库没有sdk,需要解决 Maven打包找不到相关类,需要解决 ps:最近好久没有写点东西了,项目太紧,今天来一篇 一.本文简介 ...

  6. vue双向数据绑定原理探究(附demo)

    昨天被导师叫去研究了一下vue的双向数据绑定原理...本来以为原理的东西都非常高深,没想到vue的双向绑定真的很好理解啊...自己动手写了一个. 传送门 双向绑定的思想 双向数据绑定的思想就是数据层与 ...

  7. Android Studio-—使用OpenCV的配置方法和demo以及开发过程中遇到的问题解决

    前提: 1.安装Android Studio(过程略) 2.官网下载OpenCV for Android 网址:http:opencv.org/downloads.html 我下载的是下图的版本 3. ...

  8. iOS之ProtocolBuffer搭建和示例demo

    这次搭建iOS的ProtocolBuffer编译器和把*.proto源文件编译成*.pbobjc.h 和 *.pbobjc.m文件时,碰到不少问题! 搭建pb编译器到时没有什么问题,只是在把*.pro ...

  9. 钉钉开放平台demo调试异常问题解决:hostname in certificate didn't match

    今天研究钉钉的开放平台,结果一个demo整了半天,这帮助系统写的也很难懂.遇到两个问题: 1.首先是执行demo时报unable to find valid certification path to ...

随机推荐

  1. 工作日志,证书无效 unable to find valid certification path to requested target

    工作日志,证书无效 unable to find valid certification path to requested target 最近被这个问题弄得头大.导致所有用到 se.transmod ...

  2. Octave中的矩阵操作

    >> a=[1 2;3 4;5 6];>> b=ones(2,3)b = 1 1 1 1 1 1 >> a*b 矩阵的乘法ans = 3 3 3 7 7 7 11 ...

  3. npm --save-dev 和 --save 的区别

    转载 >>> 1. npm install 在安装 npm 包时,有两种命令参数可以把它们的信息写入 package.json 文件, 一个是npm install--save    ...

  4. 元数据MetaData(五)

    JDBC的元数据接口有: DatabaseMetaData数据库级 ResultSetMetaData结果集级 一.DatabaseMetaData 在对数据源进行连接以后,得到一个Connectio ...

  5. WPF 绑定属性 XAML 时间格式化

    原文:WPF 绑定属性 XAML 时间格式化 XAML 时间格式化{Binding Birthday,StringFormat='yyyy-MM-dd '} public class AssetCla ...

  6. 打包一个python解释器

    利用python的exec语句,可以很方便地动态执行python语句.如果一个python代码打包为了exe,其原先的代码就很难更改了.一个好的解决方法就是import相应的库,然后把主程序段放到一个 ...

  7. oracle查询字段重复数据

    select in_ordr_no,count(*) from t_pay_jnl group by in_ordr_no having count(*) > 按照字段in_ordr_no查询重 ...

  8. Codechef November Challenge 2019 Division 1

    Preface 这场CC好难的说,后面的都不会做QAQ 还因为不会三进制位运算卷积被曲明姐姐欺负了,我真是太菜了QAQ PS:最后还是狗上了六星的说,期待两(三)场之内可以上七星 Physical E ...

  9. 一个python问题引发的思考

    问题: pyqt5下开发的时候,遇到了一个这样的问题.Traceback (most recent call last):File “test.py”, line 3, in from PyQt5.Q ...

  10. spring cloud 2.x版本 Gateway路由网关教程

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...