Introducing PSPDFKit Libraries

At PSPDFKit, we’ve always been focused on providing our customers with a professional and advanced UI and user experience — from our mobile iOS and Android frameworks, to our ever-growing web solutions. In addition, we take great care in providing an amazing developer experience for our customers, and now we’re making another big push in that area.

Today we’re happy to launch PSPDFKit Libraries, a new product based on the same battle-tested code that runs all our existing products, and one that carries over our experience in API design to bring familiarity to users of our other SDKs.

Together with our customers, we’ve identified a few key use cases (which we’ll outline in this post) for the first release and are eager to expand the scope of PSPDFKit Libraries even further. Reach out to us and let us know how we can expand PSPDFKit Libraries to cover your use case!

Compatibility

PSPDFKit Libraries offers native bindings for both Java/Kotlin and .NET.

Java and Kotlin

To ensure compatibility, we will be supporting all current Java versions (8, 11, 12, 13). Additionally, upon release, the PSPDFKit Java Library will operate on Windows (32/64 bit), macOS (64 bit), and Linux (64 bit). PSPDFKit Libraries also supports Kotlin, thanks to the interoperability of the language.

.NET

To ensure compatibility with a variety of .NET implementations, the PSPDFKit .NET Library is built using .NET Standard 2.0, which supports:

Again, the supported platforms are Windows (32/64 bit), macOS (64 bit), and Linux (64 bit).

Features

PSPDFKit Libraries is designed to drop straight into your project, and simple API calls are accessible in your native language. You can click on the following features to find out more.

Use Cases

As part of our initial design, we identified a few key use cases for PSPDFKit Libraries, as requested by our partners. These include batch processing, optimized server-client communication, and document manipulation. Below are some examples to give you an idea of how you can get started with PSPDFKit Libraries.

Adding a Cover Page

When collating document information, whether for business or individual purposes, you often want to merge documents together and file them as a single document with an informational front page or a company-branded cover.

With PSPDFKit Libraries, document manipulation is simple. The Document Editor API (Java/.NET) makes it possible to merge multiple documents into one, as well as add, move, remove, and rotate single or multiple pages to suit your needs:

Copy
1
2
3
4
5
6
7
8
9
10
11
12
// Open a document to append a cover page to and create a Document Editor from it.
File file = new File("Assets/default.pdf");
PdfDocument document = new PdfDocument(new FileDataProvider(file));
DocumentEditor documentEditor = document.createDocumentEditor();

// Prepend the document with the cover page.
File coverPage = new File("Assets/coverPage.pdf");
documentEditor.importDocument(0, DocumentEditor.IndexPosition.BeforeIndex, new FileDataProvider(coverPage));

// Save the document to an output file.
File outputFile = File.createTempFile("documentWithCoverPage", ".pdf");
documentEditor.saveDocument(new FileDataProvider(outputFile));
Copy
1
2
3
4
5
6
7
8
9
10
11
12
// Open a document to append a cover page to and create a Document Editor from it.
var document = new Document(new FileDataProvider("Assets/default.pdf"));
var documentEditor = document.CreateDocumentEditor();

// Prepend the document with the cover page.
documentEditor.ImportDocument(0, DocumentEditor.IndexPosition.BeforeIndex,
    new FileDataProvider("Assets/coverPage.pdf"));

// Save the document to an output file.
const string filename = "documentWithCoverPage.pdf";
File.Create(filename).Close(); // Create the file and close it to ensure it is not used by this process.
documentEditor.SaveDocument(new FileDataProvider(filename));

Thumbnail Rendering

If you’re providing documents on a website or an internal infrastructure, it’s often helpful to show a preview before your user opens a document.

With PSPDFKit Libraries, you can rely upon our high-fidelity rendering engine to show any page (render pages in Java/.NET) of the document at any desired size:

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
// Open the document you want to render.
File file = new File("Assets/default.pdf");
PdfDocument document = new PdfDocument(new FileDataProvider(file));

for (int i = 0; i < document.getPageCount(); i++) {
    // Render a thumbnail for each page.
    PdfPage page = document.getPage(i);
    BufferedImage bufferedImage = page.renderPage(120, 170);

    // Write the render out to a PNG.
    File outputFile = File.createTempFile("page" + i, ".pdf");
    ImageIO.write(bufferedImage, "png", outputFile);
}
Copy
1
2
3
4
5
6
7
8
9
10
11
// Open the document you want to render.
var document = new Document(new FileDataProvider("Assets/default.pdf"));

for (uint i = 0; i < document.GetPageCount(); i++) {
    // Render a thumbnail for each page.
    var page = document.GetPage(i);
    var bitmap = page.RenderPage(120, 170);

    // Write the render out to a PNG.
    bitmap.Save("page" + i + ".pdf", ImageFormat.Png);
}

Applying Annotations

When working with large PDFs, high network loads passing documents back and forth can become problematic. To mitigate this, PSPDFKit Libraries offers Instant Document JSON (Java/.NET) or XFDF (Java/.NET), thereby allowing for a subset of information to be exchanged.

With Instant Document JSON (Java/.NET), only the changes to the document are exported, which means you don’t have to transmit the entire PDF. The exported data can then be sent to another location to replicate the document with the changes.

An example use case of Instant Document JSON in action is a document review system where the documents may be hundreds of megabytes in size. The client reviewer can make annotations on the document remotely and then send only the Instant Document JSON changes to a server to be applied, thus minimizing large amounts of network traffic:

Copy
1
2
3
4
5
6
7
// Open the document to apply the Instant Document JSON to.
File documentFile = new File("Assets/default.pdf");
PdfDocument document = new PdfDocument(new FileDataProvider(documentFile));

// Open the Instant document JSON and apply to the document.
File instantFile = new File("Assets/instant.json");
document.importDocumentJson(new FileDataProvider(instantFile));
Copy
1
2
3
4
5
// Open the document to apply the Instant Document JSON to.
var document = new Document(new FileDataProvider("Assets/default.pdf"));

// Open the Instant document JSON and apply to the document.
document.ImportDocumentJson(new FileDataProvider("Assets/instant.json"));

Applying Redactions to Multiple Documents

When sharing documents with third parties, it’s critical to ensure no sensitive personal, business, or legal information is included. This means you need a reliable way of completely redacting text, images, and annotations from a page, leaving no trace of them in the final PDF.

With PSPDFKit Libraries, it’s possible to iterate over documents — for example, a customer-filled form that includes private information like a social security number — and apply a redaction annotation to the same location on each document before saving and sending them all out to an external source. This even works with scanned documents, where the document is an image included in the PDF!

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Define the redaction annotation to use.
JSONObject redactionAnnotation = new JSONObject();
redactionAnnotation.put("bbox", new float[]{337.77972412109375f, 121.1519775390625f, 166.67999267578125f, 45.39599609375f});
redactionAnnotation.put("creatorName", "User");
redactionAnnotation.put("fillColor", "#000000");
redactionAnnotation.put("opacity", 1);
redactionAnnotation.put("pageIndex", 0);
redactionAnnotation.put("type", "pspdfkit/markup/redaction");
redactionAnnotation.put("v", 1);

// Open each file and apply the same redaction annotation. Upon saving, apply the redactions.
for (File fileToRedact : filesToRedact) {
    PdfDocument document = new PdfDocument(new FileDataProvider(fileToRedact));
    document.getAnnotationProvider().addAnnotationJson(redactionAnnotation);
    document.save(new DocumentSaveOptions.Builder().applyRedactionAnnotations(true).build());
}
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Define the redaction annotation to use.
var redactionAnnotation = new JObject
{
    {
        "bbox",
        new JArray {337.77972412109375f, 121.1519775390625f, 166.67999267578125f, 45.39599609375f}
    },
    {"creatorName", "User"},
    {"fillColor", "#000000"},
    {"opacity", 1},
    {"pageIndex", 0},
    {"type", "pspdfkit/markup/redaction"},
    {"v", 1}
};

// Open each file and apply the same redaction annotation. Upon saving, apply the redactions.
foreach (var fileToRedact in filesToRedact)
{
    var document = new Document(new FileDataProvider(fileToRedact));
    document.GetAnnotationProvider().AddAnnotationJson(redactionAnnotation);
    document.Save(new DocumentSaveOptions
    {
        applyRedactionAnnotations = true
    });
}

It’s also possible to design how the redactions would look on one of our powerful UI frameworks (iOS/Android), export this redaction information, and apply the redactions on a server with PSPDFKit Libraries. To create the redaction information, Instant Document JSON (Java/.NET) is used. It can then be imported into the document on the server, and the redactions can be applied:

Copy
1
2
3
4
5
6
7
8
9
10
// Open the document.
File file = new File("Assets/default.pdf");
PdfDocument document = new PdfDocument(new FileDataProvider(file));

// Open and import the redaction annotations from the Instant Document JSON.
File redactionJsonFile = new File("Assets/redaction.json");
document.importDocumentJson(new FileDataProvider(redactionJsonFile));

// Save the document with the redaction annotations applied.
document.save(new DocumentSaveOptions.Builder().applyRedactionAnnotations(true).build());
Copy
1
2
3
4
5
6
7
8
9
10
11
// Open the document.
var document = new Document(new FileDataProvider(tempPath));

// Open and import the redaction annotations from the Instant Document JSON.
document.ImportDocumentJson(new FileDataProvider("Assets/redaction.json"));

// Save the document with the redaction annotations applied.
document.Save(new DocumentSaveOptions
{
    applyRedactionAnnotations = true,
});

Flattening Annotations

If a client signs your document with an ink annotation and you’d like to redistribute this document without the possibility of anyone else editing the signature, you can flatten annotations. By doing this, the ink annotation will be embedded in the PDF page and will no longer be editable.

It’s easy to flatten a document with PSPDFKit Libraries. Just add the flatten flag to the save API (Java/.NET) and you’re done:

Copy
1
2
3
4
5
6
// Open the document.
File file = new File("default.pdf");
PdfDocument document = new PdfDocument(new FileDataProvider(file));

// Save and flatten the annotations in the document.
document.save(new DocumentSaveOptions.Builder().flattenAnnotations(true).build());
Copy
1
2
3
4
5
6
7
8
// Open the document.
var document = new Document(new FileDataProvider("default.pdf"));

// Save and flatten the annotations in the document.
document.Save(new DocumentSaveOptions
{
    flattenAnnotations = true
});

Conclusion

We’re excited for this new chapter for PSPDFKit and to expand our reach to a wider audience.

Now, over to you.

  • What projects would you like to use PSPDFKit Libraries for?
  • What languages would you like to see supported?
  • What features do you want to see next?

Get in touch and tell us about your use case, and we’ll see how the product can grow to suit your needs.

PSPDFKit Library for Java/.NET

Download the free 60-day trial and integrate it with your web app today.

The data you submit is treated confidentially and will never be disclosed to third parties.
We may occasionally send you product news and important announcements.