STBlazePDF.JSignPdf 1.0.1

dotnet add package STBlazePDF.JSignPdf --version 1.0.1                
NuGet\Install-Package STBlazePDF.JSignPdf -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="STBlazePDF.JSignPdf" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add STBlazePDF.JSignPdf --version 1.0.1                
#r "nuget: STBlazePDF.JSignPdf, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install STBlazePDF.JSignPdf as a Cake Addin
#addin nuget:?package=STBlazePDF.JSignPdf&version=1.0.1

// Install STBlazePDF.JSignPdf as a Cake Tool
#tool nuget:?package=STBlazePDF.JSignPdf&version=1.0.1                

Table of Contents

Overview

This library was created to assist STBlazePDF in signing PDF documents. It is a small library that includes the JSignPDF Java assets. This library exposes the available arguments for JSignPDF and will call the Java Library with the applicable arguments. There are a few additional methods included in this library, but it is mostly for cleanup and allowing multiple signatures to be processed sequentially.

Requirements

The Java Runtime Environment (JRE) 8.0 or Higher must be installed on the computer. As such, this library will not work if it is included in a WASM project.

Gotcha's

When adding multiple signatures to a PDF document and the document is either password encrypted or encrypted via a certificate, only the last signature will be visible. The only way to have multiple signatures on a page is to not encrypt the PDF.

Suggested Deployments

This library will work when it is included in a Blazor Server Side project or when it's a standalone ASP.Net project.

Quick Start

To start using this library, it needs to be registered on the application startup


builder.Services.AddBlazePDFSigning(() =>
{
    return new Configuration()
    {
        TemporaryDirectory = @"c:\temp\signed_pdf",
        JavaExePath = @"C:\Program Files\Java\jre1.8.0_361\bin\java.exe",
        RemoveTemporaryFilesOnDispose = true
    };
});

Then, using dependency injection you can retrieve an instance of the service and call the signing service with the applicable arguments.

Custom Sign Document Services

public class SignDocumentService : ISignDocumentService
{
    private readonly IJSignPdfRunner _jSignPdfRunner;
    
    public SignDocumentService(IJSignPdfRunner jSignPdfRunner)
    {
        _jSignPdfRunner = jSignPdfRunner;
    }
    
    public Task<string> SignDocument(SignDocumentFile signDocumentFile)
    {
        var signingArguments = new JSignPDFArgs()
        {
            Append = true,
            VisibleSignature = true,
            OwnerPassword = signDocumentFile.OwnerPassword,
            QuietMode = true,
            UserPassword = signDocumentFile.DocumentPassword,
            RenderMode = RenderMode.GRAPHIC_AND_DESCRIPTION,
            KeyStoreType = "WINDOWS-MY",
            BackgroundScale = 0,
            EncryptionMode = EncryptionMode.NONE
        };

        var signRequest = new STBlazePDF.JSignPdf.Models.SignRequest()
        {
            OwnerPassword = signDocumentFile.OwnerPassword,
            UserPassword = signDocumentFile.DocumentPassword,
            DocumentDataBase64 = signDocumentFile.DocumentDataBase64,
            Signatures = signDocumentFile.Signatures.Select(x => new STBlazePDF.JSignPdf.Models.SignatureRequest()
                {
                    Position = x.Position,
                    PageNumber = x.PageNumber,
                    Location = "Nashville, TN",
                    Reason = "Signature Test",
                    Contact = "615 999 9999",
                    SignatureBase64 = x.SignatureBase64
                }
            ).ToList()
        };
        
        var result = _jSignPdfRunner.RunSignPDFFromBase64(signingArguments, 
            signRequest);

        if (result.Success == false)
            throw result.Exception!;
        
        return Task.FromResult<string>(result.ResponseContent ?? ""); 
    }
    
}

Sign Document Signature Model


public class SignDocumentFileSignature
{

    #region Properties

    /// <summary>
    /// Gets or sets the page number of the signature
    /// </summary>
    public int PageNumber { get; set; }

    /// <summary>
    /// Gets or sets the base 64 image data
    /// </summary>
    public string SignatureBase64 { get; set; } = string.Empty;

    /// <summary>
    /// Gets or sets the position of the signature image
    /// </summary>
    public Rectangle Position { get; set; }
    #endregion

}

Sign Document Model

public class SignDocumentFile
{

    #region Properties

    /// <summary>
    /// Gets or sets a list of signatures to apply to the document
    /// </summary>
    public List<SignDocumentFileSignature> Signatures { get; set; } = new();

    /// <summary>
    /// Gets or sets the owner password of the document
    /// </summary>
    /// <remarks>
    /// This is not yet used but may be in future
    /// </remarks>
    public string? OwnerPassword { get; set; }

    /// <summary>
    /// Gets or sets the user password of the document
    /// </summary>
    /// <remarks>
    /// This is not yet used but may be in future
    /// </remarks>
    public string? UserPassword { get; set; }

    /// <summary>
    /// Gets or sets the original password the document was opened with
    /// </summary>
    public string? DocumentPassword { get; set; }

    /// <summary>
    /// Gets or sets the base 64 encoded document data
    /// </summary>
    public string DocumentDataBase64 { get; set; } = string.Empty;

    #endregion


}

Help

Since this library is only a wrapper around the JSignPDF library, it is suggested to read that documentation if issues arise.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

v0.0.1 Initial Release
v0.0.2 Added Custom Target to copy jvm assets
v1.0.0 Release
v1.0.1 Added Nuget Readme Configuration