Skip to content

Compression report ​

The compression report shows what Hyper Compress did inside one compression: each font, each page image and each piece of document structure, before and after. Use it to explain a result, to audit what a preset removes, or to find the images that make a file large.

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

const result = await compress({ sourcePath: 'input.pdf', savePath: 'output.pdf', report: true });
for (const img of result.report?.images ?? []) {
  console.log(img.page, img.name, img.before.bytes, '->', img.after?.bytes);
}
rust
use std::path::PathBuf;

use hyper_compress::{compress, Binaries, CompressInput, ReportRequest};

fn main() {
    let input = CompressInput {
        source_path: PathBuf::from("input.pdf"),
        save_path: Some(PathBuf::from("output.pdf")),
        report: ReportRequest::Return,
        binaries: Binaries::beside_exe(),
        ..Default::default()
    };
    let result = compress(&input).expect("compress failed");
    if let Some(report) = result.report {
        for img in report.images {
            println!("{} {} {}", img.page, img.name, img.before.bytes);
        }
    }
}

Requesting a report ​

SurfaceHowWhere the report goes
CLI--report <file>Written to the file as indented JSON.
Node.js SDKreport: trueresult.report
Node.js SDKreport: 'report.json'result.report, and written to the file as JSON.
Rust cratereport: ReportRequest::Returnresult.report
Rust cratereport: ReportRequest::File(path)result.report, and written to the file as JSON.
HTTP API, WebAssembly, C APINot available.

A report adds two read passes with qpdf, one over the input and one over the output, so leave it off when you do not need it.

If the PDF structure cannot be read, or qpdf is not available, the compression still succeeds, no report is returned or written, and the warning report unavailable: the PDF structure could not be read is added. When the input is signed and returned unchanged, the report still describes it, with the same content before and after.

Example ​

json
{
  "originalSize": 601042,
  "compressedSize": 77105,
  "fonts": [
    {
      "name": "Helvetica",
      "type": "Type1",
      "action": "kept",
      "before": { "count": 1, "embedded": false, "subset": false, "bytes": 0 },
      "after": { "count": 1, "embedded": false, "subset": false, "bytes": 0 }
    }
  ],
  "images": [
    {
      "page": 1,
      "name": "Im0",
      "dpi": 64,
      "before": { "width": 500, "height": 400, "colorSpace": "DeviceRGB", "codec": "FlateDecode", "bytes": 600191 },
      "after": { "width": 500, "height": 400, "colorSpace": "DeviceRGB", "codec": "DCTDecode", "bytes": 76186 }
    }
  ],
  "cleanup": []
}

Top level ​

NameTypeDescription
originalSizenumberInput file size in bytes, as given (before decryption).
compressedSizenumberOutput file size in bytes.
fontsarray of font entriesOne entry per font name and type in the input.
imagesarray of image entriesOne entry per image placed directly on a page of the input.
cleanuparray of cleanup entriesCounts of document structures before and after.

With a password, "before" describes the decrypted input.

fonts ​

Fonts with the same name and type are grouped into one entry, ordered by where the font first appears in the file's object list.

NameTypeDescription
namestringFont name without the six-letter subset prefix (ABCDEF+), for example Helvetica. (unnamed) when the font has no name.
typestringType1, TrueType, Type3, MMType1, or for composite fonts Type0/CIDFontType0 or Type0/CIDFontType2.
actionstringWhat happened to the font. See below.
beforefont stateThe font in the input.
afterfont state or nullThe font in the output, or null when it is gone.

A font state has these fields:

NameTypeDescription
countnumberFont objects with this name and type.
embeddedbooleantrue if any copy carries its font program in the file. Type3 fonts always count as embedded.
subsetbooleantrue only if every copy is a subset (holds only the characters the document uses).
bytesnumberCombined stored size of the embedded font programs.

action is the first of these that applies:

ValueMeaning
removedThe font is no longer in the document, for example because the page content that used it was rasterized.
unembeddedIt was embedded and now the viewer supplies it (removeStandardFonts, unembedAliasedFonts).
subsetIt was a full font and is now a subset.
mergedDuplicate copies were merged into fewer (mergeFonts).
recompressedSame font, stored in fewer bytes.
keptUnchanged.

images ​

NameTypeDescription
pagenumberPage number, starting at 1.
namestringThe image's resource name on that page, for example Im0.
dpinumber or nullResolution as placed on the page, as measured by the engine. null when it is not known.
beforeimage stateThe image in the input.
afterimage state or nullThe image with the same name on the same page of the output, or null when it is gone, for example after rasterizing or MRC.

An image state has these fields:

NameTypeDescription
width, heightnumberSize in pixels.
colorSpacestringFor example DeviceRGB, DeviceGray, DeviceCMYK, ICCBased, Indexed. ImageMask for a stencil mask, none when not set.
codecstringThe compression filter: DCTDecode (JPEG), JPXDecode (JPEG 2000), JBIG2Decode, FlateDecode, CCITTFaxDecode and so on. Several filters are joined with +. none means uncompressed.
bytesnumberStored size of the image data.

Images inside form XObjects (reusable page parts) are not listed.

cleanup ​

Each entry is { "item": string, "before": number, "after": number }. Only items present in the input or the output are listed, so an empty array means the document had none of them.

itemWhat is counted
documentInfoEntries in the document information dictionary (title, author, producer, dates, custom entries).
xmpMetadata1 when the document has an XMP metadata packet.
bookmarksBookmark (outline) entries.
attachmentsEmbedded files plus file attachment annotations.
actionsOpen action, document and page triggers, document JavaScript, and annotations that run JavaScript, launch files, import data, submit forms or play media.
namedDestinationsNamed destinations.
printSettingsPrint settings in the viewer preferences (scaling, duplex, paper tray, page range, copies, print area, print clip).
annotationsMarkup annotations: everything except form fields and links.
formFieldsForm field widgets.
linksLink annotations.
thumbnailsPages with an embedded thumbnail.
structureTree1 when the document is tagged.
articleThreads1 when the document has article threads.
outputIntents1 when the document has output intents (colour profiles for print).
searchIndexWeb capture identifiers (the IDS and URLS name trees).

Types ​

The Node.js SDK exports the report types by name:

ts
import type {
  CompressResult,
  HyperReport,
  HyperFontReport,
  HyperImageReport,
  HyperImageState,
  HyperCleanupReport,
} from 'hyper-compress';

function largestImage(result: CompressResult): HyperImageReport | undefined {
  const report: HyperReport | undefined = result.report;
  return [...(report?.images ?? [])].sort((a, b) => b.before.bytes - a.before.bytes)[0];
}
ts
interface HyperReport {
  originalSize: number;
  compressedSize: number;
  fonts: HyperFontReport[];
  images: HyperImageReport[];
  cleanup: HyperCleanupReport[];
}

interface HyperFontReport {
  name: string;
  type: string;
  before: { count: number; embedded: boolean; subset: boolean; bytes: number };
  after: { count: number; embedded: boolean; subset: boolean; bytes: number } | null;
  action: 'kept' | 'subset' | 'unembedded' | 'merged' | 'recompressed' | 'removed';
}

interface HyperImageReport {
  page: number;
  name: string;
  dpi: number | null;
  before: HyperImageState;
  after: HyperImageState | null;
}

interface HyperImageState {
  width: number;
  height: number;
  colorSpace: string;
  codec: string;
  bytes: number;
}

interface HyperCleanupReport {
  item: string;
  before: number;
  after: number;
}

In Rust the report is hyper_compress::report::Report; its fields are listed on Rust crate.

Next steps ​

Dual-licensed under AGPL-3.0 and Commercial License.