syncfusion-dotnet-pdf
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePDF Document Processing
PDF文档处理
Overview
概述
Create, read, write, and convert PDF files using the Syncfusion PDF Library. This skill supports two operational modes — generating C# code for the user's project or executing tasks directly through a CSX script.
使用Syncfusion PDF Library创建、读取、写入和转换PDF文件。该技能支持两种操作模式——为用户项目生成C#代码,或通过CSX脚本直接执行任务。
Key Capabilities
核心功能
- Create & Edit: PDF files from scratch, text, images (various formats), tables, shapes, paragraphs, headings, styles, lists, hyperlinks, bookmarks, headers/footers, watermarks, template management, metadata editing
- Forms & Interactive Elements: Create, fill, and flatten forms (AcroForms and XFA), bookmarks, annotations, attachments, buttons, and content controls
- Advanced Features: Comments, layers (add, remove, flatten), PDF portfolios, JavaScript execution, 3D model embedding and interaction, rich media content (audio/video), optical character recognition (Tesseract engine), text redaction, image redaction, digital signatures and validation
- Conversion: XPS to PDF, PDF to PDF/A conformance, extract text and images from PDF documents
- Security: Password encryption/decryption, advanced encryption standards, document protection with editable ranges, macro management, digital signing capabilities
- Barcodes & Standards: 1D barcodes, 2D barcodes, ZUGFeRD invoice support, PDF/A-1B, PDF/A-1A, PDF/A-2B, PDF/A-2A, PDF/A-2U, PDF/A-3B, PDF/A-3A, PDF/A-3U, PDF/A-4, PDF/A-4E, PDF/A-4F, PDF/X1-A conformances, Accessible PDF/Tagged PDF (PDF/UA) with Section 508 compliance
- Additional Operations: Merge and split PDF files, open and modify existing PDF files, compress PDF files, corrupted PDF detection.
- 创建与编辑:从零开始创建PDF文件,支持文本、图片(多种格式)、表格、形状、段落、标题、样式、列表、超链接、书签、页眉/页脚、水印、模板管理、元数据编辑
- 表单与交互元素:创建、填写并扁平化表单(AcroForms和XFA),支持书签、注释、附件、按钮和内容控件
- 高级功能:注释、图层(添加、删除、扁平化)、PDF作品集、JavaScript执行、3D模型嵌入与交互、富媒体内容(音频/视频)、光学字符识别(Tesseract引擎)、文本红action、图片红action、数字签名与验证
- 格式转换:XPS转PDF、PDF转PDF/A合规格式、从PDF文档中提取文本和图片
- 安全防护:密码加密/解密、高级加密标准、带可编辑范围的文档保护、宏管理、数字签名功能
- 条码与合规标准:一维条码、二维条码、ZUGFeRD发票支持、PDF/A-1B、PDF/A-1A、PDF/A-2B、PDF/A-2A、PDF/A-2U、PDF/A-3B、PDF/A-3A、PDF/A-3U、PDF/A-4、PDF/A-4E、PDF/A-4F、PDF/X1-A合规、符合Section 508标准的无障碍PDF/标签化PDF(PDF/UA)
- 附加操作:合并与拆分PDF文件、打开并修改现有PDF文件、压缩PDF文件、损坏PDF检测
Quick Start Examples
快速入门示例
Example 1: Generate Code (Mode 1)
示例1:生成代码(模式1)
User: "Show me the C# code to create a PDF with a title, a heading, and a paragraph."
Result: C# code snippet displayed (no files created)
用户: "展示如何用C#代码创建包含标题、副标题和段落的PDF。"
结果: 显示C#代码片段(不创建文件)
Example 2: Execute Task (Mode 2)
示例2:执行任务(模式2)
User: "Generate a meeting agenda document and save it to ."
Result: Physical file created at specified path
output/agenda.pdf用户: "生成会议议程文档并保存到。"
结果: 在指定路径创建实际文件
output/agenda.pdfTwo Modes — Choose Based on User Intent
两种模式——根据用户意图选择
Mode 1: Generate C# Code for the User's Project (default)
模式1:为用户项目生成C#代码(默认)
Trigger keywords: "code", "snippet", "how to write", "Program.cs", "show me", "sample", "example code", "generate code for".
Workflow:
- Build the C# code using snippets from files and replace placeholders with actual content
references/*.md - Add the code directly into the user's project files (e.g., )
Program.cs - Do not create or run any script
.csx
Note: Use namespace for this code for cross-platform projects, not . This ensures compatibility across Windows, macOS, and Linux.
Syncfusion.DrawingSystem.DrawingNote: If package is suggested, then must be use the namespace for graphics operations instead of to ensure cross-platform compatibility. The package is designed to work with the namespace, which provides a consistent API for drawing operations across different platforms. Using may lead to compatibility issues, especially on non-Windows platforms, as it relies on GDI+ which is not fully supported outside of Windows. Therefore, always use when working with PDF graphics in a cross-platform context.
Syncfusion.Pdf.Net.CoreSyncfusion.DrawingSystem.DrawingSyncfusion.Pdf.Net.CoreSyncfusion.DrawingSystem.DrawingSyncfusion.DrawingNote: If RectangleF, PointF, SizeF, or Color types are needed, use the ones from namespace for cross-platform compatibility, not the ones from . This ensures that the code will work correctly on Windows, macOS, and Linux without relying on GDI+.
Syncfusion.DrawingSystem.Drawing触发关键词: "code"、"snippet"、"how to write"、"Program.cs"、"show me"、"sample"、"example code"、"generate code for"。
工作流程:
- 从文件中提取代码片段构建C#代码,并用实际内容替换占位符
references/*.md - 将代码直接添加到用户项目文件中(如)
Program.cs - 不创建或运行任何脚本
.csx
注意:跨平台项目中,该代码需使用命名空间,而非,以确保在Windows、macOS和Linux上的兼容性。
Syncfusion.DrawingSystem.Drawing注意:若推荐使用包,图形操作必须使用命名空间,而非,以确保跨平台兼容性。包专为命名空间设计,提供跨平台一致的绘图API。使用可能导致兼容性问题,尤其是在非Windows平台,因为它依赖于GDI+,而GDI+在Windows以外的平台未得到完全支持。因此,在跨平台场景中处理PDF图形时,务必使用。
Syncfusion.Pdf.Net.CoreSyncfusion.DrawingSystem.DrawingSyncfusion.Pdf.Net.CoreSyncfusion.DrawingSystem.DrawingSyncfusion.Drawing注意:若需要RectangleF、PointF、SizeF或Color类型,需使用命名空间下的对应类型,而非,以确保代码在Windows、macOS和Linux上正确运行,无需依赖GDI+。
Syncfusion.DrawingSystem.DrawingMode 2: Execute via CSX Script (does not touch project files)
模式2:通过CSX脚本执行(不修改项目文件)
Trigger keywords: "create a pdf document", "make a document", "generate a document", "open", "edit", "modify", "change" a file, "without modifying my project", "run a csx script", or when the user provides a file path (e.g., ).
.pdfoutput/report.pdfWorkflow:
- Create using
{skill-root}/syncfusion-dotnet-pdf/scripts/temp-{timestamp}.csxas the base orreferences/template.csxfor OCR-specific operations. Example,references/template-ocr.csx=skill-root..github/skills - Add required operations from snippets and replace placeholders with actual content
references/*.md - Run:
dotnet script {skill-root}/syncfusion-dotnet-pdf/scripts/temp-{timestamp}.csx - Delete the temp script after execution
- Report SUCCESS/ERROR and show the output file path
Note: Use namespace for this csx script, not .
Syncfusion.DrawingSystem.Drawing触发关键词: "create a pdf document"、"make a document"、"generate a document"、"open"、"edit"、"modify"、"change" a file、"without modifying my project"、"run a csx script",或当用户提供文件路径时(如)。
.pdfoutput/report.pdf工作流程:
- 以为基础,或针对OCR操作使用
references/template.csx,在references/template-ocr.csx目录下创建{skill-root}/syncfusion-dotnet-pdf/scripts/文件(例如,temp-{timestamp}.csx=skill-root).github/skills - 从片段中添加所需操作,并用实际内容替换占位符
references/*.md - 执行:
dotnet script {skill-root}/syncfusion-dotnet-pdf/scripts/temp-{timestamp}.csx - 执行完成后删除临时脚本
- 报告执行成功/错误,并显示输出文件路径
注意:该CSX脚本需使用命名空间,而非。
Syncfusion.DrawingSystem.DrawingCode References
代码参考
All templates and snippets are in the folder:
references/| File | Contents |
|---|---|
| template.csx | Core CSX script template (used in Mode 2) |
| document-structure.md | Document lifecycle: create, save, close; sections and page setup |
| open-pdf.md | Open existing PDFs from file stream, byte array, encrypted files, corrupted documents, and cloud storage (Azure Blob, AWS S3, Google Drive, Google Cloud Storage, Dropbox) |
| save-pdf.md | Save new and loaded PDFs to file path, MemoryStream, byte array, and cloud storage (Azure Blob, AWS S3, Google Drive, Google Cloud Storage, Dropbox) |
| pages.md | Add, insert, remove, rotate, rearrange, import, and configure pages; page count, blank detection, page labels, section numbering, PageAdded event, and page-level actions |
| pdf-graphics.md | Working with PdfGraphics: text, images, and shapes |
| shapes.md | Draw shapes: lines, rectangles, ellipses, polygons, arcs, bezier curves, paths |
| brushes.md | Fill shapes with solid, linear gradient, radial gradient, tiling, and hatch brushes; PdfBrushes static colors; combine pen and brush |
| images.md | Insert, draw, replace, remove, clip, transform, and paginate raster images (JPEG, PNG, BMP, GIF, TIFF, ICO); image masking; multi-page TIFF to PDF; unit conversion for image placement |
| text.md | Draw text with standard, TrueType, OpenType, and CJK fonts; alignment, RTL, complex scripts, HTML styled text, multi-column, paginated text flow, ordered/unordered lists, string measurement, text clipping detection, and unit conversion |
| merge-pdf.md | Merge multiple PDFs into one file |
| split-pdf.md | Divide a single PDF into separate files |
| compress-pdf.md | Reduce and optimize PDF file size |
| extract-text.md | Retrieve text content from PDFs and find text within it |
| extract-image.md | Extract images and image metadata (bounds, index) from PDF pages and entire documents using PdfPageBase and PdfDocumentExtractor |
| ocr.md | Perform OCR on scanned PDFs and images using Tesseract; supports region OCR, rotated pages, layout result, page segmentation modes, engine modes, image enhancement, whitelist/blacklist, Unicode, and image-to-PDF conversion |
| tables.md | Build tables in PDFs using PdfGrid |
| headers-and-footers.md | Add headers and footers with automatic fields and dynamic content |
| bookmarks.md | Create and manage PDF bookmarks (outline navigation) |
| attachments.md | Add, manage, and extract file attachments in PDFs |
| security.md | Encrypt and protect PDFs with passwords and permissions |
| actions.md | Add interactive actions, triggers, and JavaScript to PDFs |
| hyperlinks.md | Add web URL links, internal document navigation, and external file links using PdfTextWebLink, PdfDocumentLinkAnnotation, and PdfFileLinkAnnotation |
| watermarks.md | Add text and image watermarks with transparency and rotation |
| portfolio.md | Create PDF portfolios embedding multiple files |
| layers.md | Create and manage layers (optional content) in PDFs |
| metadata.md | Work with document and image XMP metadata; properties schemas and custom fields |
| redact.md | Redaction examples and usage (text/image/pattern/regex-based redaction) |
| digital-sign.md | Digital signature examples: basic signing → advanced (TSA, LTV, external sign) |
| import-export-annotation.md | Import and export annotations (FDF, XFDF, JSON) — file, stream, and round-trip workflows |
| pdf-forms.md | Create, fill, modify, flatten, and manage AcroForm fields (text box, combo box, radio button, list box, check box, signature, button); covers field properties, visibility, read-only, auto-naming, complex script, and appearance |
| import-export-form.md | Import and export AcroForm field data (FDF, XFDF, JSON) — fill, export, round-trip, and flatten |
| annotations.md | Add, modify, remove, flatten PDF annotations (popup, free text, line, stamp, ink, markup, URI, redaction, cloud border, and more) |
| barcode.md | Add 1D (Code 39, EAN-13, EAN-8, Codabar, Code 93, Code 128, PDF417) and 2D (QR, DataMatrix) barcodes; export barcodes as images |
| colorspace.md | Work with DeviceGray, DeviceRGB, DeviceCMYK, and ICC-based color spaces for drawing and images |
| conformance.md | Produce PDF/A (1B, 2B, 3B) and PDF/X compliant files; convert existing PDFs to conformance standards |
| named-destinations.md | Add, modify, remove, and link named destinations for in-document and URL-based navigation |
| pdf-templates.md | Create and use PdfTemplate, PdfPageTemplateElement (header/footer), and PdfPageTemplate; create overlays and capture pages as templates |
| accessible-pdf.md | Create tagged PDFs, PDF/UA-2, Well-Tagged PDFs and Extract accessiblity tag elements |
| tagged-pdf.md | Create tagged (accessible/structured) PDFs with logical structure trees for screen-reader and reflow support |
| zugferd-invoice.md | Create ZUGFeRD electronic invoice PDFs (PDF/A-3b) with embedded XML; supports ZUGFeRD 1.0, 2.0, Factur-X, and XRechnung conformance levels; extract XML from existing ZUGFeRD PDFs |
| xps-to-pdf.md | Convert XPS (XML Paper Specification) documents to PDF using XPSToPdfConverter |
所有模板和代码片段均位于目录下:
references/| 文件 | 内容 |
|---|---|
| template.csx | 核心CSX脚本模板(用于模式2) |
| document-structure.md | 文档生命周期:创建、保存、关闭;章节和页面设置 |
| open-pdf.md | 从文件流、字节数组、加密文件、损坏文档和云存储(Azure Blob、AWS S3、Google Drive、Google Cloud Storage、Dropbox)打开现有PDF |
| save-pdf.md | 将新生成和已加载的PDF保存到文件路径、MemoryStream、字节数组和云存储(Azure Blob、AWS S3、Google Drive、Google Cloud Storage、Dropbox) |
| pages.md | 添加、插入、删除、旋转、重排、导入和配置页面;页面计数、空白页检测、页面标签、章节编号、PageAdded事件和页面级操作 |
| pdf-graphics.md | 使用PdfGraphics处理文本、图片和形状 |
| shapes.md | 绘制形状:线条、矩形、椭圆、多边形、弧线、贝塞尔曲线、路径 |
| brushes.md | 使用纯色、线性渐变、径向渐变、平铺和图案画刷填充形状;PdfBrushes静态颜色;画笔与画刷的组合使用 |
| images.md | 插入、绘制、替换、删除、裁剪、变换和分页栅格图片(JPEG、PNG、BMP、GIF、TIFF、ICO);图片遮罩;多页TIFF转PDF;图片放置的单位转换 |
| text.md | 使用标准、TrueType、OpenType和CJK字体绘制文本;对齐、RTL、复杂脚本、HTML样式文本、多列、分页文本流、有序/无序列表、字符串测量、文本裁剪检测和单位转换 |
| merge-pdf.md | 将多个PDF合并为单个文件 |
| split-pdf.md | 将单个PDF拆分为多个独立文件 |
| compress-pdf.md | 缩小并优化PDF文件大小 |
| extract-text.md | 从PDF中提取文本内容并查找指定文本 |
| extract-image.md | 使用PdfPageBase和PdfDocumentExtractor从PDF页面和整个文档中提取图片及图片元数据(边界、索引) |
| ocr.md | 使用Tesseract对扫描PDF和图片执行OCR;支持区域OCR、旋转页面、布局结果、页面分割模式、引擎模式、图片增强、白名单/黑名单、Unicode和图片转PDF转换 |
| tables.md | 使用PdfGrid在PDF中构建表格 |
| headers-and-footers.md | 添加带有自动字段和动态内容的页眉和页脚 |
| bookmarks.md | 创建和管理PDF书签(大纲导航) |
| attachments.md | 在PDF中添加、管理和提取文件附件 |
| security.md | 使用密码和权限对PDF进行加密和保护 |
| actions.md | 为PDF添加交互操作、触发器和JavaScript |
| hyperlinks.md | 使用PdfTextWebLink、PdfDocumentLinkAnnotation和PdfFileLinkAnnotation添加网页URL链接、文档内部导航和外部文件链接 |
| watermarks.md | 添加带有透明度和旋转效果的文本和图片水印 |
| portfolio.md | 创建嵌入多个文件的PDF作品集 |
| layers.md | 在PDF中创建和管理图层(可选内容) |
| metadata.md | 处理文档和图片XMP元数据;属性架构和自定义字段 |
| redact.md | 红action示例与用法(基于文本/图片/模式/正则表达式的红action) |
| digital-sign.md | 数字签名示例:基础签名 → 高级签名(TSA、LTV、外部签名) |
| import-export-annotation.md | 导入和导出注释(FDF、XFDF、JSON)——文件、流和往返工作流 |
| pdf-forms.md | 创建、填写、修改、扁平化和管理AcroForm字段(文本框、下拉框、单选按钮、列表框、复选框、签名、按钮);涵盖字段属性、可见性、只读、自动命名、复杂脚本和外观 |
| import-export-form.md | 导入和导出AcroForm字段数据(FDF、XFDF、JSON)——填充、导出、往返和扁平化 |
| annotations.md | 添加、修改、删除、扁平化PDF注释(弹出框、自由文本、线条、图章、墨迹、标记、URI、红action、云边框等) |
| barcode.md | 添加一维(Code 39、EAN-13、EAN-8、Codabar、Code 93、Code 128、PDF417)和二维(QR、DataMatrix)条码;将条码导出为图片 |
| colorspace.md | 为绘图和图片使用DeviceGray、DeviceRGB、DeviceCMYK和基于ICC的颜色空间 |
| conformance.md | 生成符合PDF/A(1B、2B、3B)和PDF/X标准的文件;将现有PDF转换为合规格式 |
| named-destinations.md | 添加、修改、删除和链接命名目标,用于文档内和基于URL的导航 |
| pdf-templates.md | 创建和使用PdfTemplate、PdfPageTemplateElement(页眉/页脚)和PdfPageTemplate;创建覆盖层并将页面捕获为模板 |
| accessible-pdf.md | 创建标签化PDF、PDF/UA-2、格式正确的标签化PDF,并提取无障碍标签元素 |
| tagged-pdf.md | 创建带逻辑结构树的标签化(无障碍/结构化)PDF,支持屏幕阅读器和重排 |
| zugferd-invoice.md | 创建嵌入XML的ZUGFeRD电子发票PDF(PDF/A-3b);支持ZUGFeRD 1.0、2.0、Factur-X和XRechnung合规级别;从现有ZUGFeRD PDF中提取XML |
| xps-to-pdf.md | 使用XPSToPdfConverter将XPS(XML Paper Specification)文档转换为PDF |
Rules
规则
- Output files go in directory
./output/ - Temp scripts must be created inside
.csx— never in the workspace root or customer{skill-root}/syncfusion-dotnet-pdf/scripts/folderscripts/ - Use license key from at workspace root
SyncfusionLicense.txt - Never use Python libraries (e.g., python-pdf)
- Never leave temp files after execution
.csx - Always use the latest NuGet package version
- 输出文件保存到目录
./output/ - 临时脚本必须创建在
.csx目录下——绝对不能在工作区根目录或客户的{skill-root}/syncfusion-dotnet-pdf/scripts/文件夹中scripts/ - 使用工作区根目录下中的许可证密钥
SyncfusionLicense.txt - 绝不使用Python库(如python-pdf)
- 执行完成后绝不保留临时文件
.csx - 始终使用最新版本的NuGet包
Prerequisites
前置条件
- .NET SDK 8+ and :
dotnet-scriptdotnet tool install -g dotnet-script - Syncfusion License: or env var
SyncfusionLicense.txtSYNCFUSION_LICENSE_KEY - Free license: https://www.syncfusion.com/products/communitylicense
- .NET SDK 8+ 及 :执行
dotnet-script安装dotnet tool install -g dotnet-script - Syncfusion许可证:或环境变量
SyncfusionLicense.txtSYNCFUSION_LICENSE_KEY - 免费许可证:https://www.syncfusion.com/products/communitylicense