编译 Pdfium

Windows

代理配置

因为 gclient 不支持设置代理,如没有配置网关代理,可以使用全局透明代理 Windows 下 Mellow,Linux 可用 QV2ray
记得将原来的 git 等代理取消掉,因为 gclient 会用 git

工具下载

  • 工具 python2,gn,ninja,gclinet,git 直接下 prebuilt 丢环境变量即可
  • VS vs installer 勾上 C++桌面开发(+ATLMFC),Windows平台开发 。环境变量可以丢可以不丢,不丢直接用 VS 自带的 command prompt 即可
  • Debugging Tools

The SDK Debugging Tools must also be installed. If the Windows 10 SDK was installed via the Visual Studio installer, then they can be installed by going to: Control Panel → Programs → Programs and Features → Select the “Windows Software Development Kit” → Change → Change → Check “Debugging Tools For Windows” → Change. Or, you can download the standalone SDK installer and use it to install the Debugging Tools.


获取代码

mkdir repo   
cd repo   
gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git   
gclient sync   
cd pdfium

generate build file

  • gn 配置文件
gn args out/Debug #ninja  
gn gen --ide=vs out\Debug #vs
  • 内容
use_goma = false  # Googlers only. Make sure goma is installed and running first.  
is_debug = true  # Enable debugging features.  

# Set true to enable experimental Skia backend.  
pdf_use_skia = false  
# Set true to enable experimental Skia backend (paths only).  
pdf_use_skia_paths = false  

pdf_enable_xfa = true  # Set false to remove XFA support (implies JS support).  
pdf_enable_v8 = true  # Set false to remove Javascript support.  
pdf_is_standalone = true  # Set for a non-embedded build.  
is_component_build = false # Disable component build (Though it should work)  

clang_use_chrome_plugins = false  # Currently must be false.</pre>

fix

  • ERROR at //build/config/win/visual_studio_version.gni:27:7: Script returned non-zero exit code.exec_script("../../vs_toolchain.py", [ "get_toolchain_dir" ], "scope")

解决: set DEPOT_TOOLS_WIN_TOOLCHAIN=0 使用本地Win Toolchian,如无效,手动加到环境变量,重开控制台

  • ERROR at //build/timestamp.gni:31:19: Script returned non-zero exit code.

解决: 使用cmd 重新 sync gclient sync , 貌似是一个powershell 的命令问题。

  • Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Win/clang-n344329-9284abd0-6.tgz <urlopen error [Errno 11004] getaddrinfo failed>

解决:应该是dns劫持问题,ip.sb 上面查一个 commondatastorage.googleapis.com 的 ip, 加到 C:\Windows\System32\drivers\etc\hosts

build

ninja -C out/Debug pdfium_test

Run a test

0c79d441-cf86-45c6-8ecf-fe5cf83d3713.png
e165c86b-fd3e-4db6-9ea4-47483b3bf592.png
Some rights reserved
Except where otherwise noted, content on this page is licensed under a Creative Commons Attribution-ShareAlike 4.0 International license