#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

最新文章

  1. 【JAVA并发编程实战】10、并发程序的测试
  2. Linux(CentOs6.4)安装Git
  3. 精通Web Analytics 2.0 (6) 第四章:点击流分析的奇妙世界:实际的解决方案
  4. Djunit工作记录Mock时出现为null的情况setReturnValueAt|MockObjectManager.addReturnValue不起作用
  5. RaphaelJS实践--猫和老鼠矢量图展示
  6. appserver安装常见的问题
  7. iOS-Gdata XML解析配置和简单使用
  8. 【转载】理解OAuth 2.0
  9. Win2003+iis6部署MVC4网站的方法
  10. SQL Server 扩展事件(Extented Events)从入门到进阶(1)——从SQL Trace到Extented Events
  11. java多线程的实现的两种方法
  12. HDU 3415 Max Sum of Max-K-sub-sequence 最长K子段和
  13. RadioGroup+TabHost
  14. DOS日期和时间 - Robin Hu的专栏 - 博客频道 - CSDN.NET
  15. Servlet中进行context属性的同步
  16. RabbitMQ的应用场景以及基本原理简介
  17. 【CH6802】车的放置
  18. thread join和detach的区别
  19. 在windows server 2008 R2 64bit上面配置PI OPC Server的DCOM
  20. 关于vc工程包含多个lib库老是提示无法打开问题

热门文章

  1. gcc 4.9 编译安装 in Ubuntu 18.04(主要用于在无root权限下,进行更新系统 gcc 版本)
  2. Linux-3.14.12内存管理笔记【构建内存管理框架(2)】
  3. 关于Linux下进程的详解【进程查看与管理】
  4. 008.MongoDB分片群集概念及原理
  5. May 26th, 2019. Week 22nd, Sunday
  6. Fiddler应用——Fiddler过滤功能
  7. golang中的pflag示例
  8. Mac--管理mysql、redis服务的常用命令
  9. 使用OC实现单链表:创建、删除、插入、查询、遍历、反转、合并、判断相交、求成环入口
  10. Leetcode练习题Longest Common Prefix