syncfusion-javascript-pdf

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Processing 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 (
@syncfusion/ej2-pdf
) is a powerful, high-performance class library that enables:
  • 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:
  • PdfDocument
    - Main document object
  • PdfPage
    - Individual pages
  • PdfGraphics
    - Drawing surface for content
  • PdfFont
    ,
    PdfBitmap
    ,
    PdfBrush
    - Content elements
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
    @syncfusion/ej2-pdf
    package
  • 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
    PdfDocument
    instances
  • 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
    drawString()
    method
  • 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
    PdfBitmap
    class
  • 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

创建发票或报告

  1. Create document with custom page settings
  2. Add company logo (image)
  3. Add header text with formatting
  4. Create tables with borders (shapes + text)
  5. Add totals and footer
  6. Save and download
Start with: references/getting-started.md, then references/text-rendering.md and references/images.md
  1. 创建带有自定义页面设置的文档
  2. 添加公司标志(图像)
  3. 添加带格式的页眉文本
  4. 创建带边框的表格(形状+文本)
  5. 添加总计和页脚
  6. 保存并下载
参考起点references/getting-started.md,然后是references/text-rendering.mdreferences/images.md

Fill and Flatten PDF Form

填充并扁平化PDF表单

  1. Load existing PDF document with form fields
  2. Fill form fields programmatically
  3. Flatten form to make it non-editable
  4. Save modified document
Start with: references/form-fields.md
  1. 加载包含表单字段的现有PDF文档
  2. 以编程方式填充表单数据
  3. 扁平化表单使其不可编辑
  4. 保存修改后的文档
参考起点references/form-fields.md

Extract Data from PDF

从PDF提取数据

  1. Load existing PDF document
  2. Extract text from specific pages
  3. Extract images if needed
  4. Parse and process extracted data
Start with: references/text-extraction.md and references/image-extraction.md
  1. 加载现有PDF文档
  2. 从特定页面提取文本
  3. 如有需要,提取图像
  4. 解析并处理提取的数据
参考起点references/text-extraction.mdreferences/image-extraction.md

Merge Multiple PDFs

合并多个PDF

  1. Create main document
  2. Import pages from source documents
  3. Optionally add bookmarks for sections
  4. Save combined document
Start with: references/merge-documents.md
  1. 创建主文档
  2. 从源文档导入页面
  3. (可选)为各章节添加书签
  4. 保存合并后的文档
参考起点references/merge-documents.md

Add Digital Signature

添加数字签名

  1. Load document or create new one
  2. Configure digital signature with certificate
  3. Set signature appearance and position
  4. Save signed document
Start with: references/digital-signatures.md
  1. 加载文档或创建新文档
  2. 使用证书配置数字签名
  3. 设置签名外观和位置
  4. 保存已签名的文档
参考起点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

  • addPage(settings?)
    - Add new page
  • getPage(index)
    - Access existing page
  • save(filename)
    - Save document
  • destroy()
    - Clean up resources
  • embedFont()
    - Load font for use
  • addPage(settings?)
    - 添加新页面
  • getPage(index)
    - 访问现有页面
  • save(filename)
    - 保存文档
  • destroy()
    - 清理资源
  • embedFont()
    - 加载要使用的字体

PdfGraphics

PdfGraphics

  • drawString(text, font, bounds, brush)
    - Draw text
  • drawImage(image, bounds)
    - Draw image
  • drawRectangle(pen, bounds)
    - Draw rectangle
  • save()
    - Save graphics state
  • restore(state)
    - Restore graphics state
  • drawString(text, font, bounds, brush)
    - 绘制文本
  • drawImage(image, bounds)
    - 绘制图像
  • drawRectangle(pen, bounds)
    - 绘制矩形
  • save()
    - 保存图形状态
  • restore(state)
    - 恢复图形状态

PdfPage

PdfPage

  • graphics
    - Get drawing surface
  • size
    - Get page dimensions
  • rotation
    - Get/set rotation
For complete API details, refer to the specific reference files.
  • graphics
    - 获取绘制表面
  • size
    - 获取页面尺寸
  • rotation
    - 获取/设置旋转角度
有关完整的API详情,请参阅具体的参考文档。

Common Use Cases

常见用例

  1. Automated Report Generation - Create branded reports with charts, tables, and formatted text
  2. Invoice Creation - Generate professional invoices with line items and totals
  3. Certificate Generation - Create certificates with templates and custom text
  4. Form Filling - Programmatically fill PDF forms for bulk processing
  5. Document Assembly - Merge multiple PDFs into consolidated documents
  6. Data Extraction - Extract text and images from PDFs for processing
  7. Digital Signing - Apply digital signatures for document authentication
  8. Watermarking - Add branding or security watermarks to documents
  9. Redaction - Remove sensitive information before sharing
  10. Archive Creation - Convert documents to PDF/A format for long-term storage
  1. 自动化报告生成:创建包含图表、表格和格式化文本的品牌报告
  2. 发票创建:生成包含项目明细和总计的专业发票
  3. 证书生成:使用模板和自定义文本创建证书
  4. 表单填充:批量处理PDF表单的程序化填充
  5. 文档组装:将多个PDF合并为统一文档
  6. 数据提取:从PDF中提取文本和图像用于后续处理
  7. 数字签名:添加数字签名以实现文档认证
  8. 水印添加:添加品牌标识或安全水印
  9. 内容红act:共享前移除敏感信息
  10. 存档创建:将文档转换为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
    document.destroy()
    after saving
  • Extract features not working: Install
    @syncfusion/ej2-pdf-data-extract
    package
  • 字体缺失:使用
    document.embedFont()
    确保字体已嵌入后再使用
  • 图像不显示:验证图像格式(JPEG/PNG)和数据(base64/Uint8Array)
  • 文件过大:使用增量更新或拆分操作
  • 内存问题:保存后调用
    document.destroy()
  • 提取功能无法工作:安装
    @syncfusion/ej2-pdf-data-extract

Related Resources

相关资源

  • Package:
    @syncfusion/ej2-pdf
  • Add-on:
    @syncfusion/ej2-pdf-data-extract
    (for extraction features)
  • Dependencies:
    @syncfusion/ej2-compression
    ,
    @syncfusion/ej2-base
  • 包:
    @syncfusion/ej2-pdf
  • 附加组件:
    @syncfusion/ej2-pdf-data-extract
    (用于提取功能)
  • 依赖项:
    @syncfusion/ej2-compression
    @syncfusion/ej2-base