淮安企业网站眉山网站建设公司
web/
2025/9/26 10:37:26/
文章来源:
淮安企业网站,眉山网站建设公司,甘肃省住房与城乡建设厅网站首页,淮南 小学网站建设在当今世界#xff0c;Windows 应用程序对我们的工作至关重要。随着处理 PDF 文档的需求不断增加#xff0c;将 ComPDFKit PDF 查看和编辑功能集成到您的 Windows 应用程序或系统中#xff0c;可以极大地为您的用户带来美妙的体验。
在本博客中#xff0c;我们将首先探索集…在当今世界Windows 应用程序对我们的工作至关重要。随着处理 PDF 文档的需求不断增加将 ComPDFKit PDF 查看和编辑功能集成到您的 Windows 应用程序或系统中可以极大地为您的用户带来美妙的体验。
在本博客中我们将首先探索集成 ComPDFKit PDF SDK 的必要步骤并使用 ComPDFKit 构建 Windows PDF 阅读器。
ComPDFKit SDK for Windows 入门
ComPDFKit 是一个功能强大的 PDF SDK。只需数行C#代码即可轻松将 ComPDFKit PDF SDK 嵌入到您的 Windows 应用程序中。让我们用几分钟时间开始使用。
以下部分介绍了配置要求、安装包的结构以及如何通过C#语言使用 ComPDFKit PDF SDK制作 Windows PDF 阅读器。
要求
Windows 7、8、10 和 1132 位、64 位。Visual Studio 2017 或更高版本。.NET Framework 4.6.1 或更高版本。
Windows包结构
您可以联系我们获取我们的PDF SDK安装包。
SDK包中包含以下文件:
“Examples” - 包含Windows示例项目的文件夹。“lib” - 包含ComPDFKit动态库x86, x64的文件夹。“nuget” - 包含ComPDFKit.NetFramework nuget包的文件夹。“api_reference_windows.chm” - API参考文档。“developer_guide_windows.pdf” - 开发者文档。“legal.txt” - 法律和版权信息。“release_notes.txt” - Release信息。 使用C#构建Windows PDF查看器
第一步创建一个新项目 启动Visual Studio 2022, 单击创建新项目 选择“WPF APP (.NET Framework)”然后单击“下一步”。 配置您的项目设置您的项目名称并选择存储程序的位置。在本示例中项目名称称为“ComPDFKit Demo”。此示例项目使用 .NET Framework 4.6.1 作为编程框架。 点击“创建”按钮至此项目创建完成。
第二步添加ComPDFKit PDF SDK包 打开您的项目解决方案右击“引用”在右键菜单项中选择“管理Nuget程序包”这将打开您的项目的NuGet包管理器。 点击“浏览”设置程序包源为nuget.org搜索ComPDFKit.NetFramework您将搜索到“ComPDFKit.NetFramework”包。 选中包后在右侧包的详情面板中点击“安装”来下载包。 安装完成后您现在可以在“解决方案资源管理器”-“引用”中找到对应的包的引用。
第三步应用许可证密钥
您可以联系ComPDFKit团队获取试用许可证在使用任何ComPDFKit SDK功能之前需要进行的操作是设置许可证密钥。将以下方法“LicenseVerify()”添加到“MainWindow.xaml.cs”。
bool LicenseVerify()
{bool result CPDFSDKVerifier.LoadNativeLibrary();if (!result){return false;}string Key Input your key instead of this string;string Secret Input your secret instead of this string;CPDFSDKVerifier.LicenseErrorCode verifyResult CPDFSDKVerifier.LicenseVerify(Key, Secret);if (verifyResult ! CPDFSDKVerifier.LicenseErrorCode.LICENSE_ERR_SUCCESS){return false;}return true;
}
第四步显示PDF文档
现在我们已经完成了所有准备工作接下来我们将显示一份PDF文件。
将下面的代码添加到您的MainWindow.xaml,“MainWindow.xaml.cs”,从而显示PDF文件。请注意确保将“ComPDFKit_Demo”替换为您的项目名称。
您的MainWindow.xaml代码应该如下所示在此我将显示PDF文件的Grid命名为PDFGrid:
Window x:ClassComPDFKit_Demo.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:ComPDFKit_Demomc:IgnorabledTitleMainWindow Height450 Width800 UseLayoutRoundingTrueGridGrid.RowDefinitionsRowDefinition Height*/RowDefinition Height52//Grid.RowDefinitionsGrid NamePDFGrid Grid.Row0 /Button ContentOpen PDF Grid.Row1 HorizontalAlignmentLeft Margin10 ClickOpenPDF_Click//Grid
/Window您的“MainWindow.xaml.cs”文件应该如下所示。 请注意您需要输入许可证密钥代码中需要修改的部分已使用注释进行了标注。您只需将注释下方的字符串内容自行替换即可。
using ComPDFKit.NativeMethod;
using ComPDFKit.PDFDocument;
using ComPDFKitViewer.PdfViewer;
using Microsoft.Win32;
using System.Windows;namespace ComPDFKit_Demo
{public partial class MainWindow : Window{public MainWindow(){InitializeComponent();LicenseVerify();}bool LicenseVerify(){bool result CPDFSDKVerifier.LoadNativeLibrary();if (!result){return false;}// You should fill in your key and secret into the string below. string key Input your key instead of this string;string secret Input your secret instead of this string;LicenseErrorCode verifyResult CPDFSDKVerifier.LicenseVerify(key, secret);if (verifyResult ! LicenseErrorCode.LICENSE_ERR_SUCCESS){return false;}return true;}private void OpenPDF_Click(object sender, RoutedEventArgs e){// Get the path of a PDF file.var dlg new OpenFileDialog();dlg.Filter PDF Files (*.pdf)|*.pdf;if (dlg.ShowDialog() true){// Use the PDF file path to open the document in CPDFViewer.CPDFViewer pdfViewer new CPDFViewer();pdfViewer.InitDocument(dlg.FileName);if (pdfViewer.Document ! null pdfViewer.Document.ErrorType CPDFDocumentError.CPDFDocumentErrorSuccess){pdfViewer.Load();PDFGrid.Children.Add(pdfViewer);}}}}
}现在运行程序并单击“Open File”按钮选择您需要显示的PDF文件您将看到文件被显示在MainWindow上了。PDF查看器已经创建完成。
故障排除
如果在LicenseVerify()函数中出现System.IO.FileNotFoundException如下图
检查您的 WPF 项目并确保在创建项目时选择WPF APP(.NET Framework)而不是WPF Application。
其他问题 如果您在集成我们的 ComPDFKit PDF SDK for Windows 时遇到其他问题请随时联系ComPDFKit 团队。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/82144.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!