Skip to content
ComPDF
DemoSampleAPI ReferenceFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

Get Start With Linux

Run the Samples

Enter the sample folder and run the example from the command line:

  • Input/ Run. sh all to run all examples.
  • Input/ Run. sh [samplename] to run a specific example. For example/ Run. sh BatesTest.

If you receive an error message bash:/ Test. sh: Permission denied, you need to enter the following command:

shell
chmod+x run .sh

Integrate into Your Application

You can follow the manual or nuget integration described below for operation. This section will help you build your first ComPDFKit application. If you can open, save, and close PDFDoc, you can easily integrate the rest of the ComPDF PDF SDK.

Integrate Manually

  1. Create a new project named ComPDFKit Demo_ through the console:

    shell
    mkdir ComPDFKitDemo
    cd ComPDFKitDemo
    dotnet new console -o "ComPDFKit Demo"
  2. Copy the ComPDFKitNative.so file and ComPDFKit Copy the NET.dll file to the project folder.

  3. Add the following code to the. csproj file:

    xml
    <ItemGroup>
     <Reference Include="ComPDFKit.NET.dll">
       <HintPath>ComPDFKit.NET.dll</HintPath>
     </Reference>
    </ItemGroup>
    
    <ItemGroup>
        <Content Include="ComPDFKitNative.so">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
    </ItemGroup>

    Your final ComPDFKit Demo.csproj file should look like this:

    xml
    <Project Sdk="Microsoft.NET.Sdk">
    
        <PropertyGroup>
            <OutputType>Exe</OutputType>
            <TargetFramework>net6.0</TargetFramework>
        </PropertyGroup>
    
        <ItemGroup>
            <Reference Include="ComPDFKit.NET.dll">
                <HintPath>ComPDFKit.NET.dll</HintPath>
            </Reference>
        </ItemGroup>
    
        <ItemGroup>
            <Content Include="ComPDFKitNative.so">
                <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            </Content>
        </ItemGroup>
    
    </Project>

Integrate with NuGet

  1. Create a new project named ComPDFKit Demo_ through the console:

    shell
    mkdir ComPDFKitDemo
    cd ComPDFKitDemo
    dotnet new console -o "ComPDFKit Demo"
  2. Enter the project folder and install ComPDFKit Core NuGet package:

    bash
    dotnet add package ComPDFKit.NetCore

Create PDF Document

We have completed all the preparation steps. Now let's use the ComPDF PDF SDK to create a PDF file with a blank page, and replace your Program. cs file with the following code. Note that you need to specify the path to your license key XML file in the LicenseVerify() method.

csharp
using ComPDFKit.NativeMethod;
using ComPDFKit.PDFDocument;
using System.Reflection.Metadata;

namespace ComPDFKit_Demo
{
    public class Program
    {
        private static bool LicenseVerify()
        {
            if (!CPDFSDKVerifier.LoadNativeLibrary())
                return false;
            string xmlPath = "The path to your license key XML file";
            LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(xmlPath);
            return (verifyResult == LicenseErrorCode.E_LICENSE_SUCCESS);
        }
        
        public static void Main()
        { 
            LicenseVerify();
            CPDFDocument document = CPDFDocument.CreateDocument();
			int pageIndex = 0;
			int pageWidth = 595;
			int pageHeight = 842;
			document.InsertPage(pageIndex, pageWidth, pageHeight, "");
			document.WriteToFilePath("new_file.pdf");
            Console.WriteLine("Done. Results saved in new_file.pdf");
        }
    }
}

Now you can run the program from the command line:

bash
dotnet run

Now you will find the 'new_file. pdf' file in the program output directory, which is a PDF file with a blank page.