pdfium舍弃v8依赖

Step 3 去除v8依赖

用文本编辑器打开pdfium根目录下的pdfium.gyp文件,找到‘javascript‘及‘jsapi‘依赖(47行左右):

‘dependencies‘: [
        ‘safemath‘,
        ‘fdrm‘,
        ‘fpdfdoc‘,
        ‘fpdfapi‘,
        ‘fpdftext‘,
        ‘formfiller‘,
        ‘fxcodec‘,
        ‘fxcrt‘,
        ‘fxedit‘,
        ‘fxge‘,
        ‘javascript‘,
        ‘jsapi‘,
        ‘pdfwindow‘,
      ],

将其移除并删除对应的工程(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‘,
      ],
    },

‘javascript‘是将pdf js规定的对象嵌入到js引擎中,使得PDF引擎使用的js引擎是标准js的超集。

‘jsapi‘则是导入v8的接口

如果是在windows平台下编译,到这里就可以直接使用gyp生成vs工程了。如果是linux平台的还需要进一步移除源码中对js的引用,均位于

fpdfsdk/src/fsdk_mgr.cpp

文件中。

  • 注释掉第11行的头文件应用
//#include "../include/javascript/IJavaScript.h"
  • 注释掉215行GetJSRuntimeFactory()函数及其引用(235-238)
CJS_RuntimeFactory* GetJSRuntimeFactory()
{
	static CJS_RuntimeFactory s_JSRuntimeFactory;
	return &s_JSRuntimeFactory;
}


	m_pJSRuntimeFactory = NULL;
	m_pJSRuntimeFactory = GetJSRuntimeFactory();
	m_pJSRuntimeFactory->AddRef();
  • 置CPDFDoc_Environment::GetJSRuntime()函数返回NULL
IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime()
{
	/*if(!IsJSInitiated())
		return NULL;
	assert(m_pJSRuntimeFactory);
	if(!m_pJSRuntime)
		m_pJSRuntime = m_pJSRuntimeFactory->NewJSRuntime(this);
	return m_pJSRuntime;*/
	return NULL;
}

OK,前置任务完成!进入编译。

https://zhuanlan.zhihu.com/p/37729756

相关推荐