{"_id":"@caijinglong/pdf-compress","_rev":"2-791fbfe7c88e53092be5cae23d4bab88","name":"@caijinglong/pdf-compress","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"@caijinglong/pdf-compress","version":"0.1.0","keywords":["pdf","compress","browser","nodejs","pdf-lib"],"author":{"name":"caijinglong"},"license":"MIT","_id":"@caijinglong/pdf-compress@0.1.0","maintainers":[{"name":"caijinglong","email":"cjl_spy@163.com"}],"homepage":"https://github.com/caijinglong/pdf-compress","bugs":{"url":"https://github.com/caijinglong/pdf-compress/issues"},"dist":{"shasum":"7bd1166df54cfcd7555328a686c34053cc029368","tarball":"https://registry.npmjs.org/@caijinglong/pdf-compress/-/pdf-compress-0.1.0.tgz","fileCount":13,"integrity":"sha512-/ndhf2hsOTy1Zr5Fz0FK/EGJUPV7Xn/KzCJ6QkH7Upxo/EWDqxAZXwxJGRkit1aoDkZ3lcBDmGzW4+y75rf+yg==","signatures":[{"sig":"MEQCIHM4X3Bb4Szpm6DQ/5Jl4wzQPT/naFlrYoPek33lbDPWAiAR7jGHYuv8bx/jvMdy7Zu4QD1Eevg3iioqt6+6TjH2wA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":7390216},"type":"module","unpkg":"./dist/pdf-compress.global.js","exports":{".":{"types":"./dist/node.d.ts","browser":"./dist/browser.js","default":"./dist/node.js"},"./node":{"types":"./dist/node.d.ts","default":"./dist/node.js"},"./browser":{"types":"./dist/browser.d.ts","default":"./dist/browser.js"}},"gitHead":"e9a0904c2324f8ae1fec5df30c3d11b5f4bbfd46","scripts":{"test":"vitest run","build":"bun run build:esm && bun run build:global","serve":"serve -l 4884 .","build:esm":"tsup","typecheck":"tsc --noEmit","build:global":"node scripts/build-global.mjs"},"_npmUser":{"name":"caijinglong","email":"cjl_spy@163.com"},"jsdelivr":"./dist/pdf-compress.global.js","repository":{"url":"git+https://github.com/caijinglong/pdf-compress.git","type":"git"},"_npmVersion":"10.9.2","description":"一个面向 Node.js 和现代浏览器的 PDF 图片压缩库，专门压缩 PDF 中的位图图片内容，尽量不破坏文本、字体和矢量元素。","directories":{},"_nodeVersion":"23.6.1","dependencies":{"pdf-lib":"^1.17.1","@napi-rs/canvas":"^0.1.65"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.0","serve":"^14.2.6","vitest":"^3.2.4","esbuild":"^0.25.4","typescript":"^5.8.3","@types/node":"^22.15.2"},"_npmOperationalInternal":{"tmp":"tmp/pdf-compress_0.1.0_1779178447398_0.11128223455677122","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@caijinglong/pdf-compress","version":"0.1.2","type":"module","exports":{".":{"types":"./dist/node.d.ts","browser":"./dist/browser.js","default":"./dist/node.js"},"./browser":{"types":"./dist/browser.d.ts","default":"./dist/browser.js"},"./node":{"types":"./dist/node.d.ts","default":"./dist/node.js"}},"unpkg":"./dist/pdf-compress.global.js","jsdelivr":"./dist/pdf-compress.global.js","scripts":{"build:esm":"tsup","build:global":"node scripts/build-global.mjs","build":"bun run build:esm && bun run build:global","serve":"serve -l 4884 .","test":"vitest run","typecheck":"tsc --noEmit"},"keywords":["pdf","compress","browser","nodejs","pdf-lib"],"author":{"name":"caijinglong"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/CaiJingLong/pdf-compress.git"},"homepage":"https://github.com/CaiJingLong/pdf-compress","dependencies":{"@napi-rs/canvas":"^0.1.65","pdf-lib":"^1.17.1"},"devDependencies":{"@types/node":"^22.15.2","esbuild":"^0.25.4","serve":"^14.2.6","tsup":"^8.5.0","typescript":"^5.8.3","vitest":"^3.2.4"},"gitHead":"22b8be537dde9d47ab4fb4d4dcd934063f997e9a","_id":"@caijinglong/pdf-compress@0.1.2","description":"一个面向 Node.js 和现代浏览器的 PDF 图片压缩库，专门压缩 PDF 中的位图图片内容，尽量不破坏文本、字体和矢量元素。","bugs":{"url":"https://github.com/CaiJingLong/pdf-compress/issues"},"_nodeVersion":"24.15.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-MH4hNODW/cxYlAo/UufLZQbFq+y1GEGQuEr4tIJoLZyzAytXP4AZ1JtHPX7zt9jWz+De/+WNi28Tb0SRz45Q9Q==","shasum":"805d8ef522d623eeab4cbfe3c142a63be8c51927","tarball":"https://registry.npmjs.org/@caijinglong/pdf-compress/-/pdf-compress-0.1.2.tgz","fileCount":13,"unpackedSize":7390220,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@caijinglong%2fpdf-compress@0.1.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCES1SJTzvdx6nlPtAPYButw0mdWVAOHW9nM9s51NKa9QIhAIPcjWHg+6xVH2i3Ap2tXtEKZKI2GR5Tu2djyEVMXTUW"}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:ebc1a880-5629-435e-b591-029adc729aec"}},"directories":{},"maintainers":[{"name":"caijinglong","email":"cjl_spy@163.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pdf-compress_0.1.2_1779181781004_0.5548877372243068"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-19T08:14:07.265Z","modified":"2026-05-19T09:09:41.722Z","0.1.0":"2026-05-19T08:14:07.620Z","0.1.2":"2026-05-19T09:09:41.281Z"},"bugs":{"url":"https://github.com/CaiJingLong/pdf-compress/issues"},"author":{"name":"caijinglong"},"license":"MIT","homepage":"https://github.com/CaiJingLong/pdf-compress","keywords":["pdf","compress","browser","nodejs","pdf-lib"],"repository":{"type":"git","url":"git+https://github.com/CaiJingLong/pdf-compress.git"},"description":"一个面向 Node.js 和现代浏览器的 PDF 图片压缩库，专门压缩 PDF 中的位图图片内容，尽量不破坏文本、字体和矢量元素。","maintainers":[{"name":"caijinglong","email":"cjl_spy@163.com"}],"readme":"# @caijinglong/pdf-compress\n\n一个面向 Node.js 和现代浏览器的 PDF 图片压缩库，专门压缩 PDF 中的位图图片内容，尽量不破坏文本、字体和矢量元素。\n\n## 功能特点\n\n- 尽量保留文本和矢量内容\n- 只处理 PDF 内嵌位图图片\n- 同时支持 Node.js、浏览器 ESM 和浏览器全局脚本\n- 提供单文件浏览器构建 `dist/pdf-compress.global.js`\n\n## 使用限制\n\n- 适合图片较多的 PDF，不是通用 PDF 全量优化器\n- 不处理字体子集化、矢量简化、对象重排这类优化\n- 遇到不安全或不支持的图片流时会跳过\n- 如果压缩后没有更小，会直接返回原始 PDF 数据\n\n## 安装\n\n```bash\n/Users/cai/.bun/bin/bun add @caijinglong/pdf-compress\n```\n\n## Node 用法\n\n按文件路径压缩：\n\n```ts\nimport { compressPdfFile } from '@caijinglong/pdf-compress/node';\n\nconst result = await compressPdfFile('./assets/samples/sample-images.pdf', {\n  quality: 0.83,\n  maxWidth: 1800,\n  maxHeight: 1800,\n});\n\nconsole.log(result.outputPath);\nconsole.log(result.summary);\n```\n\n按二进制压缩：\n\n```ts\nimport { readFile } from 'node:fs/promises';\nimport { compressPdf } from '@caijinglong/pdf-compress/node';\n\nconst input = await readFile('./assets/samples/sample-images.pdf');\nconst result = await compressPdf(input, {\n  quality: 0.83,\n  maxWidth: 1800,\n  maxHeight: 1800,\n});\n\nconsole.log(result.summary);\n```\n\n## 浏览器 ESM 用法\n\n```ts\nimport { compressPdf } from '@caijinglong/pdf-compress/browser';\n\nconst result = await compressPdf(file, {\n  quality: 0.83,\n  maxWidth: 1800,\n  maxHeight: 1800,\n});\n```\n\n## 浏览器全局脚本用法\n\n```html\n<script src=\"https://cdn.jsdelivr.net/npm/@caijinglong/pdf-compress/dist/pdf-compress.global.js\"></script>\n```\n\n```js\nconst result = await window.PdfCompress.compressPdf(file, {\n  quality: 0.83,\n  maxWidth: 1800,\n  maxHeight: 1800,\n});\n```\n\n## CDN ESM 用法\n\n```ts\nimport { compressPdf } from 'https://esm.sh/@caijinglong/pdf-compress/browser';\n```\n\n## 示例目录\n\n- 浏览器全局脚本示例：[examples/browser-global/index.html](/Users/cai/code/web/pdf-compress/examples/browser-global/index.html:1)\n- 浏览器 ESM 示例：[examples/browser-esm/index.html](/Users/cai/code/web/pdf-compress/examples/browser-esm/index.html:1)\n- 公开样例 PDF 和来源说明：[assets/samples/README.md](/Users/cai/code/web/pdf-compress/assets/samples/README.md:1)\n\n本地预览：\n\n```bash\n/Users/cai/.bun/bin/bun run build\n/Users/cai/.bun/bin/bun run serve\n```\n\n访问：\n\n```text\nhttp://127.0.0.1:4884/examples/browser-global/\nhttp://127.0.0.1:4884/examples/browser-esm/\n```\n\n## 默认参数\n\n- `quality: 0.83`\n- `maxWidth: 2000`\n- `maxHeight: 2000`\n- `minBytes: 32768`\n- `minWidth: 256`\n- `minHeight: 256`\n- `skipImagesWithAlpha: true`\n- `jpegOnly: false`\n\n## 开发命令\n\n```bash\n/Users/cai/.bun/bin/bun install\n/Users/cai/.bun/bin/bun run build\n/Users/cai/.bun/bin/bun test\n/Users/cai/.bun/bin/bun run typecheck\n```\n\n## 相关文档\n\n- 英文说明：[README.md](/Users/cai/code/web/pdf-compress/README.md:1)\n- 开发者文档：[docs/developer-guide.zh-CN.md](/Users/cai/code/web/pdf-compress/docs/developer-guide.zh-CN.md:1)\n","readmeFilename":"README.zh-CN.md"}