{"id":19756881,"url":"https://github.com/compdfkit/compdfkit-pdf-sdk-windows","last_synced_at":"2025-04-30T12:31:08.960Z","repository":{"id":45519823,"uuid":"511052566","full_name":"ComPDFKit/compdfkit-pdf-sdk-windows","owner":"ComPDFKit","description":"Show how to integrate PDF library into applications on Windows.","archived":false,"fork":false,"pushed_at":"2024-09-12T05:54:50.000Z","size":291815,"stargazers_count":26,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-09-13T14:18:38.841Z","etag":null,"topics":["compdfkit","csharp","dotnet","pdf","pdf-document","pdf-editor","pdf-viewer","windows"],"latest_commit_sha":null,"homepage":"https://www.compdf.com/Windows","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ComPDFKit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-06T08:27:07.000Z","updated_at":"2024-09-12T05:55:00.000Z","dependencies_parsed_at":"2023-11-24T03:23:09.094Z","dependency_job_id":"9b900160-8c36-4a71-9c2a-4a7bc2a6a8df","html_url":"https://github.com/ComPDFKit/compdfkit-pdf-sdk-windows","commit_stats":null,"previous_names":["compdfkit/compdfkit-pdf-sdk-windows"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-windows","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-windows/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-windows/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-windows/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ComPDFKit","download_url":"https://codeload.github.com/ComPDFKit/compdfkit-pdf-sdk-windows/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224207933,"owners_count":17273679,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compdfkit","csharp","dotnet","pdf","pdf-document","pdf-editor","pdf-viewer","windows"],"created_at":"2024-11-12T03:17:18.499Z","updated_at":"2024-11-12T03:17:20.927Z","avatar_url":"https://github.com/ComPDFKit.png","language":"C#","readme":"# Introduction\n[ComPDFKit PDF SDK](https://www.compdf.com) is a robust PDF library, which offers comprehensive functions for quickly viewing, annotating, editing, and signing PDFs. It is feature-rich and battle-tested, making PDF files process and manipulation easier and faster.\n\n[ComPDFKit for Windows](https://www.compdf.com/windows) allows you to quickly add PDF functions to any Windows application, elevating your Window programs to ensure efficient development. It is available at [nuget](https://www.nuget.org/packages/ComPDFKit.NetFramework) and [github.com](https://github.com/ComPDFKit/compdfkit-pdf-sdk-windows).\n\n# Related\n\n- [ComPDFKit API Library for .Net](https://github.com/ComPDFKit/compdfkit-api-.net)\n- Download [ComPDFKit PDF SDK for .NET](https://www.nuget.org/packages/ComPDFKit.NetFramework) in Nuget\n- [How to Build a Windows PDF Viewer or Editor](https://www.compdf.com/blog/build-a-windows-pdf-viewer-or-editor)\n- [Brief Introduction to ComPDFKit for Windows](https://www.compdf.com/blog/compdfkit-for-windows)\n\n# Get Started\n\nIt is easy to embed ComPDFKit PDF SDK in your Windows application with a few lines of C# code. The following sections introduce the requirements, the structure of the installation package, and how to make a Windows PDF Reader in C# with ComPDFKit PDF SDK. Take just a few minutes and get started.\n\n\n## Requirements\n\n- Windows 7, 8, 10, and 11 (32-bit and 64-bit).\n- Visual Studio 2017 or higher (Make sure the **.NET Desktop Development** is installed).\n- .NET Framework 4.5 or higher.\n\n## How to Run a Demo\n[ComPDFKit PDF SDK for Windows](https://www.compdf.com/guides/pdf-sdk/windows/overview) provides multiple demos in C# for developers to learn how to call the SDK on Windows. You can find them in the ***\"Examples\"*** folder.\n\nIn this guide, we take ***\"PDFViewer\"*** as an example to show how to run it in Visual Studio 2022.\n\n1. Copy your ***\"license_key_windows.xml\"*** to the ***\"Examples\"*** folder (The file is the license to make your project run).\n\n2. Find ***\"Examples.sln\"*** in the ***\"Examples\"*** folder and open it in Visual Studio 2022.\n\n   \u003cimg src=\"images-windows/imagev2.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n3. Select ***\"PDFViewer\"*** and right-click to set it as a startup project.\n\n   \u003cimg src=\"images-windows/image-2v2.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n4. Run the project and then you can open the multifunctional ***\"PDFViewer\"*** demo.\n\n   \u003cimg src=\"images-windows/image-1.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n**Note:** *This is a demo project, presenting completed [ComPDFKit PDF SDK](https://www.compdf.com/pdf-sdk) functions. The functions might be different based on the license you have purchased. Please check that the functions you choose work fine in this demo project.*\n\n\n\n## How to Make a Windows Program in C#\n\n### Create a New Project\n\n1. Open Visual Studio 2022, and click **Create a new project**.\n\n   \u003cimg src=\"images-windows/vs2022_1.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n2. Choose **WPF App (.NET Framework)** and click **Next**.\n\n   \u003cimg src=\"images-windows/vs2022_2.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n3. Configure your project: Set your project name and choose the location to store your program. The project name is called \"ComPDFKit Demo\" in this example. This sample project uses .NET Framework 4.6.1 as the programming framework.\n\n   \u003cimg src=\"images-windows/vs2022_3.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n4. Click the **Create** button. Then, the new project will be created.\n\n\n\n### Add ComPDFKit to Your Project\n\nThere are two ways to add ComPDFKit to your Project: [Nuget Repository](https://www.nuget.org/packages/ComPDFKit.NetFramework) and Local Package, you can choose one or the other according to your needs.\n\n**Nuget Repository**\n\n1. Open your project's solution, and in the Solution Explorer, right-click on **References** and click on the menu item **Manage NuGet Packages**. This will open the NuGet Package Manager for your solution.\n\n   \u003cimg src=\"images-windows/2.4.2.1.png\" alt=\"2.4\" width=\"35%\" height=\"35%\"/\u003e\n\n2. Go to [ComPDFKit.NetFramework](https://www.nuget.org/packages/ComPDFKit.NetFramework) in Nuget, and click on the **Install** button to install the package.\n\n   \u003cimg src=\"images-windows/2.4.2.3v2.png\" alt=\"2.4\" width=\"65%\" height=\"65%\"/\u003e\n\n3. Once that is complete, you'll see a reference to the package in the Solution Explorer under **References**.\n\n   \u003cimg src=\"images-windows/2.4.2.4.png\" alt=\"2.4\" width=\"35%\" height=\"35%\"/\u003e\n\n\n\n**Local Package**\n\nRather than targeting a package held at Nuget, you may set up a configuration to point to a local package. This can be useful for some situations, for example, your build machines don't have access to the internet.\n\n1. You can find ***\"ComPDFKit.NetFramework....nupkg\"*** file in the [SDK Package](https://github.com/ComPDFKit/compdfkit-pdf-sdk-windows/tree/Tutorials-Blog/ComPDFKit%201.11.0%20for%20Windows/nuget)\n\n2. Create or edit a ***\"nuget.config\"*** file in the same directory as your solution file (e.g. ***\"ComPDFKit Demo.sln\"***).\n\n\u003cimg src=\"images-windows/2.4.2.5.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n- The contents of the file should contain an XML element, _packageSources_ - which describes where to find NuGet packages - as a child of a root node named _configuration_. If the file already exists, add the extra _packageSources_ entry shown below. If the file is blank, copy and paste the entirety of the following contents:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cconfiguration\u003e\n    \u003cpackageSources\u003e\n        \u003cadd key=\"ComPDFKitSource\" value=\"path\\to\\directoryContainingNupkg\" /\u003e\n    \u003c/packageSources\u003e\n\u003c/configuration\u003e\n```\n\n- Edit the _value_ of the contents to correctly refer to the location of the directory containing the ***\"ComPDFKit.NetFramework....nupkg\"*** package - for example, C:\\Users\\me\\nugetPackages\\. Now save the file, and close and reopen your solution for Visual Studio to force a read of the NuGet configuration.\n\n3. Open your project's solution, and in the Solution Explorer, right-click on **References** and click on the menu item **Manage NuGet Packages…**. This will open the NuGet Package Manager for your solution.\n\n   \u003cimg src=\"images-windows/2.4.2.6.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n4. On the right-hand side of the manager in the Package source dropdown window, choose the entry _ComPDFKitSource_ (or whatever you decided to name it). You should then see the entry for ***\"ComPDFKit.NetFramework\"***.\n\n   \u003cimg src=\"images-windows/2.4.2.7.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n5. On the right side, in the panel describing the package, click on the **Install** button to install the package.\n\n   \u003cimg src=\"images-windows/2.4.2.8v2.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n6. Once that's complete, you'll see a reference to the package in the Solution Explorer under **References**.\n\n   \u003cimg src=\"images-windows/2.4.2.9.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n### Apply the License Key\n\nYou can [contact the ComPDFKit team](https://www.compdf.com/contact-us) to obtain a trial license. Before using any classes from the ComPDFKit PDF SDK, you need to choose the corresponding scheme from the following two options based on the license type and apply the license to your application.\n\n**Online Authentication**\n\nYou can perform online authentication using the following approach:\n\n```c#\npublic static bool LicenseVerify()\n{\n\tif (!CPDFSDKVerifier.LoadNativeLibrary())\n\t{ \n\t\treturn false;\n\t}\n\tLicenseErrorCode status = CPDFSDKVerifier.OnlineLicenseVerify(\"Input your license here.\");\n\treturn status == LicenseErrorCode.E_LICENSE_SUCCESS;\n}\n```\n\nAdditionally, if you need to confirm the communication status with the server during online authentication, you can implement the `CPDFSDKVerifier.LicenseRefreshed` callback:\n\n```C#\nCPDFSDKVerifier.LicenseRefreshed += CPDFSDKVerifier_LicenseRefreshed;\n\nprivate void CPDFSDKVerifier_LicenseRefreshed(object sender, ResponseModel e)\n{\n    if(e != null)\n    {\n        string message = string.Format(\"{0} {1}\", e.Code, e.Message);\n        Trace.WriteLine(message);\n    }\n    else\n    {\n        Trace.WriteLine(\"Network not connected.\"); \n    } \n}\n\n```\n\n**Offline Authentication** \n\nThe following is the `LicenseVerify()` method for implementing offline authentication:\n\n```c#\nbool LicenseVerify()\n{\n    if (!CPDFSDKVerifier.LoadNativeLibrary())\n        return false;\n\n    LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(\"Input your license here.\", false);\n    return (verifyResult == LicenseErrorCode.E_LICENSE_SUCCESS);\n}\n```\n\n### Display a PDF Document\n\nWe have finished all prepare steps. Let's display a PDF file.\n\n1. Add the following code to ***\"MainWindow.xaml\"*** and ***\"MainWindow.xaml.cs\"*** to display a PDF document. Please make sure to replace \"ComPDFKit_Demo\" with the name of your project. Now, all you need to do is to create a `CPDFViewer` object, and then display the `CPDFViewer` object in the Grid (component) named \"PDFGrid\" using the `OpenPDF_Click` method.\n\n2. Now your ***\"MainWindow.xaml\"*** should look like the following code.\n\n```c#\n\u003cWindow x:Class=\"ComPDFKit_Demo.MainWindow\"\n        xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n        xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n        xmlns:d=\"http://schemas.microsoft.com/expression/blend/2008\"\n        xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"\n        xmlns:local=\"clr-namespace:ComPDFKit_Demo\"\n        xmlns:compdfkitviewer=\"clr-namespace:ComPDFKitViewer;assembly=ComPDFKit.Viewer\"\n        mc:Ignorable=\"d\"\n        Focusable=\"True\"\n        Title=\"MainWindow\" Height=\"600\" Width=\"800\" UseLayoutRounding=\"True\"\u003e\n    \u003cGrid\u003e\n        \u003cGrid.RowDefinitions\u003e\n            \u003cRowDefinition Height=\"*\"/\u003e\n            \u003cRowDefinition Height=\"52\"/\u003e\n        \u003c/Grid.RowDefinitions\u003e\n        \u003cGrid Name=\"PDFGrid\" Grid.Row=\"0\"\u003e\n            \u003cScrollViewer Focusable=\"False\" CanContentScroll=\"True\" HorizontalScrollBarVisibility=\"Auto\" VerticalScrollBarVisibility=\"Auto\"\u003e\n                \u003ccompdfkitviewer:CPDFViewer x:Name=\"PDFViewer\"/\u003e\n            \u003c/ScrollViewer\u003e\n        \u003c/Grid\u003e\n        \u003cButton Content=\"Open PDF\" Grid.Row=\"1\" HorizontalAlignment=\"Left\" Margin=\"10\" Click=\"OpenPDF_Click\"/\u003e\n    \u003c/Grid\u003e\n\u003c/Window\u003e\n```\n\n3. Now your ***“MainWindow.xaml.cs”*** should look like the following code. Please note: You need to enter your license key. All the places that need to be modified in the code have been marked with comments in the code below. You just need to replace the string content below the comments by yourself.\n\n```c#\nusing ComPDFKit.NativeMethod;\nusing ComPDFKit.PDFDocument;\nusing Microsoft.Win32;\nusing System.Windows;\n\nnamespace ComPDFKit_Demo\n{\n    public partial class MainWindow : Window\n    {\n        public MainWindow()\n        {\n            InitializeComponent();\n            LicenseVerify();\n        }\n\n        bool LicenseVerify()\n        {\n            if (!CPDFSDKVerifier.LoadNativeLibrary())\n                return false;\n\n            // Input your license.\n            LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(\"Input your license here.\");\n            return (verifyResult == LicenseErrorCode.E_LICENSE_SUCCESS);\n        }\n\n        private void OpenPDF_Click(object sender, RoutedEventArgs e)\n        {\n            // Get the path of a PDF file.\n            var dlg = new OpenFileDialog();\n            dlg.Filter = \"PDF Files (*.pdf)|*.pdf\";\n            if (dlg.ShowDialog() == true)\n            {\n                // Use the PDF file path to open the document in CPDFViewer.\n                CPDFDocument doc = CPDFDocument.InitWithFilePath(dlg.FileName);\n                if (doc != null \u0026\u0026 doc.ErrorType == CPDFDocumentError.CPDFDocumentErrorSuccess)\n                    PDFViewer.InitDoc(doc);\n            }\n        }\n    }\n}\n```\n\n4. Now run the project and you will see the PDF file that you want to display.  The PDF Viewer has been created successfully.\n\n\u003cimg src=\"images-windows/2.4.4.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n\n\n### Troubleshooting\n\n1. License Verification Failed\n- If \"System.IO.FileNotFoundException\" occurred in the `LicenseVerify()` function like this:\n\n\u003cimg src=\"images-windows/vs2022_4.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n- Check your WPF project and ensure that you chose **WPF App(.NET Framework)** instead of **WPF Application** when creating the project.\n\n\u003cimg src=\"images-windows/vs2022_5.png\" alt=\"2.4\" width=\"50%\" height=\"50%\"/\u003e\n\n2. Other Problems\n\n   If you meet some other problems when integrating our ComPDFKit PDF SDK for Windows, feel free to contact [our support team](https://www.compdf.com/support).\n\n\n# Samples\n\nThe Samples use preset parameters and documentation to call the [API of ComPDFKit](https://api.compdf.com/) for each function without UI interaction or parameter settings. They not only demonstrate the best practices for each function but also provide detailed introductions. The impact of each function on PDF documents can be observed in the output directory. With the help of the Samples, you can quickly learn how to use the functions you need and apply them to your projects.\n\nYou can get our [code examples for Windows](https://www.compdf.com/guides/pdf-sdk/windows/examples) on our website. To learn more about the ComPDFKit API, please visit our [API Reference](https://developers.compdf.com/guides/pdf-sdk/windows/api-reference/index).\n\n# Support\n\n[ComPDFKit]((https://www.compdf.com)) has a professional R\u0026D team that produces comprehensive technical documentation and guides to help developers. Also, you can get an immediate response when reporting your problems to our support team.\n\n- For detailed information, please visit our [Guides](https://www.compdf.com/guides/pdf-sdk/windows/overview) page.\n\n- Stay updated with the latest improvements through our [Changelog](https://www.compdf.com/pdf-sdk/changelog-windows).\n\n- For technical assistance, please reach out to our [Technical Support](https://www.compdf.com/support).\n\n- To get more details and an accurate quote, please contact our [Sales Team](https://compdf.com/contact-us).\n\n\n\n\n# License\n\nComPDFKit PDF SDK supports flexible licensing options, please contact [our sales team](mailto:support@compdf.com) to know more. Each license is only valid for one application ID in development mode.  However, any documents, sample code, or source code distribution from the released package of ComPDFKit PDF SDK to any third party is prohibited.\n\n\n\n# Note\n\nWe are glad to announce that you can register a ComPDFKit API account for a [free trial](https://api.compdf.com/api/pricing) to process 1000 documents per month for free.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompdfkit%2Fcompdfkit-pdf-sdk-windows","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcompdfkit%2Fcompdfkit-pdf-sdk-windows","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompdfkit%2Fcompdfkit-pdf-sdk-windows/lists"}