syncfusion-flutter-pdf

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PDF 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
    ,
    main.dart
    , etc.) to identify the Flutter platform target (mobile, web, desktop).
  • Tell the user to add
    syncfusion_flutter_pdf
    to their
    pubspec.yaml
    before generating any code.
  • 检查工作区项目文件(
    pubspec.yaml
    main.dart
    等)以识别Flutter目标平台(移动、Web、桌面)。
  • 在生成任何代码之前,告知用户将
    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
    references/*.md
    file(s) for the requested feature
  • 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
      web
      package approach
  • 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
references/
folder:
FileContents
document-structure.mdCreate/load document, page settings, orientation, margins, sections, save to file/stream, incremental update, compression, open encrypted PDF, dispose
pages.mdAdd/insert/remove/rotate pages, get page count, set margins, sections with different page settings, get client size
flow-layout.mdChain elements using PdfLayoutResult, paginate text across pages, PdfLayoutFormat options
text.mdDraw text (drawString, PdfTextElement), standard/TrueType/CJK fonts, RTL text, multicolumn text, pens and brushes
images.mdInsert JPEG/PNG images (PdfBitmap), apply transparency and rotation, insert from web URL
shapes.mdDraw polygon, line, curve, path, rectangle, pie, arc, bezier, ellipse
tables.mdCreate PdfGrid, add columns/headers/rows, cell/row/column customization, built-in styles, pagination, multiple tables
lists.mdOrdered lists (PdfOrderedList), unordered lists (PdfUnorderedList), sub-lists
header-footer.mdAdd headers and footers (PdfPageTemplateElement), automatic fields (page number, page count, date/time), composite fields
bookmarks.mdAdd/insert/remove/modify bookmarks (PdfBookmark), child bookmarks, destination, color, text style
annotations.mdRectangle, ellipse, line, polygon, URI, document link, text web link, text markup, popup annotations; flatten, modify, remove annotations; import/export FDF/XFDF/JSON
hyperlinks.mdWeb navigation links (PdfTextWebLink), URI annotations, internal document navigation (PdfDocumentLinkAnnotation), destination modes
watermarks.mdText and image watermarks with transparency and rotation, apply to all pages via PdfPageTemplateElement stamp
pdf-templates.mdCreate PdfTemplate, draw templates on pages, extract page as template using createTemplate, stamp overlays with PdfPageTemplateElement
digital-signature.mdPdfSignatureField, PdfCertificate, sign new/existing PDF, signature appearance, external signer, multiple signatures, timestamp, LTV
text-extraction.mdExtract text (full/page/range), extract text lines/words/characters with bounds and font info, find text with MatchedItem
pdf-conformance.mdPDF/A-1b, PDF/A-2b, PDF/A-3b conformance levels, embedded fonts requirement, attachment relationships for PDF/A-3b
attachments.mdAdd/remove file attachments (PdfAttachment), attach from base64, extract and save to disk, PDF/A-3b attachment metadata
layers.mdAdd/toggle/remove layers (PdfPageLayer), nested layers (PdfLayer), visibility control, flatten layers
forms.mdAcroForm 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.mdRC4 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.mdPdfSignatureField、PdfCertificate、签署新/现有PDF、签名外观、外部签名者、多重签名、时间戳、LTV
text-extraction.md提取文本(全文/页面/范围)、提取带有边界和字体信息的文本行/单词/字符、使用MatchedItem查找文本
pdf-conformance.mdPDF/A-1b、PDF/A-2b、PDF/A-3b合规级别、嵌入字体要求、PDF/A-3b的附件关联
attachments.md添加/删除文件附件(PdfAttachment)、从base64附加、提取并保存到磁盘、PDF/A-3b附件元数据
layers.md添加/切换/删除图层(PdfPageLayer)、嵌套图层(PdfLayer)、可见性控制、扁平化图层
forms.mdAcroForm字段:文本框、组合框、单选按钮、列表框、复选框、签名、按钮;填充/修改/扁平化/删除字段;导入/导出FDF/XFDF/JSON/XML
encryption.mdRC4和AES加密、用户/所有者密码、权限(打印、复制、编辑)、保护现有PDF、更改/移除密码

Rules

规则

  • Output files go in
    ./output/
    directory
  • Temp
    .dart
    scripts must be created inside
    {skill-root}/flutter/pdf/scripts/
    — never in the workspace root or customer
    scripts/
    folder
  • Never leave temp
    .dart
    files after execution
  • Always call
    document.dispose()
    after saving
  • All units in PDF are in points (not pixels)
  • Use
    PdfLayoutResult
    to chain elements and avoid content overlap
  • 输出文件放入
    ./output/
    目录
  • 临时
    .dart
    脚本必须创建在
    {skill-root}/flutter/pdf/scripts/
    中 — 绝不能放在工作区根目录或客户的
    scripts/
    文件夹中
  • 执行后不得遗留临时
    .dart
    文件
  • 保存后必须调用
    document.dispose()
  • PDF中的所有单位都是(不是像素)
  • 使用
    PdfLayoutResult
    链式连接元素,避免内容重叠

Prerequisites

前提条件

  • Flutter SDK installed
  • Add to
    pubspec.yaml
    :
    yaml
    dependencies:
      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.yaml
    yaml
    dependencies:
      syncfusion_flutter_pdf: ^xx.x.xx
  • 运行:
    flutter pub get
  • 在Dart代码中导入:
    dart
    import 'package:syncfusion_flutter_pdf/pdf.dart';