Skip to content

Get Start With Linux

Requirements

  • .NET Core SDK

    Note: ComPDFKit PDF SDK is multi-targeting. Target Frameworks : .NET Core 2.1+, .NET Standard 2.0, .NET 5, .NET 6, .NET 7, .NET 8。

  • ComPDFKit 's .NET Core PDF Library for Linux:

    Please contact us to obtain the ComPDFKit PDF SDK for NET Core.

  • ComPDFKit PDF SDK license

    Commercial license keys are required for use in production environments. If you do not have a valid license key, please contact us to obtain the license key.

    License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).

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 ComPDFKit 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 ComPDFKit 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 replace your license 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;
            LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify("Input your license here");
            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.