TL;DR In the latest release of our PDF library JPedal, we added Brotli support to our PDF Manipulator. Brotli is a recent addition to the PDF format, so older PDF viewers may not be able to open files which use it. You can now detect whether a PDF file contains any Brotli encoded streams, convert those streams to Flate so older viewers can read them, and write new streams using Brotli.
Contents:
- What is Brotli?
- Detect Brotli streams in a PDF file
- Convert Brotli streams to Flate
- Write Brotli encoded streams
- Using the command line
- Add Brotli compression support in Java
- FAQ
What is Brotli?
Most of the data in a PDF file lives inside streams, such as page content streams, fonts and images. These streams are usually compressed, and the /Filter entry in the stream dictionary tells the reader how to decompress them. For a long time the ‘default’ filter has been Flate (/FlateDecode), which uses the same Deflate algorithm as zip files.
Brotli is a compression algorithm originally built for the web (you may have come across it in WOFF2 web fonts) which generally compresses better than Deflate. The PDF Association has now added Brotli to PDF 2.0 as an optional alternative to Flate, using the /BrotliDecode filter. It is particularly good at shrinking text-heavy data like fonts and content streams.
JPedal has been able to read Brotli compressed streams since our 2026.05 release, so these files open, render and convert just like any other PDF. There is a catch though. Brotli is a recent addition to the PDF format, so older PDF viewers may not be able to open files which use it! That is where the new features come in.
Detect Brotli streams in a PDF file
If you are receiving PDF files from other people, you might want to know whether they contain any Brotli before you pass them on. You can check this with containsBrotli(), which returns true if any stream in the document is encoded with Brotli.
final PdfManipulator pdf = new PdfManipulator();
pdf.loadDocument(new File("inputFile.pdf"));
final boolean hasBrotli = pdf.containsBrotli();
pdf.closeDocument();
Convert Brotli streams to Flate
To make a file readable by viewers which do not support Brotli, you can use removeBrotli(). This converts every Brotli encoded stream in the document to Flate.
final PdfManipulator pdf = new PdfManipulator();
pdf.loadDocument(new File("inputFile.pdf"));
pdf.removeBrotli();
pdf.apply();
pdf.writeDocument(new File("outputFile.pdf"));
pdf.closeDocument();
If that is the only thing you need to do to the file, there is also a static method which does it in one line:
PdfManipulator.removeBrotli(new File("inputFile.pdf"), new File("outputFile.pdf"));
You do not need to call containsBrotli() first, as removeBrotli() will return silently if the document does not contain any Brotli streams. Flate is always used here, regardless of the compression algorithm setting described below.
Write Brotli encoded streams
You can also go the other way! The PDF Manipulator lets you choose which compression algorithm it uses when writing new streams. Currently, Brotli, Flate, LZW and ‘None’ (which is not recommended) are supported, with the default being Flate.
To use Brotli, set the compression algorithm before applying your manipulations:
pdf.setCompressionAlgorithm(Filter.BROTLI);
Filterhere isorg.jpedal.constants.Filter
Note that this will not change any existing streams in the file which use a different algorithm. If you want to recompress existing page content, you can rewrite the page content streams from scratch using the currently selected algorithm with rewriteStream(). With no arguments it rewrites every page, or you can pass a page number or a PageRanges such as new PageRanges("1-10").
final PdfManipulator pdf = new PdfManipulator();
pdf.setCompressionAlgorithm(Filter.BROTLI);
pdf.loadDocument(new File("inputFile.pdf"));
pdf.rewriteStream();
pdf.apply();
pdf.writeDocument(new File("outputFile.pdf"));
pdf.closeDocument();
This only recompresses page content streams. Other streams, such as fonts and images, keep whatever filter they already had. Before switching everything over to Brotli, remember that not every viewer can read it yet. If your users are on older software, Flate is still the safer choice.
Using the command line
Detecting and removing Brotli are also available from the command line:
java -jar jpedal.jar --manipulate --containsBrotli inputFile
java -jar jpedal.jar --manipulate --removeBrotli inputFile outputFile
Writing Brotli streams is currently only available through the Java API.
Add Brotli compression support in Java
Download a JPedal trial jar from our website to start working with Brotli in your PDF files.
Learn more about manipulating PDF files in Java, or about compression formats in PDF files.
We can help you better understand the PDF format as developers who have been working with the format for more than 2 decades!
FAQ
What are the benefits of Brotli?
Brotli generally compresses better than Flate (Deflate), so PDF files which use it can be smaller. It is particularly good at shrinking text-heavy data such as fonts and page content streams.
Why might I want to add Brotli encoding to a PDF file?
To reduce file size, which saves storage and makes files quicker to download and send. It is a good fit when you know the people opening the files use viewers that support Brotli.
Why might I want to remove Brotli encoding from a PDF file?
For compatibility. Brotli is a recent addition to the PDF format, so older PDF viewers may not be able to open files which use it. Converting the Brotli streams to Flate makes the file readable by those viewers.