Available Now: Explore our latest release with enhanced accessibility and powerful IDP features

Creating a Ruby Wrapper for the Apryse SDK

By Roger Dunham | 2023 Nov 09

Sanity Image
Read time

4 min

Summary

Copied to clipboard

In this article we will look at how to:

  • Generate the wrappers for Ruby (which can then be used as a template for other languages)
  • Add a license key
  • Get ready to run the samples that are shipped with the SDK.

This will be done using Ubuntu 22.02 running within WSL (Windows Subsystem for Linux) on Windows 11 and will use the 64-bit version of the Apryse SDK.

Introduction

Copied to clipboard

The Apryse SDK is a powerful document processing library that supports viewing, editing and annotating PDFs and other documents, as well as being able to display audio and video, supporting redaction, digital signatures, and a multitude of other functionality.

Prebuilt libraries are available for Java, .NET, Electron, Python, C++, Go and Node. For other languages there is a guide for how to create wrappers using SWIG that allows the SDK to be used from PHP and Ruby.

What is SWIG?

Copied to clipboard

Wikipedia says, “The Simplified Wrapper and Interface Generator (SWIG) is an open-source software tool used to connect computer programs or libraries written in C or C++ with scripting languages such as Lua, Perl, PHP, Python, R, Ruby, Tcl, and other languages like C#, Java, JavaScript, Go, D, OCaml, Octave, Scilab and Scheme.”

Basically, it takes a C or C++ library, such as the Apryse SDK, and creates a new library in a different language that can then use it. Furthermore, it does that without needing much manual intervention, and avoids the risks of errors creeping in that would be likely if the code was ported manually.

Copied to clipboard

Ruby version 2.x

CMake version ≥ 2.8

SWIG 2.0.4 - 2.0.12 or SWIG 3.0.12 or SWIG 4.0.2+ (Ruby 2.7+)

64-bit Apryse SDK for Linux (or 32-bit)

Creating the Wrappers

Copied to clipboard

In Linux, create a new folder which will contain the wrappers. You can call it whatever you wish, but I used the name ‘Wrappers’.

Having created the folder, navigate to it.

Blog image

Clone the uncompiled PDFNet wrappers from the git repo using

git clone https://github.com/PDFTron/PDFNetWrappers

Blog image

Navigate to the newly created PDFNetWrappers/PDFNetC and download the PDFNet C/C++ SDK into that directory. (Make sure that you get the bitness that you need for your Ruby interpreter).

For example, the way to do this for the 64-bit interpreter is

Blog image

Unpack PDFNetC64.tar.gz using tar xvzf PDFNetC64.tar.gz. If you are using the 32-bit SDK then the file name will be different.

Blog image

Now move the PDFNet libraries into the current folder using

mv PDFNetC64/Lib/ . 

and

mv PDFNetC64/Headers/ .

Blog image

You are now finished with PDFNetC64.tar.gz, so feel free to delete it.

Create a new folder called Build inside /PDFNetWrappers (which will likely be the parent folder of the one that you are currently in), then navigate into it.

Blog image

Now call CMake

cmake -D BUILD_PDFNetRuby=ON ..

Blog image
Blog image

When this successfully completes you will see 

“Build files have been written to ~/PDFNetWrappers/Build”

Great stuff. Nearly there!

Call make.

You are likely to see some warnings, but they can be ignored. SWIG is a generic tool, and some of the warnings don’t relate to specific languages.

Blog image
Blog image

Finally call sudo make install

Blog image

Excellent work! All that is left to do is to enter a license key, and run the samples or integrate Apryse SDK into your own application.

Finding the Samples

Copied to clipboard

A plethora of samples are included with the SDK. These cover the vast range of functionality that the SDK supports – Adding annotations, Converting Office documents to PDFs, Redaction and Creation of PDF Portfolios to name just a few.

These samples are located in the PDFNetWrappers/Samples folder.

Blog image

Adding a License Key

Copied to clipboard

If you don’t already have a trial key, then you can request one from https://dev.apryse.com/get-key

The key then needs to be added to the file LicenseKey.rb in the folder PDFNetWrappers/Samples/LicenseKey/RUBY/

Blog image

Awesome! You are now ready to use the SDK!

Conclusion

Copied to clipboard

You have now seen how a wrapper can be created for Ruby that allows the power of the Apryse SDK to be leveraged for use for that language.

When you are ready to get started, see the documentation for the SDK to get started quickly. If you have any problems then please reach out to us on Discord.

Sanity Image

Roger Dunham

Share this post

email
linkedIn
twitter