
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
kdf-pdf-tools
Advanced tools
A powerful React component library for viewing, annotating, and managing PDFs and Markdown documents with BBox support and multimedia attachments. Perfect for document annotation systems.
一个强大的 React PDF 组件库,支持文档查看、BBox 标注和多媒体附件管理
npm install kdf-pdf-tools react react-dom react-pdf pdfjs-dist
或使用 yarn:
yarn add kdf-pdf-tools react react-dom react-pdf pdfjs-dist
无需手动配置! 从 v2.0.0 开始,PDF.js worker 会自动配置:
详细信息请查看 WORKER_SETUP.md
import { KDFReader } from 'kdf-pdf-tools'
function App() {
return (
<KDFReader
pdfUrl="https://example.com/document.pdf"
editable={true}
/>
)
}
import { KDFReader } from 'kdf-pdf-tools'
const bboxData = {
blocksByPage: {
"1": [
{
id: "block_1",
bbox: [100, 100, 200, 150],
type: "text"
}
]
}
}
function App() {
return (
<KDFReader
pdfUrl="https://example.com/document.pdf"
bboxData={bboxData}
editable={true}
/>
)
}
import { useRef } from 'react'
import { KDFReader } from 'kdf-pdf-tools'
function App() {
const kdfReaderRef = useRef(null)
const handleUpload = async () => {
// 获取 PDF File 对象
const pdfFile = kdfReaderRef.current.getPdfFile()
// 获取多媒体 File 对象
const multimediaFiles = kdfReaderRef.current.getMultimediaFiles()
// 创建 FormData 并上传
const formData = new FormData()
formData.append('pdf', pdfFile)
multimediaFiles.forEach((item, index) => {
formData.append(`multimedia_${index}`, item.file)
formData.append(`multimedia_${index}_bboxId`, item.bboxId)
})
// 发送到服务器
await fetch('/api/upload', {
method: 'POST',
body: formData
})
}
return (
<div>
<KDFReader
ref={kdfReaderRef}
pdfUrl={pdfFile}
bboxData={bboxData}
editable={true}
/>
<button onClick={handleUpload}>上传到服务器</button>
</div>
)
}
| Prop | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
pdfUrl | string | File | ✅ | - | PDF 文件 URL 或 File 对象 |
bboxData | Object | ❌ | null | BBox 标注数据 |
editable | boolean | ❌ | false | 是否可编辑(显示上传/删除按钮) |
multimedias | Array | ❌ | [] | 已存在的多媒体文件 |
width | number | ❌ | 900 | 查看器宽度 |
onMultimediaChange | Function | ❌ | null | 多媒体变化回调 |
documentOptions | Object | ❌ | - | PDF.js 文档选项 |
workerSrc | string | ❌ | auto | 自定义 worker 路径(自动配置) |
fileSizeLimits | Object | ❌ | 见下表 | 文件大小限制 |
style | Object | ❌ | {} | 容器自定义样式 |
| 类型 | 限制 |
|---|---|
| 图片 | 10 MB |
| 视频 | 100 MB |
| 音频 | 20 MB |
| 3D模型 | 50 MB |
| 50 MB |
通过 ref 可以访问以下方法:
getPdfFile() - 获取 PDF File 对象getPdfUrl() - 获取 PDF URLgetPdfDocument() - 获取 pdf.js Document 对象getNumPages() - 获取 PDF 页数getMultimedias() - 获取多媒体元数据getMultimediaFiles() ⭐ - 获取多媒体 File 对象(用于上传)getMultimediaByBboxId(bboxId) - 获取指定 bbox 的元数据getMultimediaFileByBboxId(bboxId) ⭐ - 获取指定 bbox 的 File 对象getBboxData() - 获取 BBox 数据getSnapshot() - 获取完整数据快照详细的 API 文档请参考 REF_API.md
| 类型 | 支持格式 | 功能 |
|---|---|---|
| 图片 | jpg, png, gif, webp | 查看、适应/填充、显示/隐藏 |
| 视频 | mp4, webm, ogg | 播放控制、进度条 |
| 音频 | mp3, wav, ogg | 播放控制、进度条 |
| 3D 模型 | gltf, glb | 预留支持 |
const handleUploadAll = async () => {
const pdfFile = kdfReaderRef.current.getPdfFile()
const multimediaFiles = kdfReaderRef.current.getMultimediaFiles()
const formData = new FormData()
formData.append('pdf', pdfFile)
multimediaFiles.forEach((item, index) => {
formData.append(`multimedia_${index}`, item.file)
formData.append(`multimedia_${index}_bboxId`, item.bboxId)
formData.append(`multimedia_${index}_metadata`, JSON.stringify(item.metadata))
})
const response = await fetch('/api/documents/upload-all', {
method: 'POST',
body: formData
})
const result = await response.json()
console.log('上传成功:', result)
}
const express = require('express')
const multer = require('multer')
const app = express()
const upload = multer({ dest: 'uploads/' })
app.post('/api/documents/upload-all', upload.any(), (req, res) => {
const files = req.files
const pdfFile = files.find(f => f.fieldname === 'pdf')
const multimediaFiles = files.filter(f => f.fieldname.startsWith('multimedia_'))
const mediaMapping = multimediaFiles.map(file => {
const index = file.fieldname.split('_')[1]
return {
filename: file.filename,
bboxId: req.body[`multimedia_${index}_bboxId`],
metadata: JSON.parse(req.body[`multimedia_${index}_metadata`])
}
})
res.json({
success: true,
pdf: pdfFile.filename,
multimedias: mediaMapping
})
})
更多示例请查看 EXAMPLES.md
npm run build
npm publish
getMultimediaFiles() 只返回通过上传的文件,URL 加载的文件不会返回 File 对象URL.createObjectURL() 后记得清理MIT © [Your Name]
欢迎提交 Issue 和 Pull Request!
如有问题,请提交 Issue
FAQs
A powerful React component library for viewing, annotating, and managing PDFs and Markdown documents with BBox support and multimedia attachments. Perfect for document annotation systems.
The npm package kdf-pdf-tools receives a total of 13 weekly downloads. As such, kdf-pdf-tools popularity was classified as not popular.
We found that kdf-pdf-tools demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.