syncfusion-wpf-pdf-viewer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSyncfusion WPF PDFViewer – UI Sample Generator
Syncfusion WPF PDFViewer – UI示例生成器
Generate C# Code for the User's Project (default)
为用户项目生成C#代码(默认选项)
Trigger keywords: "how to", "code sample", "show me", "example", "snippet", "integrate", "wpf PdfViewer", "create sample".
Purpose: Generate clean, ready-to-use C# and XAML code snippets that users can directly insert into their WPF applications when working with the Syncfusion WPF PdfViewer control.
Workflow:
-
Build the C# code using snippets provided in thefiles.
references/*.md -
Before generating the sample, ask the user whether the code should be inserted into an existing XAML file in their WPF project or created as a new WPF project application.
-
If the user chooses to create a new WPF project, ask them which target framework they want to use:
- .NET Framework (e.g. 4.6, 4.7, 4.8) — uses and targets classic .NET Framework.
Syncfusion.PdfViewer.WPF - .NET Core / .NET (e.g., .NET 8, .NET 10) — uses with
Syncfusion.PdfViewer.WPF(or the selected version).<TargetFramework>net8.0-windows</TargetFramework> - Based on the user's choice, generate the file with the correct
.csprojvalue, and tailor any framework-specific code (e.g., namespace imports, NuGet package versions, startup code) accordingly.<TargetFramework>
- .NET Framework (e.g. 4.6, 4.7, 4.8) — uses
-
XAML generation rules — MANDATORY: analyze the reference files BEFORE writing any XAML:⚠️ STRICT RULE — NO EXCEPTIONS: Open and read the relevantfile(s) for the requested feature before producing any XAML. Ask yourself: "Does the reference file contain any XAML markup for this feature?"
references/*.md- YES → XAML exists in reference → include only those exact XAML elements shown in the snippet.
- NO → reference is C# only → MUST contain only
MainWindow.xamlinside a<syncfusion:PdfViewerControl>. Stop. Do not add anything else.<Grid>
Checklist to run before every XAML output:- I have opened the relevant file.
references/*.md - I have confirmed whether it contains XAML or is C#-only.
- If C#-only: my XAML contains nothing beyond inside
<syncfusion:PdfViewerControl x:Name="pdfViewer"/>.<Grid> - If XAML exists in reference: I am copying only those elements — not inventing new ones.
Forbidden (when reference has no XAML):,<Button>,<ComboBox>,<Slider>,<StackPanel>,<TextBlock>, or any UI element that does not appear verbatim in the reference snippet.<Grid.RowDefinitions>Known C#-only features (no XAML must be generated):- Ink / shape / stamp / text / highlight annotations () — all settings are C# only.
annotation.md - Magnifying / zoom level () — C# only.
magnifying.md - Interaction mode () — C# only.
interaction-mode.md - Text selection () — C# only.
text-selection.md - PDF layers () — C# only.
pdf-layers.md - Redaction () — C# only.
redaction.md - Print () — C# only.
print.md - Export image () — C# only.
export-image.md - Saving PDF () — C# only.
saving-pdf-files.md
Known features that DO require XAML (sourced from references):- Commands (): navigation/zoom/annotation/undo/redo/print/unload buttons use
commands.md.Command="{Binding ElementName=..., Path=...}" - Toolbar items (): classic style requires
toolbar-items.mdonStyle="{StaticResource SyncfusionPdfViewerCustomControlStyle}".<syncfusion:PdfViewerControl>
All XAML additions must be placed inside the samethat hosts<Grid>, using a<syncfusion:PdfViewerControl>or<StackPanel>sub-layout only when the reference snippet implies it.<Grid> -
Add only the APIs required to satisfy the user's requested functionality. Do not include optional APIs, additional.
-
C# language version compatibility: When the target framework is .NET Framework (e.g., 4.6, 4.7, 4.8), the default C# language version is 7.3. The generated C# code MUST NOT use any C# 8.0+ language features. Specifically, do NOT use:
- Switch expressions ()
x switch { ... } - Nullable reference types (,
string?,#nullable enable)object? - Default interface implementations
- Ranges and indices (,
^1)1..^1 - null-coalescing assignment Use
??=or traditionalif/elsestatements instead of switch expressions. Use regular null checks (switch) instead of nullable reference type syntax.if (x != null)
- Switch expressions (
触发关键词: "how to"、"code sample"、"show me"、"example"、"snippet"、"integrate"、"wpf PdfViewer"、"create sample"。
用途: 生成简洁、可直接使用的C#和XAML代码片段,用户可将其直接插入到使用Syncfusion WPF PdfViewer控件的WPF应用程序中。
工作流程:
-
使用文件中提供的代码片段构建C#代码。
references/*.md -
在生成示例之前,询问用户代码应插入到WPF项目中现有的XAML文件,还是创建为新的WPF项目应用程序。
-
如果用户选择创建新WPF项目,询问他们要使用哪个目标框架:
- .NET Framework(例如4.6、4.7、4.8)——使用,面向经典.NET Framework。
Syncfusion.PdfViewer.WPF - .NET Core / .NET(例如.NET 8、.NET 10)——使用,并设置
Syncfusion.PdfViewer.WPF(或所选版本)。<TargetFramework>net8.0-windows</TargetFramework> - 根据用户的选择,生成具有正确值的
<TargetFramework>文件,并调整任何框架特定代码(例如命名空间导入、NuGet包版本、启动代码)。.csproj
- .NET Framework(例如4.6、4.7、4.8)——使用
-
XAML生成规则——强制要求:在编写任何XAML之前分析参考文件⚠️ 严格规则——无例外: 在生成任何XAML之前,打开并阅读所请求功能对应的文件。 自问:“参考文件中是否包含此功能的XAML标记?”
references/*.md- 是→参考文件中有XAML→仅包含代码片段中显示的那些确切XAML元素。
- 否→参考文件仅含C#代码→必须仅在
MainWindow.xaml内包含<Grid>。停止操作,不得添加其他内容。<syncfusion:PdfViewerControl>
每次输出XAML前需检查的事项:- 已打开相关的文件。
references/*.md - 已确认文件包含XAML还是仅含C#代码。
- 如果仅含C#代码:我的XAML除了内的
<Grid>之外无其他内容。<syncfusion:PdfViewerControl x:Name="pdfViewer"/> - 如果参考文件中有XAML:我仅复制那些元素——不自行创建新元素。
禁止操作(当参考文件无XAML时): 添加、<Button>、<ComboBox>、<Slider>、<StackPanel>、<TextBlock>或任何未在参考代码片段中出现的UI元素。<Grid.RowDefinitions>已知仅需C#代码的功能(不得生成XAML):- 墨迹/形状/图章/文本/高亮批注()——所有设置均仅通过C#实现。
annotation.md - 放大/缩放级别()——仅通过C#实现。
magnifying.md - 交互模式()——仅通过C#实现。
interaction-mode.md - 文本选择()——仅通过C#实现。
text-selection.md - PDF图层()——仅通过C#实现。
pdf-layers.md - 红action()——仅通过C#实现。
redaction.md - 打印()——仅通过C#实现。
print.md - 导出图片()——仅通过C#实现。
export-image.md - 保存PDF()——仅通过C#实现。
saving-pdf-files.md
已知需要XAML的功能(源自参考文件):- 命令():导航/缩放/批注/撤销/重做/打印/卸载按钮使用
commands.md。Command="{Binding ElementName=..., Path=...}" - 工具栏项():经典样式需要在
toolbar-items.md上设置<syncfusion:PdfViewerControl>。Style="{StaticResource SyncfusionPdfViewerCustomControlStyle}"
所有XAML新增内容必须放置在承载的同一<syncfusion:PdfViewerControl>内,仅当参考代码片段有暗示时才使用<Grid>或<StackPanel>子布局。<Grid> -
仅添加满足用户请求功能所需的API。不得包含可选API或额外内容。
-
C#语言版本兼容性: 当目标框架为**.NET Framework**(例如4.6、4.7、4.8)时,默认C#语言版本为7.3。生成的C#代码不得使用任何C# 8.0+的语言特性。具体而言,不得使用:
- 开关表达式()
x switch { ... } - 可空引用类型(、
string?、#nullable enable)object? - 默认接口实现
- 范围和索引(、
^1)1..^1 - 空合并赋值 使用
??=或传统if/else语句替代开关表达式。使用常规空检查(switch)替代可空引用类型语法。if (x != null)
- 开关表达式(
Code References
代码参考
All templates and operation snippets live in . Each file is a focused snippet or template the agent will combine when generating samples.
references/*.md| File | Purpose |
|---|---|
| Load-sample.md | Load and unload PDFs using file paths, streams, or PdfLoadedDocument (encrypted or not); support async loading, MVVM binding, password handling, loading indicator customization, and theme application. |
| navigation.md | Navigate PDF pages using index‑ or number‑based APIs; retrieve page state information; scroll programmatically; manage thumbnails and bookmarks; and handle hyperlink navigation events. |
| annotation.md | Enable, customize, and manage all annotation types; handle annotation events; programmatically select, hide, lock, or delete annotations; control comments panel, authorship, hyperlinks, and selection visuals. |
| pdf-rendering.md | Configure the PDF rendering engine by switching between PDFium and SfPdf and setting the required ReferencePath. |
| text-extraction-engine.md | Select the text extraction engine (PDFium or SfPdf) to control text extraction behavior. |
| print.md | Print PDFs with silent or dialog options; configure printers, page size, scaling, orientation, page range, paper source, and document name; and handle print lifecycle events. |
| export-image.md | Export PDF pages or page ranges as images (JPG, PNG, TIFF, BMP) with control over size, DPI, aspect ratio, and transparency. |
| import-export-annotations.md | Import and export annotations using FDF or XFDF formats. |
| extract-text-from-pdf.md | Extract text content and bounding information from pages or the entire document. |
| form-filling.md | Handle AcroForm fields: manage form events, show or hide icons, import/export form data, and add or edit form fields programmatically. |
| pdf-layers.md | Access and manage PDF layers by toggling visibility, enabling or disabling layers, and controlling the Layers pane UI. |
| redaction.md | Apply redactions by marking regions, customizing appearance, and handling redaction events. |
| pdf-coordinates.md | Convert between coordinate systems, retrieve scroll offsets, and zoom into specific page regions. |
| organize-pages.md | Rotate, reorder, and remove pages using page organizer features. |
| handwritten-signature.md | Capture handwritten signatures, customize appearance, handle signature events, and flatten signatures on save. |
| interaction-mode.md | Switch viewer interaction modes such as text selection, panning, and marquee zoom using cursor settings. |
| pdf-pages.md | Customize page appearance, handle page interaction events, and convert pixel coordinates to PDF points. |
| saving-pdf-files.md | Save edited PDFs, detect unsaved changes, cancel save operations, handle save events, and prompt before closing with pending edits. |
| magnifying.md | Control zoom behavior including zoom levels, fit modes, limits, zoom-to-rectangle, toolbar visibility, and zoom change events. |
| searching-text.md | Search and highlight text, navigate results, retrieve match bounds and text details, support multi-line search, and control search UI and availability. |
| text-selection.md | Detect text selection completion, retrieve selected text and bounds, customize highlight color, enable or disable selection, and clear selections programmatically. |
| localization.md | Localize the PDF Viewer UI using .resx resources and culture settings. |
| customize-contextmenu.md | Customize context menus by adding, removing, hiding items, and handling menu click events. |
| commands.md | Use and bind built‑in WPF commands for navigation, zoom, search, annotations, undo/redo, printing, saving, and unloading documents. |
| toolbar-items.md | Customize viewer UI by showing or hiding toolbars, panels, buttons, menus, notification bars, and switching toolbar styles. |
所有模板和操作代码片段都存储在中。代理生成示例时会组合这些专注于特定功能的代码片段或模板。
references/*.md| 文件 | 用途 |
|---|---|
| Load-sample.md | 使用文件路径、流或PdfLoadedDocument(加密或未加密)加载和卸载PDF;支持异步加载、MVVM绑定、密码处理、加载指示器自定义以及主题应用。 |
| navigation.md | 使用基于索引或页码的API导航PDF页面;获取页面状态信息;以编程方式滚动;管理缩略图和书签;处理超链接导航事件。 |
| annotation.md | 启用、自定义和管理所有批注类型;处理批注事件;以编程方式选择、隐藏、锁定或删除批注;控制批注面板、作者信息、超链接和选择视觉效果。 |
| pdf-rendering.md | 通过在PDFium和SfPdf之间切换并设置所需的ReferencePath来配置PDF渲染引擎。 |
| text-extraction-engine.md | 选择文本提取引擎(PDFium或SfPdf)以控制文本提取行为。 |
| print.md | 使用静默或对话框选项打印PDF;配置打印机、页面大小、缩放、方向、页面范围、纸张来源和文档名称;处理打印生命周期事件。 |
| export-image.md | 将PDF页面或页面范围导出为图片(JPG、PNG、TIFF、BMP),可控制尺寸、DPI、宽高比和透明度。 |
| import-export-annotations.md | 使用FDF或XFDF格式导入和导出批注。 |
| extract-text-from-pdf.md | 从页面或整个文档中提取文本内容和边界信息。 |
| form-filling.md | 处理AcroForm字段:管理表单事件、显示或隐藏图标、导入/导出表单数据、以编程方式添加或编辑表单字段。 |
| pdf-layers.md | 通过切换可见性、启用或禁用图层以及控制图层窗格UI来访问和管理PDF图层。 |
| redaction.md | 通过标记区域、自定义外观和处理红action事件来应用红action。 |
| pdf-coordinates.md | 在坐标系之间转换、获取滚动偏移量以及放大到特定页面区域。 |
| organize-pages.md | 使用页面管理器功能旋转、重新排序和删除页面。 |
| handwritten-signature.md | 捕获手写签名、自定义外观、处理签名事件以及保存时扁平化签名。 |
| interaction-mode.md | 使用光标设置切换查看器交互模式,例如文本选择、平移和框选缩放。 |
| pdf-pages.md | 自定义页面外观、处理页面交互事件以及将像素坐标转换为PDF点数。 |
| saving-pdf-files.md | 保存编辑后的PDF、检测未保存更改、取消保存操作、处理保存事件以及在关闭前提示未完成的编辑。 |
| magnifying.md | 控制缩放行为,包括缩放级别、适配模式、限制、矩形缩放、工具栏可见性和缩放更改事件。 |
| searching-text.md | 搜索并高亮文本、导航搜索结果、获取匹配范围和文本详情、支持多行搜索以及控制搜索UI和可用性。 |
| text-selection.md | 检测文本选择完成、获取选中的文本和范围、自定义高亮颜色、启用或禁用选择以及以编程方式清除选择。 |
| localization.md | 使用.resx资源和区域设置本地化PDF查看器UI。 |
| customize-contextmenu.md | 通过添加、删除、隐藏菜单项以及处理菜单点击事件来自定义上下文菜单。 |
| commands.md | 使用并绑定内置WPF命令,用于导航、缩放、搜索、批注、撤销/重做、打印、保存和卸载文档。 |
| toolbar-items.md | 通过显示或隐藏工具栏、面板、按钮、菜单、通知栏以及切换工具栏样式来自定义查看器UI。 |
Prerequisites
先决条件
- Development Environment: Visual Studio 2022 or Visual Studio Insider 2026 (recommended for .NET 10).
- NET Framework 4.5+ or .NET Core/.NET 8+ with WPF support.
- Syncfusion WPF NuGet Packages:
Syncfusion.PdfViewer.WPF
- 开发环境:Visual Studio 2022或Visual Studio Insider 2026(推荐用于.NET 10)。
- .NET Framework 4.5+或带WPF支持的.NET Core/.NET 8+。
- Syncfusion WPF NuGet包:
Syncfusion.PdfViewer.WPF
Theme NuGet Packages
主题NuGet包
To apply a built-in theme to the WPF PdfViewerControl using , install the NuGet package that matches the desired theme:
SfSkinManager| Theme Name | Required NuGet Package |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
Note: Install only the NuGet package corresponding to the theme the user wants to apply. Theme support requires, which is included as a dependency of the theme packages.Syncfusion.SfSkinManager.WPFRefer to: Apply theme using SfSkinManager | WPF PdfViewer Theme
要使用为WPF PdfViewerControl应用内置主题,请安装与所需主题匹配的NuGet包:
SfSkinManager| 主题名称 | 所需NuGet包 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
注意: 仅安装与用户想要应用的主题对应的NuGet包。主题支持需要,它是主题包的依赖项。Syncfusion.SfSkinManager.WPF