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 = true # Googlers only. Make sure 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 98When complete the arguments will be stored in `<directory>/args.gn`, and 99GN will automatically use the new arguments to generate build files. 100Should your files fail to generate, please double-check that you have set 101use\_sysroot as indicated above. 102 103## Building the code 104 105You can build the sample program by running: `ninja -C <directory> pdfium_test` 106You can build the entire product (which includes a few unit tests) by running: 107`ninja -C <directory> pdfium_all`. 108 109## Running the sample program 110 111The pdfium\_test program supports reading, parsing, and rasterizing the pages of 112a .pdf file to .ppm or .png output image files (Windows supports two other 113formats). For example: `<directory>/pdfium_test --ppm path/to/myfile.pdf`. Note 114that this will write output images to `path/to/myfile.pdf.<n>.ppm`. 115Run `pdfium_test --help` to see all the options. 116 117## Testing 118 119There are currently several test suites that can be run: 120 121 * pdfium\_unittests 122 * pdfium\_embeddertests 123 * testing/tools/run\_corpus\_tests.py 124 * testing/tools/run\_javascript\_tests.py 125 * testing/tools/run\_pixel\_tests.py 126 127It is possible the tests in the `testing` directory can fail due to font 128differences on the various platforms. These tests are reliable on the bots. If 129you see failures, it can be a good idea to run the tests on the tip-of-tree 130checkout to see if the same failures appear. 131 132### Pixel Tests 133 134If your change affects rendering, a pixel test should be added. Simply add a 135`.in` or `.pdf` file in `testing/resources/pixel` and the pixel runner will 136pick it up at the next run. 137 138Make sure that your test case doesn't have any copyright issues. It should also 139be a minimal test case focusing on the bug that renders the same way in many 140PDF viewers. Try to avoid binary data in streams by using the `ASCIIHexDecode` 141simply because it makes the PDF more readable in a text editor. 142 143To try out your new test, you can call the `run_pixel_tests.py` script: 144 145```bash 146$ ./testing/tools/run_pixel_tests.py your_new_file.in 147``` 148 149To generate the expected image, you can use the `make_expected.sh` script: 150 151```bash 152$ ./testing/tools/make_expected.sh your_new_file.pdf 153``` 154 155Please make sure to have `optipng` installed which optimized the file size of 156the resulting png. 157 158### `.in` files 159 160`.in` files are PDF template files. PDF files contain many byte offsets that 161have to be kept correct or the file won't be valid. The template makes this 162easier by replacing the byte offsets with certain keywords. 163 164This saves space and also allows an easy way to reduce the test case to the 165essentials as you can simply remove everything that is not necessary. 166 167A simple example can be found [here](https://pdfium.googlesource.com/pdfium/+/refs/heads/main/testing/resources/rectangles.in). 168 169To transform this into a PDF, you can use the `fixup_pdf_template.py` tool: 170 171```bash 172$ ./testing/tools/fixup_pdf_template.py your_file.in 173``` 174 175This will create a `your_file.pdf` in the same directory as `your_file.in`. 176 177There is no official style guide for the .in file, but a consistent style is 178preferred simply to help with readability. If possible, object numbers should 179be consecutive and `/Type` and `/SubType` should be on top of a dictionary to 180make object identification easier. 181 182## Embedding PDFium in your own projects 183 184The public/ directory contains header files for the APIs available for use by 185embedders of PDFium. The PDFium project endeavors to keep these as stable as 186possible. 187 188Outside of the public/ directory, code may change at any time, and embedders 189should not directly call these routines. 190 191## Code Coverage 192 193Code coverage reports for PDFium can be generated in Linux development 194environments. Details can be found [here](/docs/code-coverage.md). 195 196Chromium provides code coverage reports for PDFium 197[here](https://chromium-coverage.appspot.com/). PDFium is located in 198`third_party/pdfium` in Chromium's source code. 199This includes code coverage from PDFium's fuzzers. 200 201## Waterfall 202 203The current health of the source tree can be found 204[here](https://ci.chromium.org/p/pdfium/g/main/console). 205 206## Community 207 208There are several mailing lists that are setup: 209 210 * [PDFium](https://groups.google.com/forum/#!forum/pdfium) 211 * [PDFium Reviews](https://groups.google.com/forum/#!forum/pdfium-reviews) 212 * [PDFium Bugs](https://groups.google.com/forum/#!forum/pdfium-bugs) 213 214Note, the Reviews and Bugs lists are typically read-only. 215 216## Bugs 217 218PDFium uses this [bug tracker](https://bugs.chromium.org/p/pdfium/issues/list), 219but for security bugs, please use 220[Chromium's security bug template](https://bugs.chromium.org/p/chromium/issues/entry?template=Security%20Bug) 221and add the "Cr-Internals-Plugins-PDF" label. 222 223## Contributing code 224 225See the [CONTRIBUTING](CONTRIBUTING.md) document for more information on 226contributing to the PDFium project. 227