Skip to content

Colour and print ​

Hyper Compress can convert a document to one colour model and keep images detailed enough for printing. This guide shows the settings for print and for screen, how colour conversion works, and how to check what was converted.

WARNING

Hyper is a compression engine, not a prepress tool. It does not create or check PDF/X files (the print exchange version of PDF), does not add output intents, does not apply ink limits or overprint rules, and does not touch spot colours. If a print shop needs a certified PDF/X file, run your prepress tool after Hyper, or ask the shop which settings it accepts.

Before you begin ​

  • Install Hyper and compress one file first. See the Quickstart.
  • For print, start from the low preset: images at quality 80 and at most 200 dpi.
  • For screen, start from medium (150 dpi) or high (72 dpi).
  • If the file is a PDF/A archive and must stay one, read step 7 first: colour conversion is switched off there.

1. Choose the image resolution ​

Resolution has the biggest effect on both print quality and size. maxDpi sets the highest resolution colour and grayscale images keep; images above it are resampled down.

UsemaxDpiPreset that matches
Commercial print, photos that must stay sharp300none; override low
Office printing, archiving200low
Sharing and email150medium
Reading on screen only72high

maxDpi takes 0 to 600, and 0 leaves resolution alone. To set colour and grayscale images separately, use maxDpiColor and maxDpiGray. Black and white (1-bit) images have their own limit, maxDpiMono; see Scanned documents.

bash
hyper input.pdf output.pdf --preset low --set maxDpi=300
js
import { compress } from 'hyper-compress';

const result = await compress({
  sourcePath: 'input.pdf',
  savePath: 'output.pdf',
  preset: 'low',
  options: { maxDpi: 300 },
});
console.log(`${result.originalSize} -> ${result.compressedSize} bytes`);
bash
curl -o output.pdf --data-binary @input.pdf \
  --url-query 'preset=low' \
  --url-query 'options={"maxDpi":300}' \
  'http://localhost:8080/api/compress'
js
import { readFile, writeFile } from 'node:fs/promises';
import { compress } from 'hyper-compress-wasm';

const input = new Uint8Array(await readFile('input.pdf'));
const result = await compress(input, { preset: 'low', options: { maxDpi: 300 } });
await writeFile('output.pdf', result.data);

Hyper never scales an image up. An image that is lossless in the PDF is only resampled once it is more than one and a half times the limit, because resampling it saves little; set forceDownsample: true to resample every image above the limit.

2. Keep colour detail in JPEG images ​

Two more settings matter for print:

OptionValuesDefaultPrint advice
imageQuality5 to 10050 in medium, 80 in low80 or more
jpegSubsamplingauto, 444, 422, 420auto444 or auto

jpegSubsampling controls chroma subsampling: how much colour detail JPEG keeps compared with brightness detail. auto lets the encoder decide and keeps full colour resolution. 444 always keeps it. 422 halves colour resolution horizontally, and 420 halves it both ways, which is the smallest and can blur fine coloured lines and small coloured text. Both options are ignored when lossless is on.

bash
hyper input.pdf output.pdf --preset low --set maxDpi=300 \
  --set imageQuality=85 --set jpegSubsampling=444
js
import { compress } from 'hyper-compress';

await compress({
  sourcePath: 'input.pdf',
  savePath: 'output.pdf',
  preset: 'low',
  options: { maxDpi: 300, imageQuality: 85, jpegSubsampling: '444' },
});
bash
curl -o output.pdf --data-binary @input.pdf \
  --url-query 'preset=low' \
  --url-query 'options={"maxDpi":300,"imageQuality":85,"jpegSubsampling":"444"}' \
  'http://localhost:8080/api/compress'
c
/* low preset pairs, with 1=300 (maxDpi), 2=85 (quality) and 53=3 (4:4:4) */
const int ids[]  = {1, 2, 3, 8, 18, 7, 63, 10, 13, 14, 16, 17, 20, 67, 53};
const int vals[] = {300, 85, 4, 1, 1, 1, 10, 1, 1, 1, 1, 1, 8322, 6, 3};
int rc = hpdf_compress_file("input.pdf", "output.pdf", ids, vals,
                            sizeof ids / sizeof ids[0], NULL);

For files that must not change at all, use the lossless preset instead: images are only stored more efficiently and every pixel stays the same.

3. Convert to one colour model ​

colorTarget converts the document to one colour model.

colorTargetWhat is converted
originalNothing. The default.
rgbImages, text and vector colours, to sRGB
cmykImages, text and vector colours, to CMYK. Pure grays and pure black become K-only (black ink only).
grayImages, text and vector colours, to grayscale
bash
hyper input.pdf output.pdf --set colorTarget=cmyk
js
import { compress } from 'hyper-compress';

const result = await compress({
  sourcePath: 'input.pdf',
  savePath: 'output.pdf',
  options: { colorTarget: 'cmyk' },
});
console.log(result.warnings);
bash
curl -s -D - -o output.pdf --data-binary @input.pdf \
  --url-query 'options={"colorTarget":"cmyk"}' \
  'http://localhost:8080/api/compress' | grep -i '^x-warnings'
bash
docker run --rm -v "$PWD":/work ghcr.io/alam00000/bentopdf-hyper-compress:latest \
  input.pdf output.pdf --set colorTarget=cmyk
js
import { readFile, writeFile } from 'node:fs/promises';
import { compress } from 'hyper-compress-wasm';

const input = new Uint8Array(await readFile('input.pdf'));
const result = await compress(input, { options: { colorTarget: 'cmyk' } });
await writeFile('output.pdf', result.data);
console.log(result.warnings);
c
/* 51 is the colour target (0 original, 1 sRGB, 2 CMYK, 3 gray); 69=1 also converts text and vectors */
const int ids[]  = {2, 3, 51, 69};
const int vals[] = {50, 4, 2, 1};
int rc = hpdf_compress_file("input.pdf", "output.pdf", ids, vals, 4, NULL);

When every conversion was applied and the file got smaller, warnings is empty.

What colour conversion keeps ​

  • Spot colours (Separation and DeviceN, the named inks such as Pantone colours), patterns and shadings (smooth gradients) are kept as they are.

  • An image is only converted when the converted image is not larger. A CMYK image holds four channels instead of three, so photos often stay in RGB after colorTarget: 'cmyk'. Step 4 shows how to check.

  • The whole file falls back. If the converted file ends up no smaller than your input, Hyper returns your original bytes and adds a warning:

    text
    warning: colorTarget cmyk not applied: the converted file was not smaller than the original, so the original was kept
  • Lossless runs skip it. colorTarget is ignored when lossless is on, without a warning.

4. Check what was converted ​

Ask for a compression report and read each image's colour space before and after. The report is available from the CLI and the Node.js SDK.

bash
hyper input.pdf output.pdf --set colorTarget=cmyk --report report.json
js
import { compress } from 'hyper-compress';

const result = await compress({
  sourcePath: 'input.pdf',
  savePath: 'output.pdf',
  options: { colorTarget: 'cmyk' },
  report: true,
});
for (const img of result.report.images) {
  console.log(img.page, img.name, img.before.colorSpace, '->', img.after?.colorSpace);
}
text
1 Im0 DeviceRGB -> DeviceRGB

An image still in DeviceRGB was not converted because its CMYK version would have been larger. An image stored as JPEG 2000 (codec JPXDecode) can show none as its colour space, because JPEG 2000 carries the colour space inside the image data.

5. Make a grayscale copy ​

There are two ways to get rid of colour:

OptionConverts
grayscale: trueimages only; text and vector colours stay
colorTarget: 'gray'images, text and vector colours

Use grayscale when coloured headings and charts should stay coloured but photos may go gray. Use colorTarget: 'gray' for a true black and white document. When both are set, colorTarget wins.

bash
hyper input.pdf output.pdf --set colorTarget=gray
js
import { compress } from 'hyper-compress';

await compress({ sourcePath: 'input.pdf', savePath: 'output.pdf', options: { colorTarget: 'gray' } });
bash
curl -o output.pdf --data-binary @input.pdf \
  --url-query 'options={"colorTarget":"gray"}' \
  'http://localhost:8080/api/compress'

Both are ignored when lossless is on.

6. Handle colour profiles and output intents ​

An ICC profile is a small file inside the PDF that describes exactly what its colours mean. An output intent tells a printer which profile the whole document was prepared for.

OptionDefaultWhat it does
flattenIcctrue in low, medium and high; false in losslessReplaces embedded ICC 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. No effect when lossless is on.
removeOutputIntentsfalse in every presetRemoves the output intents.

For print, keep the profiles: set flattenIcc: false. Leave removeOutputIntents off; a print shop may rely on the output intent, and PDF/A and PDF/X require it.

bash
hyper input.pdf output.pdf --preset low --set flattenIcc=false
js
import { compress } from 'hyper-compress';

await compress({
  sourcePath: 'input.pdf',
  savePath: 'output.pdf',
  preset: 'low',
  options: { flattenIcc: false },
});
bash
curl -o output.pdf --data-binary @input.pdf \
  --url-query 'preset=low' \
  --url-query 'options={"flattenIcc":false}' \
  'http://localhost:8080/api/compress'

The colour conversion in step 3 uses Hyper's own built-in profiles: sRGB and a generic CMYK profile. You cannot supply your own profile, and Hyper does not add or change an output intent to match the conversion.

7. Keep PDF/A colour ​

PDF/A, the archiving version of PDF, fixes how colour is described. When you compress a PDF/A file with preserveConformance: true, Hyper keeps it conformant:

  • colorTarget is ignored, with the warning colorTarget ignored to preserve PDF/A conformance.
  • flattenIcc and removeOutputIntents are switched off, so profiles and output intents stay.
  • Everything else in this guide, such as resolution and JPEG quality, still applies.
bash
hyper archive.pdf output.pdf --set preserveConformance=true
js
import { compress } from 'hyper-compress';

const result = await compress({
  sourcePath: 'archive.pdf',
  savePath: 'output.pdf',
  options: { preserveConformance: true },
});
console.log(result.pdfaPreserved, result.warnings);
bash
curl -o output.pdf --data-binary @archive.pdf \
  'http://localhost:8080/api/compress?preservePdfa=true'

Without preserveConformance, colour conversion runs and Hyper removes the PDF/A claim from the file, because the file may no longer meet the standard. See PDF/A archives.

Recipes ​

GoalOptions
Print-ready photos, smaller filepreset low, maxDpi: 300, imageQuality: 85, jpegSubsampling: '444', flattenIcc: false
Office printpreset low
Screen only, smallestpreset high
Black and white handoutcolorTarget: 'gray'
Colour charts, gray photosgrayscale: true
Everything in CMYK where it does not grow the filecolorTarget: 'cmyk', then check with the report

Troubleshooting ​

colorTarget cmyk not applied warning. The converted file was not smaller than your input, so you got the original. Combine the conversion with a smaller maxDpi or imageQuality, or accept the original.

Photos are still RGB after colorTarget: 'cmyk'. Their CMYK version was larger, so Hyper kept them. Hyper does not force a conversion that grows the file; use a prepress tool if every image must be CMYK.

Colours look slightly different after compressing. flattenIcc replaced an embedded profile with the plain colour space. Set flattenIcc: false.

Fine coloured lines or small coloured text look blurred. Set jpegSubsampling: '444'.

colorTarget did nothing and there is no warning. lossless is on, which turns colour conversion off.

Next steps ​

Dual-licensed under AGPL-3.0 and Commercial License.