Skip to content

Get Start With macOS

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] 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:

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

    mkdir ComPDFKitDemo
    cd ComPDFKitDemo
    dotnet new console -o "ComPDFKit Demo"
  2. Copy the libComPDFKit.dylib file and the ComPDFKit.Desk.Core.dll file to the project folder.

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

    xml
    <ItemGroup>
        <Reference Include="ComPDFKit.NET.dll">
            <HintPath>ComPDFKit.Desk.Core.dll</HintPath>
        </Reference>
    </ItemGroup>
    
    <ItemGroup>
        <Content Include="ComPDFKitNative.dylib">
            <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.Desk.Core.dll</HintPath>
            </Reference>
        </ItemGroup>
    
        <ItemGroup>
            <Content Include="ComPDFKitNative.dylib">
                <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            </Content>
        </ItemGroup>
    
    </Project>

Integrate with NuGet

  1. Create a new project named ComPDFKit Demo in the console:

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

    bash
    dotnet add package ComPDFKit.NetCore

Create PDF Document

We have completed all the preparation steps. Now let us use ComPDFKit PDF SDK to create a PDF file with a blank page. Replace your Program.cs file with the following code. Note: You need to replace your license into 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:

shell
dotnet run

You will now find the new_file.pdf file in the program output directory, which is a PDF file with a blank page.