最近想试一下解析pdf文件,去查了查资料,发现别人编译好的dll我这里用不了
最终自己想试一下编译
此过程不需要科学上网
我的本地环境
由于拉的是github上的源码,看其文件是.gyp,于是乎需要安装gyp构建工具。
我用的是anaconda,其python环境是3.x。报错了半天才知道是版本原因:
安装gyp依赖于pthony2.xx,需重新配置一边2.7的环境
添加环境变量
clone:https://github.com/bnoordhuis/gyp
cmd命令提示符进入下载好的gyp目录,执行安装命令:
python setup.py install
执行以下命令查看是否安装成功
pip list
如果输出中有gyp则安装成功
clone:https://github.com/PDFium/PDFium
我本地没有javascript的环境,如果不去除的话还要科学上网编译V8。
打开下载好的pdfium根目录,找到pdfium.gyp,最好用notpad打开。
找到 ' javascript ' 及 ' jsapi ' 依赖(约在45行左右),去掉
移除对应的工程(约在734行至812行):
{
'target_name': 'javascript',
'type': 'static_library',
'include_dirs': [
'<(DEPTH)/v8',
'<(DEPTH)/v8/include',
],
'dependencies': [
'<(DEPTH)/v8/tools/gyp/v8.gyp:v8',
'<(DEPTH)/v8/tools/gyp/v8.gyp:v8_libplatform',
],
'export_dependent_settings': [
'<(DEPTH)/v8/tools/gyp/v8.gyp:v8',
],
'ldflags': [ '-L<(PRODUCT_DIR)',],
'sources': [
'fpdfsdk/include/javascript/app.h',
'fpdfsdk/include/javascript/color.h',
'fpdfsdk/include/javascript/console.h',
'fpdfsdk/include/javascript/Consts.h',
'fpdfsdk/include/javascript/Document.h',
'fpdfsdk/include/javascript/event.h',
'fpdfsdk/include/javascript/Field.h',
'fpdfsdk/include/javascript/global.h',
'fpdfsdk/include/javascript/Icon.h',
'fpdfsdk/include/javascript/IJavaScript.h',
'fpdfsdk/include/javascript/JavaScript.h',
'fpdfsdk/include/javascript/JS_Console.h',
'fpdfsdk/include/javascript/JS_Context.h',
'fpdfsdk/include/javascript/JS_Define.h',
'fpdfsdk/include/javascript/JS_EventHandler.h',
'fpdfsdk/include/javascript/JS_GlobalData.h',
'fpdfsdk/include/javascript/JS_Module.h',
'fpdfsdk/include/javascript/JS_Object.h',
'fpdfsdk/include/javascript/JS_Runtime.h',
'fpdfsdk/include/javascript/JS_Value.h',
'fpdfsdk/include/javascript/PublicMethods.h',
'fpdfsdk/include/javascript/report.h',
'fpdfsdk/include/javascript/resource.h',
'fpdfsdk/include/javascript/util.h',
'fpdfsdk/src/javascript/app.cpp',
'fpdfsdk/src/javascript/color.cpp',
'fpdfsdk/src/javascript/console.cpp',
'fpdfsdk/src/javascript/Consts.cpp',
'fpdfsdk/src/javascript/Document.cpp',
'fpdfsdk/src/javascript/event.cpp',
'fpdfsdk/src/javascript/Field.cpp',
'fpdfsdk/src/javascript/global.cpp',
'fpdfsdk/src/javascript/Icon.cpp',
'fpdfsdk/src/javascript/JS_Context.cpp',
'fpdfsdk/src/javascript/JS_EventHandler.cpp',
'fpdfsdk/src/javascript/JS_GlobalData.cpp',
'fpdfsdk/src/javascript/JS_Object.cpp',
'fpdfsdk/src/javascript/JS_Runtime.cpp',
'fpdfsdk/src/javascript/JS_Value.cpp',
'fpdfsdk/src/javascript/PublicMethods.cpp',
'fpdfsdk/src/javascript/report.cpp',
'fpdfsdk/src/javascript/util.cpp',
],
},
{
'target_name': 'jsapi',
'type': 'static_library',
'dependencies': [
'<(DEPTH)/v8/tools/gyp/v8.gyp:v8',
],
'export_dependent_settings': [
'<(DEPTH)/v8/tools/gyp/v8.gyp:v8',
],
'include_dirs': [
'<(DEPTH)/v8',
'<(DEPTH)/v8/include',
],
'ldflags': [ '-L<(PRODUCT_DIR)',],
'sources': [
'fpdfsdk/include/jsapi/fxjs_v8.h',
'fpdfsdk/src/jsapi/fxjs_v8.cpp',
],
},
cmd命令提示符进入pdfium/build目录
执行命令:
python gyp_pdfium.py
可以看到生成了all.sln
用vs2010打开:
右键All,点击生成即可进行编译
由于我们舍弃了V8,pdfium_test是编译不了的,所有的javascript有关的函数都不能用,pdf中好像表单是使用V8来渲染的。
用2010编译好以上几个项目后,会在build/Debug/lib目录下看到生成好的lib库
于是新建一个项目,将pdfium_test.cc中的代码复制过来,注释有关V8的函数,以及FPDFDOC_InitFormFillEnviroument()函数和与之所有相关的函数。
将这几个lib库连接进来,引入相关的头文件
编译好之后,不能直接启动
要用命令启动:
输入一个xxx.pdf
就跑了一遍显示12页,
再看代码,显示有个bmp命令,于是乎输入命令:
pdfdemo xxx.pdf --bmp
可以在当前目录看到pdf中所有的图片都被输出来了:
其它操作到时候再试
已经构建好的代码下载:
链接: https://pan.baidu.com/s/11C_UUe-nOfL3IWUgzODoWA 提取码: hpbb
(只支持window平台,只能以32位编译)
用VS2010打开PDFium\build\all.sln 编译即可