syncfusion-javascript-pdf
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseProcessing PDF Documents
PDF文档处理
A comprehensive skill for creating, reading, and manipulating PDF documents programmatically using the Syncfusion JavaScript PDF library. This library provides seamless integration for TypeScript, JavaScript, Angular, React, Vue, ASP.NET Core, and ASP.NET MVC applications.
本技能全面介绍如何使用Syncfusion JavaScript PDF库以编程方式创建、读取和操作PDF文档。该库可与TypeScript、JavaScript、Angular、React、Vue、ASP.NET Core和ASP.NET MVC应用无缝集成。
When to Use This Skill
适用场景
Use this skill when the user needs to:
- Create PDF documents from scratch with text, images, shapes, and other graphical elements
- Manipulate existing PDFs by adding content, modifying properties, or extracting data
- Add interactive features such as forms, annotations, bookmarks, and hyperlinks
- Secure PDFs with digital signatures
- Merge or split PDF documents for document management workflows
- Extract content including text and images from existing PDFs
- Add watermarks (text or image-based) for branding or security
- Manage document informations including title, author, subject, keywords, and dates
- Work with PDF layers for complex document structures
- Implement templates for consistent document generation
Platform Support: TypeScript, JavaScript, Angular, React, Vue, ASP.NET Core, ASP.NET MVC
当用户需要以下操作时,可使用本技能:
- 创建PDF文档:从头开始创建包含文本、图像、形状及其他图形元素的PDF文档
- 操作现有PDF:添加内容、修改属性或提取数据
- 添加交互功能:如表单、注释、书签和超链接
- PDF安全防护:添加数字签名
- 文档合并/拆分:用于文档管理工作流
- 内容提取:从现有PDF中提取文本和图像
- 添加水印:基于文本或图像的水印,用于品牌标识或安全防护
- 管理文档信息:包括标题、作者、主题、关键词和日期
- PDF图层处理:用于复杂文档结构
- 实现模板:用于生成格式一致的文档
平台支持:TypeScript、JavaScript、Angular、React、Vue、ASP.NET Core、ASP.NET MVC
Library Overview
库概述
The Syncfusion JavaScript PDF library () is a powerful, high-performance class library that enables:
@syncfusion/ej2-pdf- Creating PDF documents from scratch without Adobe Acrobat
- Loading, editing, and saving existing PDF files
- Opening password-protected PDF documents
- Adding text, images, shapes, and graphical elements
- Interactive components (bookmarks, annotations, form fields)
- Document operations (merge, split, flatten)
- Content extraction (text, images)
- Security features (digital signatures, redaction)
Key Classes:
- - Main document object
PdfDocument - - Individual pages
PdfPage - - Drawing surface for content
PdfGraphics - ,
PdfFont,PdfBitmap- Content elementsPdfBrush
Syncfusion JavaScript PDF库()是一个功能强大、高性能的类库,支持:
@syncfusion/ej2-pdf- 无需Adobe Acrobat即可从头创建PDF文档
- 加载、编辑和保存现有PDF文件
- 打开受密码保护的PDF文档
- 添加文本、图像、形状和图形元素
- 交互组件(书签、注释、表单字段)
- 文档操作(合并、拆分、扁平化)
- 内容提取(文本、图像)
- 安全功能(数字签名、内容红act)
核心类:
- - 主文档对象
PdfDocument - - 单个页面
PdfPage - - 内容绘制表面
PdfGraphics - 、
PdfFont、PdfBitmap- 内容元素PdfBrush
Documentation and Navigation Guide
文档与导航指南
Getting Started
快速入门
📄 Read: references/getting-started.md
Use this reference when the user needs to:
- Install the package
@syncfusion/ej2-pdf - Set up the library for TypeScript, JavaScript, Angular, React, Vue, or ASP.NET
- Understand dependencies and requirements
- Create their first PDF document
- Learn basic save and export operations
📄 阅读:references/getting-started.md
当用户需要以下操作时,可参考本指南:
- 安装包
@syncfusion/ej2-pdf - 为TypeScript、JavaScript、Angular、React、Vue或ASP.NET配置库
- 了解依赖项和要求
- 创建第一个PDF文档
- 学习基本的保存和导出操作
Document Creation & Settings
文档创建与设置
📄 Read: references/document-settings.md
Use this reference for:
- Creating instances
PdfDocument - Configuring page settings (size, orientation, margins, rotation)
- Setting document properties (title, author, subject, keywords, creation/modification dates)
- Enabling incremental updates
- Flattening annotations and form fields
📄 Read: references/pdf-pages.md
Use this reference for:
- Adding pages to documents
- Page manipulation and navigation
- Page sections with different settings
- Managing page collections
📄 阅读:references/document-settings.md
本指南适用于:
- 创建实例
PdfDocument - 配置页面设置(尺寸、方向、边距、旋转)
- 设置文档属性(标题、作者、主题、关键词、创建/修改日期)
- 启用增量更新
- 扁平化注释和表单字段
📄 阅读:references/pdf-pages.md
本指南适用于:
- 向文档添加页面
- 页面操作与导航
- 具有不同设置的页面章节
- 管理页面集合
Content Elements
内容元素
📄 Read: references/text-rendering.md
Use this reference when adding text:
- Drawing text with method
drawString() - Font types (Standard, TrueType, CJK fonts)
- Font styles, sizes, and formatting
- Text layout and wrapping
- Graphics state management (save/restore)
- Text positioning and bounds
📄 Read: references/images.md
Use this reference for image operations:
- Adding JPEG and PNG images
- Using class
PdfBitmap - Image positioning and sizing
- Inserting images into existing documents
- Base64 and Uint8Array image formats
- Clipping and graphics transformations
📄 Read: references/shapes.md
Use this reference for drawing shapes:
- Rectangles, circles, ellipses, lines
- Complex paths and curves
- Pens and brushes for styling
- Fill and stroke operations
- Graphics transformations (translate, rotate, scale)
📄 Read: references/lists.md
Use this reference for creating lists:
- Ordered and unordered lists
- Nested list structures
- Custom list markers
- List formatting options
📄 Read: references/templates.md
Use this reference for reusable content:
- Creating page templates
- Dynamic content stamping
- Template positioning and layout
- Reusing content across pages
📄 阅读:references/text-rendering.md
添加文本时可参考本指南:
- 使用方法绘制文本
drawString() - 字体类型(标准字体、TrueType字体、CJK字体)
- 字体样式、大小和格式
- 文本布局与换行
- 图形状态管理(保存/恢复)
- 文本定位与边界
📄 阅读:references/images.md
图像操作可参考本指南:
- 添加JPEG和PNG图像
- 使用类
PdfBitmap - 图像定位与尺寸调整
- 向现有文档插入图像
- Base64和Uint8Array图像格式
- 裁剪和图形变换
📄 阅读:references/shapes.md
绘制形状可参考本指南:
- 矩形、圆形、椭圆形、线条
- 复杂路径和曲线
- 用于样式设置的画笔和画刷
- 填充和描边操作
- 图形变换(平移、旋转、缩放)
📄 阅读:references/lists.md
创建列表可参考本指南:
- 有序列表和无序列表
- 嵌套列表结构
- 自定义列表标记
- 列表格式选项
📄 阅读:references/templates.md
可重用内容相关操作可参考本指南:
- 创建页面模板
- 动态内容盖章
- 模板定位与布局
- 在多个页面中重用内容
Interactive Features
交互功能
📄 Read: references/annotations.md
Use this reference for annotations:
- Annotation types (free text, ink, stamp, etc.)
- Adding and configuring annotations
- Annotation properties and appearance
- Flattening annotations to static content
📄 Read: references/bookmarks.md
Use this reference for navigation:
- Creating document bookmarks
- Nested bookmark hierarchies
- Bookmark navigation and linking
- Modifying existing bookmarks
📄 Read: references/form-fields.md
Use this reference for interactive forms:
- Form field types (text, checkbox, radio, dropdown, button)
- Adding and configuring form fields
- Field validation and properties
- Filling form data programmatically
- Importing/exporting form data
- Flattening forms to remove interactivity
📄 Read: references/hyperlinks.md
Use this reference for linking:
- Adding web hyperlinks
- Document internal navigation links
- Link annotations and appearance
- Navigation actions
📄 阅读:references/annotations.md
注释相关操作可参考本指南:
- 注释类型(自由文本、墨迹、图章等)
- 添加和配置注释
- 注释属性与外观
- 将注释扁平化为静态内容
📄 阅读:references/bookmarks.md
导航相关操作可参考本指南:
- 创建文档书签
- 嵌套书签层级
- 书签导航与链接
- 修改现有书签
📄 阅读:references/form-fields.md
交互表单相关操作可参考本指南:
- 表单字段类型(文本框、复选框、单选框、下拉菜单、按钮)
- 添加和配置表单字段
- 字段验证与属性
- 以编程方式填充表单数据
- 导入/导出表单数据
- 扁平化表单以移除交互性
📄 阅读:references/hyperlinks.md
链接相关操作可参考本指南:
- 添加网页超链接
- 文档内部导航链接
- 链接注释与外观
- 导航操作
Document Operations
文档操作
📄 Read: references/merge-documents.md
Use this reference for merging:
- Combining multiple PDF files
- Importing pages from other documents
- Preserving bookmarks during merge
- Merging workflows
📄 Read: references/split-documents.md
Use this reference for splitting:
- Splitting PDFs by page range
- Extracting specific pages
- Creating separate documents from pages
📄 Read: references/watermarks.md
Use this reference for watermarks:
- Text watermarks
- Image watermarks
- Watermark positioning and layout
- Opacity and rotation settings
📄 Read: references/layers.md
Use this reference for layer management:
- Creating PDF layers (Optional Content Groups)
- Layer visibility control
- Adding content to layers
- Removing or flattening layers
📄 阅读:references/merge-documents.md
合并操作可参考本指南:
- 合并多个PDF文件
- 从其他文档导入页面
- 合并时保留书签
- 合并工作流
📄 阅读:references/split-documents.md
拆分操作可参考本指南:
- 按页面范围拆分PDF
- 提取特定页面
- 从页面创建独立文档
📄 阅读:references/watermarks.md
水印操作可参考本指南:
- 文本水印
- 图像水印
- 水印定位与布局
- 透明度和旋转设置
📄 阅读:references/layers.md
图层管理可参考本指南:
- 创建PDF图层(可选内容组)
- 图层可见性控制
- 向图层添加内容
- 移除或扁平化图层
Data Extraction
数据提取
📄 Read: references/text-extraction.md
Use this reference for extracting text:
- Extracting text from PDF pages
- Text extraction layouts
- Text bounds and positioning
- Extracting from specific regions
📄 Read: references/image-extraction.md
Use this reference for extracting images:
- Extracting images from PDF documents
- Image data formats
- Saving extracted images
- Required package:
@syncfusion/ej2-pdf-data-extract
📄 阅读:references/text-extraction.md
文本提取操作可参考本指南:
- 从PDF页面提取文本
- 文本提取布局
- 文本边界与定位
- 从特定区域提取文本
📄 阅读:references/image-extraction.md
图像提取操作可参考本指南:
- 从PDF文档提取图像
- 图像数据格式
- 保存提取的图像
- 所需包:
@syncfusion/ej2-pdf-data-extract
Security & Protection
安全与防护
📄 Read: references/digital-signatures.md
Use this reference for security:
- Adding digital signatures
- Certificate-based signing
- Signature appearance customization
- Validation and verification
- Timestamp servers
📄 Read: references/redaction.md
Use this reference for content removal:
- Redacting sensitive text
- Shape redaction
- Redaction annotations
- Permanent content removal
📄 阅读:references/digital-signatures.md
安全相关操作可参考本指南:
- 添加数字签名
- 基于证书的签名
- 签名外观自定义
- 验证与校验
- 时间戳服务器
📄 阅读:references/redaction.md
内容移除操作可参考本指南:
- 红act敏感文本
- 形状红act
- 红act注释
- 永久移除内容
Quick Start Example
快速入门示例
typescript
import { PdfDocument, PdfPage, PdfGraphics, PdfFont, PdfFontFamily, PdfFontStyle, PdfBrush } from '@syncfusion/ej2-pdf';
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page
let page: PdfPage = document.addPage();
// Get graphics from the page
let graphics: PdfGraphics = page.graphics;
// Set font
let font: PdfFont = document.embedFont(PdfFontFamily.helvetica, 20, PdfFontStyle.regular);
// Create a brush
let brush = new PdfBrush({r: 0, g: 0, b: 0});
// Draw text
graphics.drawString('Hello World!', font, {x: 20, y: 20, width: 200, height: 50}, brush);
// Save the document
document.save('output.pdf');
// Clean up
document.destroy();typescript
import { PdfDocument, PdfPage, PdfGraphics, PdfFont, PdfFontFamily, PdfFontStyle, PdfBrush } from '@syncfusion/ej2-pdf';
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page
let page: PdfPage = document.addPage();
// Get graphics from the page
let graphics: PdfGraphics = page.graphics;
// Set font
let font: PdfFont = document.embedFont(PdfFontFamily.helvetica, 20, PdfFontStyle.regular);
// Create a brush
let brush = new PdfBrush({r: 0, g: 0, b: 0});
// Draw text
graphics.drawString('Hello World!', font, {x: 20, y: 20, width: 200, height: 50}, brush);
// Save the document
document.save('output.pdf');
// Clean up
document.destroy();Common Workflows
常见工作流
Create Invoice or Report
创建发票或报告
- Create document with custom page settings
- Add company logo (image)
- Add header text with formatting
- Create tables with borders (shapes + text)
- Add totals and footer
- Save and download
Start with: references/getting-started.md, then references/text-rendering.md and references/images.md
- 创建带有自定义页面设置的文档
- 添加公司标志(图像)
- 添加带格式的页眉文本
- 创建带边框的表格(形状+文本)
- 添加总计和页脚
- 保存并下载
参考起点:references/getting-started.md,然后是references/text-rendering.md和references/images.md
Fill and Flatten PDF Form
填充并扁平化PDF表单
- Load existing PDF document with form fields
- Fill form fields programmatically
- Flatten form to make it non-editable
- Save modified document
Start with: references/form-fields.md
- 加载包含表单字段的现有PDF文档
- 以编程方式填充表单数据
- 扁平化表单使其不可编辑
- 保存修改后的文档
参考起点:references/form-fields.md
Extract Data from PDF
从PDF提取数据
- Load existing PDF document
- Extract text from specific pages
- Extract images if needed
- Parse and process extracted data
Start with: references/text-extraction.md and references/image-extraction.md
- 加载现有PDF文档
- 从特定页面提取文本
- 如有需要,提取图像
- 解析并处理提取的数据
参考起点:references/text-extraction.md和references/image-extraction.md
Merge Multiple PDFs
合并多个PDF
- Create main document
- Import pages from source documents
- Optionally add bookmarks for sections
- Save combined document
Start with: references/merge-documents.md
- 创建主文档
- 从源文档导入页面
- (可选)为各章节添加书签
- 保存合并后的文档
参考起点:references/merge-documents.md
Add Digital Signature
添加数字签名
- Load document or create new one
- Configure digital signature with certificate
- Set signature appearance and position
- Save signed document
Start with: references/digital-signatures.md
- 加载文档或创建新文档
- 使用证书配置数字签名
- 设置签名外观和位置
- 保存已签名的文档
参考起点:references/digital-signatures.md
Platform-Specific Considerations
平台特定注意事项
TypeScript/JavaScript
TypeScript/JavaScript
- Direct import from
@syncfusion/ej2-pdf - Browser or Node.js environment
- File saving via browser download or Node.js fs
- 直接从导入
@syncfusion/ej2-pdf - 支持浏览器或Node.js环境
- 通过浏览器下载或Node.js fs模块保存文件
Angular/React/Vue
Angular/React/Vue
- Component-based integration
- Handle file downloads in component lifecycle
- State management for document generation
- 基于组件的集成
- 在组件生命周期中处理文件下载
- 文档生成的状态管理
ASP.NET Core/MVC
ASP.NET Core/MVC
- Server-side PDF generation
- Return PDF as file result
- Memory stream handling
For platform-specific setup details, see references/getting-started.md
- 服务器端PDF生成
- 以文件结果形式返回PDF
- 内存流处理
有关平台特定的配置详情,请参阅references/getting-started.md
Key Props and Methods
核心属性与方法
PdfDocument
PdfDocument
- - Add new page
addPage(settings?) - - Access existing page
getPage(index) - - Save document
save(filename) - - Clean up resources
destroy() - - Load font for use
embedFont()
- - 添加新页面
addPage(settings?) - - 访问现有页面
getPage(index) - - 保存文档
save(filename) - - 清理资源
destroy() - - 加载要使用的字体
embedFont()
PdfGraphics
PdfGraphics
- - Draw text
drawString(text, font, bounds, brush) - - Draw image
drawImage(image, bounds) - - Draw rectangle
drawRectangle(pen, bounds) - - Save graphics state
save() - - Restore graphics state
restore(state)
- - 绘制文本
drawString(text, font, bounds, brush) - - 绘制图像
drawImage(image, bounds) - - 绘制矩形
drawRectangle(pen, bounds) - - 保存图形状态
save() - - 恢复图形状态
restore(state)
PdfPage
PdfPage
- - Get drawing surface
graphics - - Get page dimensions
size - - Get/set rotation
rotation
For complete API details, refer to the specific reference files.
- - 获取绘制表面
graphics - - 获取页面尺寸
size - - 获取/设置旋转角度
rotation
有关完整的API详情,请参阅具体的参考文档。
Common Use Cases
常见用例
- Automated Report Generation - Create branded reports with charts, tables, and formatted text
- Invoice Creation - Generate professional invoices with line items and totals
- Certificate Generation - Create certificates with templates and custom text
- Form Filling - Programmatically fill PDF forms for bulk processing
- Document Assembly - Merge multiple PDFs into consolidated documents
- Data Extraction - Extract text and images from PDFs for processing
- Digital Signing - Apply digital signatures for document authentication
- Watermarking - Add branding or security watermarks to documents
- Redaction - Remove sensitive information before sharing
- Archive Creation - Convert documents to PDF/A format for long-term storage
- 自动化报告生成:创建包含图表、表格和格式化文本的品牌报告
- 发票创建:生成包含项目明细和总计的专业发票
- 证书生成:使用模板和自定义文本创建证书
- 表单填充:批量处理PDF表单的程序化填充
- 文档组装:将多个PDF合并为统一文档
- 数据提取:从PDF中提取文本和图像用于后续处理
- 数字签名:添加数字签名以实现文档认证
- 水印添加:添加品牌标识或安全水印
- 内容红act:共享前移除敏感信息
- 存档创建:将文档转换为PDF/A格式用于长期存储
Troubleshooting Tips
故障排除技巧
- Missing fonts: Ensure font is embedded before use with
document.embedFont() - Image not displaying: Verify image format (JPEG/PNG) and data (base64/Uint8Array)
- Large files: Use incremental updates or split operations
- Memory issues: Call after saving
document.destroy() - Extract features not working: Install package
@syncfusion/ej2-pdf-data-extract
- 字体缺失:使用确保字体已嵌入后再使用
document.embedFont() - 图像不显示:验证图像格式(JPEG/PNG)和数据(base64/Uint8Array)
- 文件过大:使用增量更新或拆分操作
- 内存问题:保存后调用
document.destroy() - 提取功能无法工作:安装包
@syncfusion/ej2-pdf-data-extract
Related Resources
相关资源
- Package:
@syncfusion/ej2-pdf - Add-on: (for extraction features)
@syncfusion/ej2-pdf-data-extract - Dependencies: ,
@syncfusion/ej2-compression@syncfusion/ej2-base
- 包:
@syncfusion/ej2-pdf - 附加组件:(用于提取功能)
@syncfusion/ej2-pdf-data-extract - 依赖项:、
@syncfusion/ej2-compression@syncfusion/ej2-base