npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@caijinglong/pdf-compress

v0.1.2

Published

一个面向 Node.js 和现代浏览器的 PDF 图片压缩库,专门压缩 PDF 中的位图图片内容,尽量不破坏文本、字体和矢量元素。

Readme

@caijinglong/pdf-compress

一个面向 Node.js 和现代浏览器的 PDF 图片压缩库,专门压缩 PDF 中的位图图片内容,尽量不破坏文本、字体和矢量元素。

功能特点

  • 尽量保留文本和矢量内容
  • 只处理 PDF 内嵌位图图片
  • 同时支持 Node.js、浏览器 ESM 和浏览器全局脚本
  • 提供单文件浏览器构建 dist/pdf-compress.global.js

使用限制

  • 适合图片较多的 PDF,不是通用 PDF 全量优化器
  • 不处理字体子集化、矢量简化、对象重排这类优化
  • 遇到不安全或不支持的图片流时会跳过
  • 如果压缩后没有更小,会直接返回原始 PDF 数据

安装

/Users/cai/.bun/bin/bun add @caijinglong/pdf-compress

Node 用法

按文件路径压缩:

import { compressPdfFile } from '@caijinglong/pdf-compress/node';

const result = await compressPdfFile('./assets/samples/sample-images.pdf', {
  quality: 0.83,
  maxWidth: 1800,
  maxHeight: 1800,
});

console.log(result.outputPath);
console.log(result.summary);

按二进制压缩:

import { readFile } from 'node:fs/promises';
import { compressPdf } from '@caijinglong/pdf-compress/node';

const input = await readFile('./assets/samples/sample-images.pdf');
const result = await compressPdf(input, {
  quality: 0.83,
  maxWidth: 1800,
  maxHeight: 1800,
});

console.log(result.summary);

浏览器 ESM 用法

import { compressPdf } from '@caijinglong/pdf-compress/browser';

const result = await compressPdf(file, {
  quality: 0.83,
  maxWidth: 1800,
  maxHeight: 1800,
});

浏览器全局脚本用法

<script src="https://cdn.jsdelivr.net/npm/@caijinglong/pdf-compress/dist/pdf-compress.global.js"></script>
const result = await window.PdfCompress.compressPdf(file, {
  quality: 0.83,
  maxWidth: 1800,
  maxHeight: 1800,
});

CDN ESM 用法

import { compressPdf } from 'https://esm.sh/@caijinglong/pdf-compress/browser';

示例目录

本地预览:

/Users/cai/.bun/bin/bun run build
/Users/cai/.bun/bin/bun run serve

访问:

http://127.0.0.1:4884/examples/browser-global/
http://127.0.0.1:4884/examples/browser-esm/

默认参数

  • quality: 0.83
  • maxWidth: 2000
  • maxHeight: 2000
  • minBytes: 32768
  • minWidth: 256
  • minHeight: 256
  • skipImagesWithAlpha: true
  • jpegOnly: false

开发命令

/Users/cai/.bun/bin/bun install
/Users/cai/.bun/bin/bun run build
/Users/cai/.bun/bin/bun test
/Users/cai/.bun/bin/bun run typecheck

相关文档