syncfusion-wpf-pdf-viewer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Syncfusion 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:
  1. Build the C# code using snippets provided in the
    references/*.md
    files.
  2. 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.
  3. 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
      Syncfusion.PdfViewer.WPF
      and targets classic .NET Framework.
    • .NET Core / .NET (e.g., .NET 8, .NET 10) — uses
      Syncfusion.PdfViewer.WPF
      with
      <TargetFramework>net8.0-windows</TargetFramework>
      (or the selected version).
    • Based on the user's choice, generate the
      .csproj
      file with the correct
      <TargetFramework>
      value, and tailor any framework-specific code (e.g., namespace imports, NuGet package versions, startup code) accordingly.
  4. XAML generation rules — MANDATORY: analyze the reference files BEFORE writing any XAML:
    ⚠️ STRICT RULE — NO EXCEPTIONS: Open and read the relevant
    references/*.md
    file(s) for the requested feature before producing any XAML. Ask yourself: "Does the reference file contain any XAML markup for this feature?"
    • YES → XAML exists in reference → include only those exact XAML elements shown in the snippet.
    • NO → reference is C# only
      MainWindow.xaml
      MUST contain only
      <syncfusion:PdfViewerControl>
      inside a
      <Grid>
      . Stop. Do not add anything else.
    Checklist to run before every XAML output:
    • I have opened the relevant
      references/*.md
      file.
    • I have confirmed whether it contains XAML or is C#-only.
    • If C#-only: my XAML contains nothing beyond
      <syncfusion:PdfViewerControl x:Name="pdfViewer"/>
      inside
      <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>
    ,
    <Grid.RowDefinitions>
    , or any UI element that does not appear verbatim in the reference snippet.
    Known C#-only features (no XAML must be generated):
    • Ink / shape / stamp / text / highlight annotations (
      annotation.md
      ) — all settings are C# only.
    • Magnifying / zoom level (
      magnifying.md
      ) — C# only.
    • Interaction mode (
      interaction-mode.md
      ) — C# only.
    • Text selection (
      text-selection.md
      ) — C# only.
    • PDF layers (
      pdf-layers.md
      ) — C# only.
    • Redaction (
      redaction.md
      ) — C# only.
    • Print (
      print.md
      ) — C# only.
    • Export image (
      export-image.md
      ) — C# only.
    • Saving PDF (
      saving-pdf-files.md
      ) — C# only.
    Known features that DO require XAML (sourced from references):
    • Commands (
      commands.md
      ): navigation/zoom/annotation/undo/redo/print/unload buttons use
      Command="{Binding ElementName=..., Path=...}"
      .
    • Toolbar items (
      toolbar-items.md
      ): classic style requires
      Style="{StaticResource SyncfusionPdfViewerCustomControlStyle}"
      on
      <syncfusion:PdfViewerControl>
      .
    All XAML additions must be placed inside the same
    <Grid>
    that hosts
    <syncfusion:PdfViewerControl>
    , using a
    <StackPanel>
    or
    <Grid>
    sub-layout only when the reference snippet implies it.
  5. Add only the APIs required to satisfy the user's requested functionality. Do not include optional APIs, additional.
  6. 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
      if/else
      or traditional
      switch
      statements instead of switch expressions. Use regular null checks (
      if (x != null)
      ) instead of nullable reference type syntax.

触发关键词: "how to"、"code sample"、"show me"、"example"、"snippet"、"integrate"、"wpf PdfViewer"、"create sample"。
用途: 生成简洁、可直接使用的C#和XAML代码片段,用户可将其直接插入到使用Syncfusion WPF PdfViewer控件的WPF应用程序中。
工作流程:
  1. 使用
    references/*.md
    文件中提供的代码片段构建C#代码。
  2. 在生成示例之前,询问用户代码应插入到WPF项目中现有的XAML文件,还是创建为新的WPF项目应用程序。
  3. 如果用户选择创建新WPF项目,询问他们要使用哪个目标框架:
    • .NET Framework(例如4.6、4.7、4.8)——使用
      Syncfusion.PdfViewer.WPF
      ,面向经典.NET Framework。
    • .NET Core / .NET(例如.NET 8、.NET 10)——使用
      Syncfusion.PdfViewer.WPF
      ,并设置
      <TargetFramework>net8.0-windows</TargetFramework>
      (或所选版本)。
    • 根据用户的选择,生成具有正确
      <TargetFramework>
      值的
      .csproj
      文件,并调整任何框架特定代码(例如命名空间导入、NuGet包版本、启动代码)。
  4. XAML生成规则——强制要求:在编写任何XAML之前分析参考文件
    ⚠️ 严格规则——无例外: 在生成任何XAML之前,打开并阅读所请求功能对应的
    references/*.md
    文件。 自问:“参考文件中是否包含此功能的XAML标记?”
    • 是→参考文件中有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>
    <Grid.RowDefinitions>
    或任何未在参考代码片段中出现的UI元素。
    已知仅需C#代码的功能(不得生成XAML):
    • 墨迹/形状/图章/文本/高亮批注(
      annotation.md
      )——所有设置均仅通过C#实现。
    • 放大/缩放级别(
      magnifying.md
      )——仅通过C#实现。
    • 交互模式(
      interaction-mode.md
      )——仅通过C#实现。
    • 文本选择(
      text-selection.md
      )——仅通过C#实现。
    • PDF图层(
      pdf-layers.md
      )——仅通过C#实现。
    • 红action(
      redaction.md
      )——仅通过C#实现。
    • 打印(
      print.md
      )——仅通过C#实现。
    • 导出图片(
      export-image.md
      )——仅通过C#实现。
    • 保存PDF(
      saving-pdf-files.md
      )——仅通过C#实现。
    已知需要XAML的功能(源自参考文件):
    • 命令
      commands.md
      ):导航/缩放/批注/撤销/重做/打印/卸载按钮使用
      Command="{Binding ElementName=..., Path=...}"
    • 工具栏项
      toolbar-items.md
      ):经典样式需要在
      <syncfusion:PdfViewerControl>
      上设置
      Style="{StaticResource SyncfusionPdfViewerCustomControlStyle}"
    所有XAML新增内容必须放置在承载
    <syncfusion:PdfViewerControl>
    的同一
    <Grid>
    内,仅当参考代码片段有暗示时才使用
    <StackPanel>
    <Grid>
    子布局。
  5. 仅添加满足用户请求功能所需的API。不得包含可选API或额外内容。
  6. 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
references/*.md
. Each file is a focused snippet or template the agent will combine when generating samples.
FilePurpose
Load-sample.mdLoad 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.mdNavigate PDF pages using index‑ or number‑based APIs; retrieve page state information; scroll programmatically; manage thumbnails and bookmarks; and handle hyperlink navigation events.
annotation.mdEnable, 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.mdConfigure the PDF rendering engine by switching between PDFium and SfPdf and setting the required ReferencePath.
text-extraction-engine.mdSelect the text extraction engine (PDFium or SfPdf) to control text extraction behavior.
print.mdPrint 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.mdExport PDF pages or page ranges as images (JPG, PNG, TIFF, BMP) with control over size, DPI, aspect ratio, and transparency.
import-export-annotations.mdImport and export annotations using FDF or XFDF formats.
extract-text-from-pdf.mdExtract text content and bounding information from pages or the entire document.
form-filling.mdHandle AcroForm fields: manage form events, show or hide icons, import/export form data, and add or edit form fields programmatically.
pdf-layers.mdAccess and manage PDF layers by toggling visibility, enabling or disabling layers, and controlling the Layers pane UI.
redaction.mdApply redactions by marking regions, customizing appearance, and handling redaction events.
pdf-coordinates.mdConvert between coordinate systems, retrieve scroll offsets, and zoom into specific page regions.
organize-pages.mdRotate, reorder, and remove pages using page organizer features.
handwritten-signature.mdCapture handwritten signatures, customize appearance, handle signature events, and flatten signatures on save.
interaction-mode.mdSwitch viewer interaction modes such as text selection, panning, and marquee zoom using cursor settings.
pdf-pages.mdCustomize page appearance, handle page interaction events, and convert pixel coordinates to PDF points.
saving-pdf-files.mdSave edited PDFs, detect unsaved changes, cancel save operations, handle save events, and prompt before closing with pending edits.
magnifying.mdControl zoom behavior including zoom levels, fit modes, limits, zoom-to-rectangle, toolbar visibility, and zoom change events.
searching-text.mdSearch and highlight text, navigate results, retrieve match bounds and text details, support multi-line search, and control search UI and availability.
text-selection.mdDetect text selection completion, retrieve selected text and bounds, customize highlight color, enable or disable selection, and clear selections programmatically.
localization.mdLocalize the PDF Viewer UI using .resx resources and culture settings.
customize-contextmenu.mdCustomize context menus by adding, removing, hiding items, and handling menu click events.
commands.mdUse and bind built‑in WPF commands for navigation, zoom, search, annotations, undo/redo, printing, saving, and unloading documents.
toolbar-items.mdCustomize 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

先决条件

  1. Development Environment: Visual Studio 2022 or Visual Studio Insider 2026 (recommended for .NET 10).
  2. NET Framework 4.5+ or .NET Core/.NET 8+ with WPF support.
  3. Syncfusion WPF NuGet Packages:
    Syncfusion.PdfViewer.WPF
  1. 开发环境:Visual Studio 2022或Visual Studio Insider 2026(推荐用于.NET 10)。
  2. .NET Framework 4.5+或带WPF支持的.NET Core/.NET 8+。
  3. Syncfusion WPF NuGet包:
    Syncfusion.PdfViewer.WPF

Theme NuGet Packages

主题NuGet包

To apply a built-in theme to the WPF PdfViewerControl using
SfSkinManager
, install the NuGet package that matches the desired theme:
Theme NameRequired NuGet Package
FluentLight
Syncfusion.Themes.FluentLight.WPF
FluentDark
Syncfusion.Themes.FluentDark.WPF
MaterialLight
Syncfusion.Themes.MaterialLight.WPF
MaterialDark
Syncfusion.Themes.MaterialDark.WPF
MaterialLight3
Syncfusion.Themes.MaterialLight3.WPF
MaterialDark3
Syncfusion.Themes.MaterialDark3.WPF
Office2019Colorful
Syncfusion.Themes.Office2019Colorful.WPF
Office2019Black
Syncfusion.Themes.Office2019Black.WPF
Office2019White
Syncfusion.Themes.Office2019White.WPF
Office2019DarkGray
Syncfusion.Themes.Office2019DarkGray.WPF
Windows11Light
Syncfusion.Themes.Windows11Light.WPF
Windows11Dark
Syncfusion.Themes.Windows11Dark.WPF
Note: Install only the NuGet package corresponding to the theme the user wants to apply. Theme support requires
Syncfusion.SfSkinManager.WPF
, which is included as a dependency of the theme packages.
要使用
SfSkinManager
为WPF PdfViewerControl应用内置主题,请安装与所需主题匹配的NuGet包:
主题名称所需NuGet包
FluentLight
Syncfusion.Themes.FluentLight.WPF
FluentDark
Syncfusion.Themes.FluentDark.WPF
MaterialLight
Syncfusion.Themes.MaterialLight.WPF
MaterialDark
Syncfusion.Themes.MaterialDark.WPF
MaterialLight3
Syncfusion.Themes.MaterialLight3.WPF
MaterialDark3
Syncfusion.Themes.MaterialDark3.WPF
Office2019Colorful
Syncfusion.Themes.Office2019Colorful.WPF
Office2019Black
Syncfusion.Themes.Office2019Black.WPF
Office2019White
Syncfusion.Themes.Office2019White.WPF
Office2019DarkGray
Syncfusion.Themes.Office2019DarkGray.WPF
Windows11Light
Syncfusion.Themes.Windows11Light.WPF
Windows11Dark
Syncfusion.Themes.Windows11Dark.WPF
注意: 仅安装与用户想要应用的主题对应的NuGet包。主题支持需要
Syncfusion.SfSkinManager.WPF
,它是主题包的依赖项。

Documentations

文档