1# PDFium 2 3## Prerequisites 4 5PDFium uses the same build tooling as Chromium. See the platform-specific 6Chromium build instructions to get started, but replace Chromium's 7"Get the code" instructions with [PDFium's](#get-the-code). 8 9* [Chromium Linux build instructions](https://chromium.googlesource.com/chromium/src/+/main/docs/linux/build_instructions.md) 10* [Chromium Mac build instructions](https://chromium.googlesource.com/chromium/src/+/main/docs/mac_build_instructions.md) 11* [Chromium Windows build instructions](https://chromium.googlesource.com/chromium/src/+/main/docs/windows_build_instructions.md) 12 13### CPU Architectures supported 14 15The default architecture for Windows, Linux, and Mac is "`x64`". On Windows, 16"`x86`" is also supported. GN parameter "`target_cpu = "x86"`" can be used to 17override the default value. If you specify Android build, the default CPU 18architecture will be "`arm`". 19 20It is expected that there are still some places lurking in the code which will 21not function properly on big-endian architectures. Bugs and/or patches are 22welcome, however providing this support is **not** a priority at this time. 23 24#### Google employees 25 26Run: `download_from_google_storage --config` and follow the 27authentication instructions. **Note that you must authenticate with your 28@google.com credentials**. Enter "0" if asked for a project-id. 29 30Once you've done this, the toolchain will be installed automatically for 31you in the [Generate the build files](#generate-the-build-files) step below. 32 33The toolchain will be in `depot_tools\win_toolchain\vs_files\<hash>`, and 34windbg can be found in 35`depot_tools\win_toolchain\vs_files\<hash>\win_sdk\Debuggers`. 36 37If you want the IDE for debugging and editing, you will need to install 38it separately, but this is optional and not needed for building PDFium. 39 40## Get the code 41 42The name of the top-level directory does not matter. In the following example, 43the directory name is "repo". This directory must not have been used before by 44`gclient config` as each directory can only house a single gclient 45configuration. 46 47``` 48mkdir repo 49cd repo 50gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git 51gclient sync 52cd pdfium 53``` 54 55On Linux, additional build dependencies need to be installed by running the 56following from the `pdfium` directory. 57 58``` 59./build/install-build-deps.sh 60``` 61 62## Generate the build files 63 64PDFium uses GN to generate the build files and [Ninja](https://ninja-build.org/) 65to execute the build files. Both of these are included with the 66depot\_tools checkout. 67 68### Selecting build configuration 69 70PDFium may be built either with or without JavaScript support, and with 71or without XFA forms support. Both of these features are enabled by 72default. Also note that the XFA feature requires JavaScript. 73 74Configuration is done by executing `gn args <directory>` to configure the build. 75This will launch an editor in which you can set the following arguments. 76By convention, `<directory>` should be named `out/foo`, and some tools / test 77support code only works if one follows this convention. 78A typical `<directory>` name is `out/Debug`. 79 80``` 81use_goma = false # Googlers only. Ensure goma is installed and running first. 82is_debug = true # Enable debugging features. 83 84# Set true to enable experimental Skia backend. 85pdf_use_skia = false 86 87pdf_enable_xfa = true # Set false to remove XFA support (implies JS support). 88pdf_enable_v8 = true # Set false to remove Javascript support. 89pdf_is_standalone = true # Set for a non-embedded build. 90is_component_build = false # Disable component build (Though it should work) 91``` 92 93For sample applications like `pdfium_test` to build, one must set 94`pdf_is_standalone = true`. 95 96By default, the entire project builds with C++17. 97 98By default, PDFium expects to build with a clang compiler that provides 99additional chrome plugins. To build against a vanilla one lacking these, 100one must set 101`clang_use_chrome_plugins = false`. 102 103When complete the arguments will be stored in `<directory>/args.gn`, and 104GN will automatically use the new arguments to generate build files. 105Should your files fail to generate, please double-check that you have set 106use\_sysroot as indicated above. 107 108## Building the code 109 110You can build the sample program by running: `ninja -C <directory> pdfium_test` 111You can build the entire product (which includes a few unit tests) by running: 112`ninja -C <directory> pdfium_all`. 113 114## Running the sample program 115 116The pdfium\_test program supports reading, parsing, and rasterizing the pages of 117a .pdf file to .ppm or .png output image files (Windows supports two other 118formats). For example: `<directory>/pdfium_test --ppm path/to/myfile.pdf`. Note 119that this will write output images to `path/to/myfile.pdf.<n>.ppm`. 120Run `pdfium_test --help` to see all the options. 121 122## Testing 123 124There are currently several test suites that can be run: 125 126 * pdfium\_unittests 127 * pdfium\_embeddertests 128 * testing/tools/run\_corpus\_tests.py 129 * testing/tools/run\_javascript\_tests.py 130 * testing/tools/run\_pixel\_tests.py 131 132It is possible the tests in the `testing` directory can fail due to font 133differences on the various platforms. These tests are reliable on the bots. If 134you see failures, it can be a good idea to run the tests on the tip-of-tree 135checkout to see if the same failures appear. 136 137### Pixel Tests 138 139If your change affects rendering, a pixel test should be added. Simply add a 140`.in` or `.pdf` file in `testing/resources/pixel` and the pixel runner will 141pick it up at the next run. 142 143Make sure that your test case doesn't have any copyright issues. It should also 144be a minimal test case focusing on the bug that renders the same way in many 145PDF viewers. Try to avoid binary data in streams by using the `ASCIIHexDecode` 146simply because it makes the PDF more readable in a text editor. 147 148To try out your new test, you can call the `run_pixel_tests.py` script: 149 150```bash 151$ ./testing/tools/run_pixel_tests.py your_new_file.in 152``` 153 154To generate the expected image, you can use the `make_expected.sh` script: 155 156```bash 157$ ./testing/tools/make_expected.sh your_new_file.pdf 158``` 159 160Please make sure to have `optipng` installed which optimized the file size of 161the resulting png. 162 163### `.in` files 164 165`.in` files are PDF template files. PDF files contain many byte offsets that 166have to be kept correct or the file won't be valid. The template makes this 167easier by replacing the byte offsets with certain keywords. 168 169This saves space and also allows an easy way to reduce the test case to the 170essentials as you can simply remove everything that is not necessary. 171 172A simple example can be found [here](https://pdfium.googlesource.com/pdfium/+/refs/heads/main/testing/resources/rectangles.in). 173 174To transform this into a PDF, you can use the `fixup_pdf_template.py` tool: 175 176```bash 177$ ./testing/tools/fixup_pdf_template.py your_file.in 178``` 179 180This will create a `your_file.pdf` in the same directory as `your_file.in`. 181 182There is no official style guide for the .in file, but a consistent style is 183preferred simply to help with readability. If possible, object numbers should 184be consecutive and `/Type` and `/SubType` should be on top of a dictionary to 185make object identification easier. 186 187## Embedding PDFium in your own projects 188 189The public/ directory contains header files for the APIs available for use by 190embedders of PDFium. The PDFium project endeavors to keep these as stable as 191possible. 192 193Outside of the public/ directory, code may change at any time, and embedders 194should not directly call these routines. 195 196## Code Coverage 197 198Code coverage reports for PDFium can be generated in Linux development 199environments. Details can be found [here](/docs/code-coverage.md). 200 201Chromium provides code coverage reports for PDFium 202[here](https://chromium-coverage.appspot.com/). PDFium is located in 203`third_party/pdfium` in Chromium's source code. 204This includes code coverage from PDFium's fuzzers. 205 206## Waterfall 207 208The current health of the source tree can be found 209[here](https://ci.chromium.org/p/pdfium/g/main/console). 210 211## Community 212 213There are several mailing lists that are setup: 214 215 * [PDFium](https://groups.google.com/forum/#!forum/pdfium) 216 * [PDFium Reviews](https://groups.google.com/forum/#!forum/pdfium-reviews) 217 * [PDFium Bugs](https://groups.google.com/forum/#!forum/pdfium-bugs) 218 219Note, the Reviews and Bugs lists are typically read-only. 220 221## Bugs 222 223PDFium uses this [bug tracker](https://bugs.chromium.org/p/pdfium/issues/list), 224but for security bugs, please use 225[Chromium's security bug template](https://bugs.chromium.org/p/chromium/issues/entry?template=Security%20Bug) 226and add the "Cr-Internals-Plugins-PDF" label. 227 228## Contributing code 229 230See the [CONTRIBUTING](CONTRIBUTING.md) document for more information on 231contributing to the PDFium project. 232