syncfusion-dotnet-pdf

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PDF 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
output/agenda.pdf
." Result: Physical file created at specified path
用户: "生成会议议程文档并保存到
output/agenda.pdf
。" 结果: 在指定路径创建实际文件

Two 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:
  1. Build the C# code using snippets from
    references/*.md
    files and replace placeholders with actual content
  2. Add the code directly into the user's project files (e.g.,
    Program.cs
    )
  3. Do not create or run any
    .csx
    script
Note: Use
Syncfusion.Drawing
namespace for this code for cross-platform projects, not
System.Drawing
. This ensures compatibility across Windows, macOS, and Linux.
Note: If
Syncfusion.Pdf.Net.Core
package is suggested, then must be use the
Syncfusion.Drawing
namespace for graphics operations instead of
System.Drawing
to ensure cross-platform compatibility. The
Syncfusion.Pdf.Net.Core
package is designed to work with the
Syncfusion.Drawing
namespace, which provides a consistent API for drawing operations across different platforms. Using
System.Drawing
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
Syncfusion.Drawing
when working with PDF graphics in a cross-platform context.
Note: If RectangleF, PointF, SizeF, or Color types are needed, use the ones from
Syncfusion.Drawing
namespace for cross-platform compatibility, not the ones from
System.Drawing
. This ensures that the code will work correctly on Windows, macOS, and Linux without relying on GDI+.

触发关键词: "code"、"snippet"、"how to write"、"Program.cs"、"show me"、"sample"、"example code"、"generate code for"。
工作流程:
  1. references/*.md
    文件中提取代码片段构建C#代码,并用实际内容替换占位符
  2. 将代码直接添加到用户项目文件中(如
    Program.cs
  3. 创建或运行任何
    .csx
    脚本
注意:跨平台项目中,该代码需使用
Syncfusion.Drawing
命名空间,而非
System.Drawing
,以确保在Windows、macOS和Linux上的兼容性。
注意:若推荐使用
Syncfusion.Pdf.Net.Core
包,图形操作必须使用
Syncfusion.Drawing
命名空间,而非
System.Drawing
,以确保跨平台兼容性。
Syncfusion.Pdf.Net.Core
包专为
Syncfusion.Drawing
命名空间设计,提供跨平台一致的绘图API。使用
System.Drawing
可能导致兼容性问题,尤其是在非Windows平台,因为它依赖于GDI+,而GDI+在Windows以外的平台未得到完全支持。因此,在跨平台场景中处理PDF图形时,务必使用
Syncfusion.Drawing
注意:若需要RectangleF、PointF、SizeF或Color类型,需使用
Syncfusion.Drawing
命名空间下的对应类型,而非
System.Drawing
,以确保代码在Windows、macOS和Linux上正确运行,无需依赖GDI+。

Mode 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
.pdf
file, "without modifying my project", "run a csx script", or when the user provides a file path (e.g.,
output/report.pdf
).
Workflow:
  1. Create
    {skill-root}/syncfusion-dotnet-pdf/scripts/temp-{timestamp}.csx
    using
    references/template.csx
    as the base or
    references/template-ocr.csx
    for OCR-specific operations. Example,
    skill-root
    =
    .github/skills
    .
  2. Add required operations from
    references/*.md
    snippets and replace placeholders with actual content
  3. Run:
    dotnet script {skill-root}/syncfusion-dotnet-pdf/scripts/temp-{timestamp}.csx
  4. Delete the temp script after execution
  5. Report SUCCESS/ERROR and show the output file path
Note: Use
Syncfusion.Drawing
namespace for this csx script, not
System.Drawing
.

触发关键词: "create a pdf document"、"make a document"、"generate a document"、"open"、"edit"、"modify"、"change" a
.pdf
file、"without modifying my project"、"run a csx script",或当用户提供文件路径时(如
output/report.pdf
)。
工作流程:
  1. references/template.csx
    为基础,或针对OCR操作使用
    references/template-ocr.csx
    ,在
    {skill-root}/syncfusion-dotnet-pdf/scripts/
    目录下创建
    temp-{timestamp}.csx
    文件(例如,
    skill-root
    =
    .github/skills
  2. references/*.md
    片段中添加所需操作,并用实际内容替换占位符
  3. 执行:
    dotnet script {skill-root}/syncfusion-dotnet-pdf/scripts/temp-{timestamp}.csx
  4. 执行完成后删除临时脚本
  5. 报告执行成功/错误,并显示输出文件路径
注意:该CSX脚本需使用
Syncfusion.Drawing
命名空间,而非
System.Drawing

Code References

代码参考

All templates and snippets are in the
references/
folder:
FileContents
template.csxCore CSX script template (used in Mode 2)
document-structure.mdDocument lifecycle: create, save, close; sections and page setup
open-pdf.mdOpen 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.mdSave new and loaded PDFs to file path, MemoryStream, byte array, and cloud storage (Azure Blob, AWS S3, Google Drive, Google Cloud Storage, Dropbox)
pages.mdAdd, insert, remove, rotate, rearrange, import, and configure pages; page count, blank detection, page labels, section numbering, PageAdded event, and page-level actions
pdf-graphics.mdWorking with PdfGraphics: text, images, and shapes
shapes.mdDraw shapes: lines, rectangles, ellipses, polygons, arcs, bezier curves, paths
brushes.mdFill shapes with solid, linear gradient, radial gradient, tiling, and hatch brushes; PdfBrushes static colors; combine pen and brush
images.mdInsert, 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.mdDraw 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.mdMerge multiple PDFs into one file
split-pdf.mdDivide a single PDF into separate files
compress-pdf.mdReduce and optimize PDF file size
extract-text.mdRetrieve text content from PDFs and find text within it
extract-image.mdExtract images and image metadata (bounds, index) from PDF pages and entire documents using PdfPageBase and PdfDocumentExtractor
ocr.mdPerform 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.mdBuild tables in PDFs using PdfGrid
headers-and-footers.mdAdd headers and footers with automatic fields and dynamic content
bookmarks.mdCreate and manage PDF bookmarks (outline navigation)
attachments.mdAdd, manage, and extract file attachments in PDFs
security.mdEncrypt and protect PDFs with passwords and permissions
actions.mdAdd interactive actions, triggers, and JavaScript to PDFs
hyperlinks.mdAdd web URL links, internal document navigation, and external file links using PdfTextWebLink, PdfDocumentLinkAnnotation, and PdfFileLinkAnnotation
watermarks.mdAdd text and image watermarks with transparency and rotation
portfolio.mdCreate PDF portfolios embedding multiple files
layers.mdCreate and manage layers (optional content) in PDFs
metadata.mdWork with document and image XMP metadata; properties schemas and custom fields
redact.mdRedaction examples and usage (text/image/pattern/regex-based redaction)
digital-sign.mdDigital signature examples: basic signing → advanced (TSA, LTV, external sign)
import-export-annotation.mdImport and export annotations (FDF, XFDF, JSON) — file, stream, and round-trip workflows
pdf-forms.mdCreate, 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.mdImport and export AcroForm field data (FDF, XFDF, JSON) — fill, export, round-trip, and flatten
annotations.mdAdd, modify, remove, flatten PDF annotations (popup, free text, line, stamp, ink, markup, URI, redaction, cloud border, and more)
barcode.mdAdd 1D (Code 39, EAN-13, EAN-8, Codabar, Code 93, Code 128, PDF417) and 2D (QR, DataMatrix) barcodes; export barcodes as images
colorspace.mdWork with DeviceGray, DeviceRGB, DeviceCMYK, and ICC-based color spaces for drawing and images
conformance.mdProduce PDF/A (1B, 2B, 3B) and PDF/X compliant files; convert existing PDFs to conformance standards
named-destinations.mdAdd, modify, remove, and link named destinations for in-document and URL-based navigation
pdf-templates.mdCreate and use PdfTemplate, PdfPageTemplateElement (header/footer), and PdfPageTemplate; create overlays and capture pages as templates
accessible-pdf.mdCreate tagged PDFs, PDF/UA-2, Well-Tagged PDFs and Extract accessiblity tag elements
tagged-pdf.mdCreate tagged (accessible/structured) PDFs with logical structure trees for screen-reader and reflow support
zugferd-invoice.mdCreate 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.mdConvert 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
    ./output/
    directory
  • Temp
    .csx
    scripts must be created inside
    {skill-root}/syncfusion-dotnet-pdf/scripts/
    — never in the workspace root or customer
    scripts/
    folder
  • Use license key from
    SyncfusionLicense.txt
    at workspace root
  • Never use Python libraries (e.g., python-pdf)
  • Never leave temp
    .csx
    files after execution
  • Always use the latest NuGet package version
  • 输出文件保存到
    ./output/
    目录
  • 临时
    .csx
    脚本必须创建在
    {skill-root}/syncfusion-dotnet-pdf/scripts/
    目录下——绝对不能在工作区根目录或客户的
    scripts/
    文件夹中
  • 使用工作区根目录下
    SyncfusionLicense.txt
    中的许可证密钥
  • 绝不使用Python库(如python-pdf)
  • 执行完成后绝不保留临时
    .csx
    文件
  • 始终使用最新版本的NuGet包

Prerequisites

前置条件

Documentations

文档