Options
Every option Hyper accepts. All surfaces take the same names and values. Pass only the options you want to change: everything you leave out comes from the preset (medium when you name none).
hyper input.pdf output.pdf --preset high --set grayscale=true --set imageQuality=40import { compress } from 'hyper-compress';
await compress({
sourcePath: 'input.pdf',
savePath: 'output.pdf',
preset: 'high',
options: { grayscale: true, imageQuality: 40 },
});curl -o output.pdf --data-binary @input.pdf \
--url-query 'preset=high' \
--url-query 'options={"grayscale":true,"imageQuality":40}' \
'http://localhost:8080/api/compress'import { readFile, writeFile } from 'node:fs/promises';
import { compress } from 'hyper-compress-wasm';
const result = await compress(new Uint8Array(await readFile('input.pdf')), {
preset: 'high',
options: { grayscale: true, imageQuality: 40 },
});
await writeFile('output.pdf', result.data);How values are read
- Numbers outside the allowed range are clamped to the nearest end, and decimals are rounded.
- Choices (
colorTarget,mrcand the like) fall back to their default when the value is not one of the listed ones. - Booleans must be
trueorfalse; anything else falls back to the default. - Unknown names are ignored, so check the spelling if a setting seems to do nothing.
A bad option never fails a run. To see exactly what will run, call resolveOptions in the Node.js SDK.
The medium column below is what you get when you set nothing. Preset values at the end lists all four presets. The guides explain when to change what.
Images
| Option | Type | medium | What it does |
|---|---|---|---|
imageQuality | number 5 to 100 | 50 | JPEG quality for re-encoded images. Lower is smaller with more visible artefacts. Below about 20 the artefacts are obvious, which is why no preset goes there, but a size target can. |
maxDpi | number 0 to 600 | 150 | Colour and grayscale images above this resolution are resampled down. 0 leaves resolution alone. Shorthand for maxDpiColor and maxDpiGray; 1-bit images have their own limit, maxDpiMono. |
maxDpiColor | number 0 to 600 | 0 | Resolution limit for colour images. 0 uses maxDpi. |
maxDpiGray | number 0 to 600 | 0 | Resolution limit for grayscale images. 0 uses maxDpi. |
maxDpiMono | number 0 to 1200 | 0 | Resolution limit for 1-bit (black and white) images such as text scans. 0 leaves them at full resolution, because 1-bit text loses legibility quickly; 300 is a safe value. Downsampled 1-bit images stay 1-bit. |
thresholdDpi | number 0 to 2400 | 0 | Only resample images above this resolution. 0 keeps the built-in rule: lossy images are resampled once they exceed the limit, lossless ones once they exceed it by half. Values below the limit act as the limit, so an image is never scaled up. |
forceDownsample | boolean | false | Resample every image above the limit, even one only slightly above it. By default lossless images are left alone until they exceed the limit by half, because resampling them buys little. |
lossless | boolean | false | Turns off quality, resolution, colour conversion, ICC profile flattening and every other lossy image step. Images are only stored more efficiently, so every pixel stays the same. A size target that the lossless result misses switches the search to lossy encoding. |
grayscale | boolean | false | Convert images to grayscale. Page text and vector colours are left alone; use colorTarget gray to convert those too. |
colorTarget | original, rgb, cmyk, gray | original | Convert the document to one colour model. rgb and cmyk convert images and page text and vector colours through ICC profiles (sRGB and a generic CMYK profile); pure grays and pure black map to K-only in CMYK. gray converts images, text and vectors to grayscale. Spot colours (Separation and DeviceN), patterns and shadings are kept. An image is only converted when the result is not larger, and if the converted file ends up larger than the original, the original is returned with a warning. Ignored when lossless and while preserving PDF/A. |
jpegSubsampling | auto, 444, 422, 420 | auto | Chroma subsampling for re-encoded JPEG images. auto lets the encoder decide (full colour resolution); 420 halves colour resolution both ways and is smallest; 422 halves it horizontally; 444 keeps it. Ignored when lossless. |
jpegProgressive | boolean | false | Write progressive JPEG images, which appear gradually while loading over slow connections. Usually a little smaller too. |
speed | quality, balanced, fast | balanced | How many encodings are tried per image. fast encodes JPEG only, with no JPEG 2000 trial and no palette trials. balanced runs the trials the other options ask for. quality also tries JPEG 2000 (except in PDF/A) and lossy and lossless palettes for every image and keeps the smallest. Ignored when lossless. |
reduceColor | boolean | true | Store images with few colours as palette (indexed) images, which are much smaller than full colour. Only images that look the same afterwards are converted. |
clipImages | boolean | true | Crop image data hidden outside the visible clip region. |
preferJpx | boolean | true | Let JPEG 2000 compete with JPEG per image and keep the smaller one. |
removeAlternates | boolean | false | Remove alternate versions of images, such as high resolution copies kept for printing. Viewers show the main image either way. |
flattenIcc | boolean | true | Replace embedded ICC colour profiles of 2 KB or more on page content with the matching plain colour space (gray, RGB or CMYK). Saves the profile bytes; colours can shift slightly where the profile differed from the standard one. |
mrc | off, auto, force | off | Mixed raster content for scanned pages: each page image is split into a sharp 1-bit text mask, a low-resolution background and a low-resolution ink colour layer. auto applies it to pages made of one or two page-sized images and no visible text; force applies it to every page. Every rewritten page is rendered before and after and rolled back if it changed visibly. Ignored when lossless. |
mrcBackgroundDpi | number 36 to 300 | 75 | Resolution of the MRC background and ink colour layers. The text mask keeps the scan resolution, up to 300 dpi. |
mrcBackgroundQuality | number 5 to 100 | 30 | JPEG quality of the MRC background layer. |
mrcForegroundQuality | number 5 to 100 | 50 | JPEG quality of the MRC ink colour layer. |
mrcDetectPhotos | boolean | true | Find photographic regions on MRC pages and keep them out of the 1-bit text mask, so photos are stored as a separate image layer at the background resolution instead of being broken into black specks. |
jbig2Symbols | boolean | false | Store repeated shapes in black and white images once and reuse them across pages (lossy JBIG2). Smaller scans, but a shape can be swapped for a similar one, so a page is kept only when every small area matches the original. Off keeps black and white images exact. |
Rasterization
For image-only documents such as scans and print-to-PDF output. Unless you also set rasterizeText, Hyper refuses to rasterize when any page contains text, including an invisible OCR layer, so it cannot destroy searchable text; the skip is reported as a warning. Rasterization is also disabled while preserving PDF/A. See Scanned documents.
| Option | Type | medium | What it does |
|---|---|---|---|
rasterizePages | boolean | false | Replace each page with a single rendered image. Shrinks vector-heavy pages dramatically. |
rasterizeDpi | number 36 to 600 | 150 | Render resolution. Higher keeps more detail. |
rasterizeQuality | number 1 to 100 | 50 | JPEG quality for the rasterized pages. |
rasterizeText | boolean | false | Rasterize pages even when the document has a text layer. Text stops being selectable and searchable, and links stop working. Needs rasterizePages. |
Fonts
| Option | Type | medium | What it does |
|---|---|---|---|
subsetFonts | boolean | true | Keep only the glyphs the document uses. Lossless: the text looks and searches the same. |
removeStandardFonts | boolean | false | Unembed the standard 14 PDF fonts (Times, Helvetica, Courier, Symbol and ZapfDingbats in their styles); every viewer has them built in. |
unembedAliasedFonts | boolean | false | Unembed metric-compatible clones of the standard fonts. Arial, Times New Roman and Courier New map to the built-in equivalents. Only applied when safe. |
mergeFonts | boolean | true | Merge duplicate font programs and font dictionaries, and with them duplicate objects and resources, so each is stored once. |
Structure and interactivity
| Option | Type | medium | What it does |
|---|---|---|---|
annotations | keep, flatten, remove | keep | What happens to comments, highlights, stamps and other markup annotations. keep leaves them; flatten draws them into the page so they can no longer be edited; remove deletes them. Form fields and links are never touched by this option; see flattenForms and flattenLinks. |
removeAnnots | boolean | false | Deprecated, use annotations. true behaves like annotations flatten, which is what it always did. |
removeBookmarks | boolean | false | Remove the bookmarks (outline) panel. |
removeActions | boolean | false | Remove JavaScript and other actions that run code or open things: the open action, document, page and annotation triggers, document-level scripts, and JavaScript, launch, import, submit and media actions on links and bookmarks. Plain links and bookmark jumps keep working. |
removeNamedDests | boolean | false | Remove the named destinations table. Links, bookmarks and the open action that point at a named destination are rewritten to point at the page directly first, so they keep working. Links from other documents to a name in this one stop working. |
removeAttachments | boolean | false | Remove embedded files, both document attachments and file attachment annotations. |
removeSignatureAppearances | boolean | false | Remove the visible appearance of empty (unsigned) signature fields. Signed documents are returned untouched unless removeSignatures is set. |
flattenForms | boolean | false | Flatten form fields into page content. Form fields stop being fillable. |
flattenLinks | boolean | false | Draw link annotations into the page. Links stop being clickable; any visible link border stays on the page. |
removeSignatures | boolean | false | Remove digital signatures so a signed document can be compressed instead of returned untouched. The visible signature stays on the page, but the file is no longer signed and can be signed again. |
removeStructTree | boolean | false | Drop the structure tree. Removes tagging, which screen readers rely on. |
removeThreads | boolean | false | Remove article threads, the reading order chains some magazines and newspapers use to jump between columns. |
Metadata and cleanup
| Option | Type | medium | What it does |
|---|---|---|---|
removeThumbnails | boolean | true | Remove embedded page thumbnails. |
removeAppData | boolean | true | Remove application private data (PieceInfo) that programs like Illustrator store to reopen the file for editing. Viewers never use it. |
removeSpiderInfo | boolean | false | Remove web capture information (SpiderInfo) left by tools that converted web pages to PDF. |
removeOutputIntents | boolean | false | Remove output intents, which tell a printer which colour profile the document was prepared for. Needed for PDF/A and PDF/X; kept while preserving PDF/A. |
removeMetadata | boolean | false | Remove the document information (title, author, producer, dates and custom entries) and the document XMP metadata packet. Refused with a warning while preserving PDF/A, which requires XMP. |
removePrintSettings | boolean | false | Remove print presets (scaling, duplex, paper tray, page range, copies). Other viewer preferences stay. |
removeSearchIndex | boolean | false | Remove web capture content identifiers (the IDS and URLS name trees). |
Output format
| Option | Type | medium | What it does |
|---|---|---|---|
preserveConformance | boolean | false | Keep a PDF/A document conformant. Disables every step that would break the standard, including Brotli and rasterization; anything dropped is reported in warnings. |
contentPrecision | number 0 to 8 | 6 | Number precision when page content is rewritten compactly. 0 keeps every value exactly. 3 to 8 rounds coordinates to that many significant digits (always keeping at least 3 decimals, so no value moves by more than 0.0005 units) and colours to 3 decimals. Ignored when lossless. |
linearize | boolean | false | Linearize the output (fast web view), so a browser can show the first page before the whole file has downloaded. Adds a little size. Skipped for signed documents, which are returned untouched, and while preserving PDF/A. |
minVersion | none, 1.4, 1.5, 1.6, 1.7, 2.0 | none | Minimum PDF version of the output. A lower header version is raised; a higher one is never lowered. 2.0 is refused while preserving PDF/A-1, 2 or 3, which require a 1.x header. |
brotli | boolean | false | PDF 2.0 Brotli stream compression. Smaller files, but the reader must support it (MuPDF 1.26+, Ghostscript 10.06+, Firefox). Off while preserving PDF/A. |
Preset values
What each preset sets, field by field. A preset is a complete set of options; start from one and override any field.
| Option | low | medium | high | lossless |
|---|---|---|---|---|
imageQuality | 80 | 50 | 20 | 100 |
maxDpi | 200 | 150 | 72 | 0 |
maxDpiColor | 0 | 0 | 0 | 0 |
maxDpiGray | 0 | 0 | 0 | 0 |
maxDpiMono | 0 | 0 | 150 | 0 |
thresholdDpi | 0 | 0 | 0 | 0 |
forceDownsample | false | false | false | false |
lossless | false | false | false | true |
grayscale | false | false | false | false |
colorTarget | original | original | original | original |
jpegSubsampling | auto | auto | auto | auto |
jpegProgressive | false | false | false | false |
speed | balanced | balanced | balanced | balanced |
reduceColor | true | true | true | true |
clipImages | false | true | true | false |
preferJpx | true | true | true | false |
removeAlternates | false | false | true | false |
flattenIcc | true | true | true | false |
mrc | off | off | off | off |
mrcBackgroundDpi | 75 | 75 | 75 | 75 |
mrcBackgroundQuality | 30 | 30 | 30 | 30 |
mrcForegroundQuality | 50 | 50 | 50 | 50 |
mrcDetectPhotos | true | true | true | true |
jbig2Symbols | false | false | false | false |
rasterizePages | false | false | false | false |
rasterizeDpi | 150 | 150 | 150 | 150 |
rasterizeQuality | 50 | 50 | 50 | 50 |
rasterizeText | false | false | false | false |
subsetFonts | true | true | true | true |
removeStandardFonts | false | false | true | false |
unembedAliasedFonts | false | false | true | false |
mergeFonts | true | true | true | true |
annotations | keep | keep | keep | keep |
removeAnnots | false | false | false | false |
removeBookmarks | false | false | false | false |
removeActions | false | false | false | false |
removeNamedDests | false | false | false | false |
removeAttachments | false | false | false | false |
removeSignatureAppearances | false | false | false | false |
flattenForms | false | false | false | false |
flattenLinks | false | false | false | false |
removeSignatures | false | false | false | false |
removeStructTree | false | false | false | false |
removeThreads | false | false | true | false |
removeThumbnails | true | true | true | true |
removeAppData | true | true | true | true |
removeSpiderInfo | false | false | true | false |
removeOutputIntents | false | false | false | false |
removeMetadata | false | false | false | false |
removePrintSettings | false | false | false | false |
removeSearchIndex | false | false | false | false |
preserveConformance | false | false | false | false |
contentPrecision | 6 | 6 | 6 | 0 |
linearize | false | false | false | false |
minVersion | none | none | none | none |
brotli | false | false | false | false |