syncfusion-winforms-pdf-viewer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Syncfusion WinForms PdfViewer - UI Sample generator

Syncfusion WinForms PdfViewer - UI示例生成器

Generate C# Code for the User's Project (default)

为用户项目生成C#代码(默认功能)

Trigger keywords: "code", "snippet", "how to write", "Program.cs", "show me", "sample", "integrate", "example code", "generate code for", "create sample", "winforms pdfviewer".
Purpose: Generate clean, ready-to-use C# code snippets that directly insert into their WinForms application when working with Syncfusion WinForms PdfViewer control.
Workflow:
  1. Build the C# code using the snippets provided in the references/*.md files.
  2. Before generating the sample, ask the user whether the code should be:Integrated into an existing WinForms project, or Created as a new WinForms application.
  3. If the user chooses to create a new WinForms project, ask them which target framework they want to use: -.NET Framework (e.g., 4.6, 4.7, 4.8) — uses Syncfusion.PdfViewer.WinForms and targets the classic .NET Framework. -.NET / .NET Core (e.g., .NET 8, .NET 10) — uses Syncfusion.PdfViewer.WinForms with <TargetFramework>net8.0-windows</TargetFramework> (or the selected version).
  4. Based on the user's choice: Generate the .csproj file with the correct <TargetFramework> value. Add the required NuGet packages. Tailor any framework-specific code, such as namespace imports, form initialization, startup code (Program.cs), and PDF Viewer setup, accordingly.
  5. Add only the APIs required to satisfy the user's requested functionality. Do not include optional APIs, additional.

触发关键词: "code", "snippet", "how to write", "Program.cs", "show me", "sample", "integrate", "example code", "generate code for", "create sample", "winforms pdfviewer"
用途: 生成简洁、可直接使用的C#代码片段,可直接插入到使用Syncfusion WinForms PdfViewer控件的WinForms应用程序中。
工作流程:
  1. 使用references/*.md文件中提供的代码片段构建C#代码。
  2. 在生成示例前,询问用户代码应:集成到现有WinForms项目中,还是创建为新的WinForms应用程序。
  3. 如果用户选择创建新的WinForms项目,询问他们想要使用哪个目标框架: -.NET Framework(例如4.6、4.7、4.8)——使用Syncfusion.PdfViewer.WinForms,面向经典.NET Framework。 -.NET / .NET Core(例如.NET 8、.NET 10)——使用Syncfusion.PdfViewer.WinForms,并设置<TargetFramework>net8.0-windows</TargetFramework>(或所选版本)。
  4. 根据用户的选择: 生成带有正确<TargetFramework>值的.csproj文件。 添加所需的NuGet包。 调整任何框架特定代码,例如命名空间导入、窗体初始化、启动代码(Program.cs)和PDF Viewer设置。
  5. 仅添加满足用户请求功能所需的API。不要包含可选API或额外内容。

Code References

代码参考

All templates and snippets are in the
references/
folder. Each file is a focused snippet or template the agent will combine when generating sample:
FileContents
view-pdfviewer.mdNuGet setup, add PdfViewerControl/PdfDocumentView, load PDF
saving-pdf-files.mdSave PDF via toolbar, programmatic save using
LoadedDocument.Save()
,
BeginSave
and
EndSave
events
printing-pdf-files.mdPrint PDF via toolbar, silent printing using
Print()
, customize print size (
ActualSize
,
Fit
,
CustomScale
), print orientation (
Auto
,
Portrait
,
Landscape
), hide print status dialog,
BeginPrint
,
PrintProgress
, and
EndPrint
events
extract-text.mdExtract text from a single page using
ExtractText(pageIndex, out textLines)
, extract text from entire file using
PageCount
loop, extract text with line bounds via
TextLines
/
TextLine
, extract words with bounds via
WordCollection
/
TextWord
pdf-rendering-engines.mdSwitch rendering engine using
RenderingEngine
property (
PDFium
default,
SfPdf
alternative), set custom PDFium binary path via
ReferencePath
for restricted-access environments
searching-text.mdSearch next/previous text instance using
SearchNextText()
/
SearchPreviousText()
, find all instances with bounds using
FindText()
, count total matches, enable/disable highlight all instances via
TextSearchSettings.HighlightAllInstance
, customize highlight colors via
TextSearchSettings.CurrentInstanceColor
/
OtherInstanceColor
navigation.mdBookmark navigation, hyperlink handling, and page navigation (programmatic
GoToBookmark()
,
HyperlinkClicked
/
HyperlinkMouseOver
,
GoToPageAtIndex()
)
localization.mdLocalize tooltip and context menu static text, default
en-US
localization keys table, add culture-specific Resx files (e.g.,
Syncfusion.PdfViewer.Windows.fr.resx
), set custom assembly/namespace for localization using
LocalizationManager.SetResources()
themes.mdApply built-in themes using
ThemeName
property (
Office2016Colorful
,
Office2016Black
,
Office2016DarkGray
,
Office2016White
,
Office2019Colorful
,
HighContrastBlack
), load theme assemblies via
SkinManager.LoadAssembly()
, reset to default theme
interaction-modes.mdSwitch cursor modes using
CursorMode
property —
PdfViewerCursorMode.SelectTool
for text selection (default),
PdfViewerCursorMode.HandTool
for panning/scrolling
error-handling.mdSubscribe to
ErrorOccurred
event, handle
ErrorOccurredEventArgs.Message
to log errors or display messages to users
magnifying.mdZoom to a specific percentage using
ZoomTo()
, get current zoom via
ZoomPercentage
, switch zoom modes using
ZoomMode
property (
FitPage
,
FitWidth
)
view-pdf-stream.mdLoad a PDF from a
FileStream
using the
Load(stream)
overload
document-information.mdAccess filename and file path of the loaded PDF via
DocumentInformation.FileName
and
DocumentInformation.FilePath
; get page count via
PageCount
mouse-position.mdHandle
PageClicked
and
PageMouseMove
events to get page index and mouse position relative to the PDF page
host-wpf-pdfviewer-in-winforms.mdHost the WPF PdfViewer inside a WinForms app using
ElementHost
to access advanced features (annotations, form filling, signatures)
toolbar.mdShow/hide individual toolbar buttons (Open, Save, Zoom, Print, Pan) using
ToolbarSettings.<Button>.IsVisible

所有模板和代码片段都位于
references/
文件夹中。每个文件都是一个聚焦的代码片段或模板,代理将在生成示例时组合使用:
文件内容
view-pdfviewer.mdNuGet设置、添加PdfViewerControl/PdfDocumentView、加载PDF
saving-pdf-files.md通过工具栏保存PDF、使用
LoadedDocument.Save()
以编程方式保存、
BeginSave
EndSave
事件
printing-pdf-files.md通过工具栏打印PDF、使用
Print()
静默打印、自定义打印尺寸(
ActualSize
Fit
CustomScale
)、打印方向(
Auto
Portrait
Landscape
)、隐藏打印状态对话框、
BeginPrint
PrintProgress
EndPrint
事件
extract-text.md使用
ExtractText(pageIndex, out textLines)
提取单页文本、使用
PageCount
循环提取整个文件的文本、通过
TextLines
/
TextLine
提取带边界的文本、通过
WordCollection
/
TextWord
提取带边界的单词
pdf-rendering-engines.md使用
RenderingEngine
属性切换渲染引擎(默认
PDFium
,备选
SfPdf
)、在受限访问环境中通过
ReferencePath
设置自定义PDFium二进制文件路径
searching-text.md使用
SearchNextText()
/
SearchPreviousText()
搜索下一个/上一个文本实例、使用
FindText()
查找所有带边界的实例、统计匹配总数、通过
TextSearchSettings.HighlightAllInstance
启用/禁用高亮所有实例、通过
TextSearchSettings.CurrentInstanceColor
/
OtherInstanceColor
自定义高亮颜色
navigation.md书签导航、超链接处理和页面导航(编程方式
GoToBookmark()
HyperlinkClicked
/
HyperlinkMouseOver
GoToPageAtIndex()
localization.md本地化工具提示和上下文菜单静态文本、默认
en-US
本地化键表、添加特定文化的Resx文件(例如
Syncfusion.PdfViewer.Windows.fr.resx
)、使用
LocalizationManager.SetResources()
设置自定义本地化程序集/命名空间
themes.md使用
ThemeName
属性应用内置主题(
Office2016Colorful
Office2016Black
Office2016DarkGray
Office2016White
Office2019Colorful
HighContrastBlack
)、通过
SkinManager.LoadAssembly()
加载主题程序集、重置为默认主题
interaction-modes.md使用
CursorMode
属性切换光标模式——
PdfViewerCursorMode.SelectTool
用于文本选择(默认)、
PdfViewerCursorMode.HandTool
用于平移/滚动
error-handling.md订阅
ErrorOccurred
事件、处理
ErrorOccurredEventArgs.Message
以记录错误或向用户显示消息
magnifying.md使用
ZoomTo()
缩放至特定百分比、通过
ZoomPercentage
获取当前缩放比例、使用
ZoomMode
属性切换缩放模式(
FitPage
FitWidth
view-pdf-stream.md使用
Load(stream)
重载从
FileStream
加载PDF
document-information.md通过
DocumentInformation.FileName
DocumentInformation.FilePath
访问已加载PDF的文件名和文件路径;通过
PageCount
获取页数
mouse-position.md处理
PageClicked
PageMouseMove
事件以获取页面索引和相对于PDF页面的鼠标位置
host-wpf-pdfviewer-in-winforms.md使用
ElementHost
在WinForms应用中托管WPF PdfViewer,以访问高级功能(注释、表单填写、签名)
toolbar.md使用
ToolbarSettings.<Button>.IsVisible
显示/隐藏单个工具栏按钮(打开、保存、缩放、打印、平移)

Prerequisites

前提条件

  • Development Environment:Visual Studio 2022 or Visual Studio insider 2026(recommended for .NET 10).
  • .NET Framework 4.5+ or .NET Core/NET 8+
  • Syncfusion WinForms NuGet Package: Syncfusion.PdfViewer.Windows
  • 开发环境:Visual Studio 2022或Visual Studio Insider 2026(推荐用于.NET 10)。
  • .NET Framework 4.5+或.NET Core/.NET 8+
  • Syncfusion WinForms NuGet包:Syncfusion.PdfViewer.Windows

Documentations

相关文档