syncfusion-flutter-pdf
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePDF Document Processing Using Syncfusion Flutter PDF Library
使用Syncfusion Flutter PDF库处理PDF文档
Create, edit, and save PDF documents (.pdf) using the Syncfusion Flutter PDF library.
This skill supports generating Dart code snippets for Flutter projects targeting mobile, web, and desktop platforms.
使用Syncfusion Flutter PDF库创建、编辑和保存PDF文档(.pdf)。
该技能支持为面向移动、Web和桌面平台的Flutter项目生成Dart代码片段。
Generate Dart Code for the User's Flutter Project (default)
为用户的Flutter项目生成Dart代码(默认模式)
Trigger keywords: "show me how", "how to", "how can I", "how do I", "provide code", "provide an example", "give an example", "demonstrate", "code snippet", "sample code", "example", "sample", "give me", "show me", "main.dart", "example code", "generate code for", "codesnippet".
Workflow:
触发关键词: "show me how", "how to", "how can I", "how do I", "provide code", "provide an example", "give an example", "demonstrate", "code snippet", "sample code", "example", "sample", "give me", "show me", "main.dart", "example code", "generate code for", "codesnippet"。
工作流程:
Step 1 — Detect the Platform and Suggest the Correct Package
步骤1 — 检测平台并推荐正确的包
- Inspect the workspace project files (,
pubspec.yaml, etc.) to identify the Flutter platform target (mobile, web, desktop).main.dart - Tell the user to add to their
syncfusion_flutter_pdfbefore generating any code.pubspec.yaml
- 检查工作区项目文件(、
pubspec.yaml等)以识别Flutter目标平台(移动、Web、桌面)。main.dart - 在生成任何代码之前,告知用户将添加到他们的
syncfusion_flutter_pdf中。pubspec.yaml
Step 2 — Generate Code from Reference Files Only
步骤2 — 仅从参考文件生成代码
Do NOT invent, guess, or suggest any API, class, method, or property not explicitly present in the reference files.
- Read the relevant file(s) for the requested feature
references/*.md - Build Dart code strictly from the APIs and snippets found in those files
- Use the correct save/launch pattern for the target platform:
- Mobile → +
getApplicationSupportDirectory()OpenFile.open() - Desktop → +
getApplicationSupportDirectory()OpenFile.open() - Web → base64 + JavaScript download or package approach
web
- Mobile →
- Do not create or run any standalone Dart script
不得发明、猜测或推荐任何未在参考文件中明确提及的API、类、方法或属性。
- 读取与所需功能相关的文件
references/*.md - 严格根据这些文件中的API和片段构建Dart代码
- 针对目标平台使用正确的保存/启动模式:
- 移动 → +
getApplicationSupportDirectory()OpenFile.open() - 桌面 → +
getApplicationSupportDirectory()OpenFile.open() - Web → base64 + JavaScript下载或包方案
web
- 移动 →
- 不得创建或运行任何独立的Dart脚本
Code References
代码参考
All snippets are in the folder:
references/| File | Contents |
|---|---|
| document-structure.md | Create/load document, page settings, orientation, margins, sections, save to file/stream, incremental update, compression, open encrypted PDF, dispose |
| pages.md | Add/insert/remove/rotate pages, get page count, set margins, sections with different page settings, get client size |
| flow-layout.md | Chain elements using PdfLayoutResult, paginate text across pages, PdfLayoutFormat options |
| text.md | Draw text (drawString, PdfTextElement), standard/TrueType/CJK fonts, RTL text, multicolumn text, pens and brushes |
| images.md | Insert JPEG/PNG images (PdfBitmap), apply transparency and rotation, insert from web URL |
| shapes.md | Draw polygon, line, curve, path, rectangle, pie, arc, bezier, ellipse |
| tables.md | Create PdfGrid, add columns/headers/rows, cell/row/column customization, built-in styles, pagination, multiple tables |
| lists.md | Ordered lists (PdfOrderedList), unordered lists (PdfUnorderedList), sub-lists |
| header-footer.md | Add headers and footers (PdfPageTemplateElement), automatic fields (page number, page count, date/time), composite fields |
| bookmarks.md | Add/insert/remove/modify bookmarks (PdfBookmark), child bookmarks, destination, color, text style |
| annotations.md | Rectangle, ellipse, line, polygon, URI, document link, text web link, text markup, popup annotations; flatten, modify, remove annotations; import/export FDF/XFDF/JSON |
| hyperlinks.md | Web navigation links (PdfTextWebLink), URI annotations, internal document navigation (PdfDocumentLinkAnnotation), destination modes |
| watermarks.md | Text and image watermarks with transparency and rotation, apply to all pages via PdfPageTemplateElement stamp |
| pdf-templates.md | Create PdfTemplate, draw templates on pages, extract page as template using createTemplate, stamp overlays with PdfPageTemplateElement |
| digital-signature.md | PdfSignatureField, PdfCertificate, sign new/existing PDF, signature appearance, external signer, multiple signatures, timestamp, LTV |
| text-extraction.md | Extract text (full/page/range), extract text lines/words/characters with bounds and font info, find text with MatchedItem |
| pdf-conformance.md | PDF/A-1b, PDF/A-2b, PDF/A-3b conformance levels, embedded fonts requirement, attachment relationships for PDF/A-3b |
| attachments.md | Add/remove file attachments (PdfAttachment), attach from base64, extract and save to disk, PDF/A-3b attachment metadata |
| layers.md | Add/toggle/remove layers (PdfPageLayer), nested layers (PdfLayer), visibility control, flatten layers |
| forms.md | AcroForm fields: text box, combo box, radio button, list box, check box, signature, button; fill/modify/flatten/remove fields; import/export FDF/XFDF/JSON/XML |
| encryption.md | RC4 and AES encryption, user/owner passwords, permissions (print, copy, edit), protect existing PDF, change/remove password |
所有片段都在文件夹中:
references/| 文件 | 内容 |
|---|---|
| document-structure.md | 创建/加载文档、页面设置、方向、边距、章节、保存到文件/流、增量更新、压缩、打开加密PDF、释放资源 |
| pages.md | 添加/插入/删除/旋转页面、获取页面数量、设置边距、带有不同页面设置的章节、获取客户端尺寸 |
| flow-layout.md | 使用PdfLayoutResult链式连接元素、跨页面分页文本、PdfLayoutFormat选项 |
| text.md | 绘制文本(drawString、PdfTextElement)、标准/TrueType/CJK字体、RTL文本、多列文本、画笔和画刷 |
| images.md | 插入JPEG/PNG图片(PdfBitmap)、应用透明度和旋转、从Web URL插入 |
| shapes.md | 绘制多边形、线条、曲线、路径、矩形、饼图、圆弧、贝塞尔曲线、椭圆 |
| tables.md | 创建PdfGrid、添加列/表头/行、单元格/行/列自定义、内置样式、分页、多表格 |
| lists.md | 有序列表(PdfOrderedList)、无序列表(PdfUnorderedList)、子列表 |
| header-footer.md | 添加页眉和页脚(PdfPageTemplateElement)、自动字段(页码、总页数、日期/时间)、复合字段 |
| bookmarks.md | 添加/插入/删除/修改书签(PdfBookmark)、子书签、目标、颜色、文本样式 |
| annotations.md | 矩形、椭圆、线条、多边形、URI、文档链接、文本网页链接、文本标记、弹出注释;扁平化、修改、删除注释;导入/导出FDF/XFDF/JSON |
| hyperlinks.md | 网页导航链接(PdfTextWebLink)、URI注释、文档内部导航(PdfDocumentLinkAnnotation)、目标模式 |
| watermarks.md | 带有透明度和旋转的文本和图片水印、通过PdfPageTemplateElement印章应用到所有页面 |
| pdf-templates.md | 创建PdfTemplate、在页面上绘制模板、使用createTemplate将页面提取为模板、使用PdfPageTemplateElement印章叠加层 |
| digital-signature.md | PdfSignatureField、PdfCertificate、签署新/现有PDF、签名外观、外部签名者、多重签名、时间戳、LTV |
| text-extraction.md | 提取文本(全文/页面/范围)、提取带有边界和字体信息的文本行/单词/字符、使用MatchedItem查找文本 |
| pdf-conformance.md | PDF/A-1b、PDF/A-2b、PDF/A-3b合规级别、嵌入字体要求、PDF/A-3b的附件关联 |
| attachments.md | 添加/删除文件附件(PdfAttachment)、从base64附加、提取并保存到磁盘、PDF/A-3b附件元数据 |
| layers.md | 添加/切换/删除图层(PdfPageLayer)、嵌套图层(PdfLayer)、可见性控制、扁平化图层 |
| forms.md | AcroForm字段:文本框、组合框、单选按钮、列表框、复选框、签名、按钮;填充/修改/扁平化/删除字段;导入/导出FDF/XFDF/JSON/XML |
| encryption.md | RC4和AES加密、用户/所有者密码、权限(打印、复制、编辑)、保护现有PDF、更改/移除密码 |
Rules
规则
- Output files go in directory
./output/ - Temp scripts must be created inside
.dart— never in the workspace root or customer{skill-root}/flutter/pdf/scripts/folderscripts/ - Never leave temp files after execution
.dart - Always call after saving
document.dispose() - All units in PDF are in points (not pixels)
- Use to chain elements and avoid content overlap
PdfLayoutResult
- 输出文件放入目录
./output/ - 临时脚本必须创建在
.dart中 — 绝不能放在工作区根目录或客户的{skill-root}/flutter/pdf/scripts/文件夹中scripts/ - 执行后不得遗留临时文件
.dart - 保存后必须调用
document.dispose() - PDF中的所有单位都是点(不是像素)
- 使用链式连接元素,避免内容重叠
PdfLayoutResult
Prerequisites
前提条件
- Flutter SDK installed
- Add to :
pubspec.yamlyamldependencies: syncfusion_flutter_pdf: ^xx.x.xx - Run:
flutter pub get - Import in Dart code:
dart
import 'package:syncfusion_flutter_pdf/pdf.dart';
- 已安装Flutter SDK
- 添加到:
pubspec.yamlyamldependencies: syncfusion_flutter_pdf: ^xx.x.xx - 运行:
flutter pub get - 在Dart代码中导入:
dart
import 'package:syncfusion_flutter_pdf/pdf.dart';