> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/get-started/languages/ruby.md).

# Ruby PDF library integration

Discover how to integrate the Apryse SDK with Ruby on macOS and Linux. Get started with precompiled Ruby wrappers or build your own with PDFNet bindings. Free trial available! The Apryse Server SDK st

Welcome to Apryse. Ruby for the Apryse SDK is supported on Linux and macOS. To get started, choose your preferred platform from the tabs below.

{% tabs %}
{% tab title="macOS" %}

## Ruby & macOS PDF library integration

There are two ways to use Apryse with Ruby on macOS:

* Use the precompiled universal library for Ruby 2.6+.
* Use PDFNet bindings to build your own wrappers.

To get started, please choose a tab below.

{% tabs %}
{% tab title="Ruby 2.6" %}
This guide will help you get started using the **precompiled Ruby wrappers**. You can [run Apryse samples](#run-the-samples) and [integrate a free trial of the Apryse SDK into Ruby application](#integrate-into-your-application) on macOS. Your free trial includes unlimited trial usage and support from solution engineers.

## Prerequisites

* **Ruby 2.6 - 2.7**
* Apryse precompiled Python/Ruby SDK for macOS:

{% code lineNumbers="true" %}

```sh
curl -L -O https://downloads.apryse.com/downloads/PDFNetWrappersMac.zip
unzip PDFNetWrappersMac.zip
```

{% endcode %}

{% hint style="info" %}
**Run Apryse SDK in production**

A commercial license key is required for use in a production environment. Please [fill out our licensing form](https://apryse.com/form/contact-sales) if you do not have a valid license key.
{% endhint %}

{% hint style="warning" %}
**Keep your commercial license key confidential.**

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

## Initial setup

1. [Download the Python and Ruby prebuilt binaries](#prerequisites).
2. Extract the downloaded zip file and navigate to it.
3. Navigate to the `/PDFNetC/Lib` directory of the Python SDK download and execute:

{% code lineNumbers="true" %}

```sh
sh ./fix_rpaths.sh
```

{% endcode %}

4. Get your Apryse trial key.

{% @apryse-license-key/apryse-license-key platform="SERVER" variant="full" %}

## Run the samples

**Run a specific sample**

1. Navigate to the `RUBY` folder in the sample, for example `/Samples/RUBY` and execute `./RunTest.sh`.

**Run all samples**

1. To run all tests, navigate to `/Samples` and execute the `runall_ruby` file:

{% code lineNumbers="true" %}

```ruby
./runall_ruby.sh
```

{% endcode %}

The tests will run one by one.

{% hint style="info" %}
Output files will be in `/Samples/TestFiles/Output`
{% endhint %}

## Integrate into your application

This section will show you how to use our SDK to create a simple Apryse "Hello World!" application. It will create a document with one blank page and save it as a [linearized PDF](https://apryse.com/blog/pdf-format/what-is-pdf-linearization) in its running directory.

1. Navigate to your `/Samples` directory and make a new directory called `myApp` (if it does not exist already). This guide will assume your application is named myApp. For organization, create a new directory inside `myApp` called `RUBY`.
2. Navigate inside that `RUBY` folder and create a new Ruby file called `myApp.rb`. Open it with your favorite text editor and paste this into it:

{% code lineNumbers="true" %}

```ruby
require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby
$stdout.sync = true
  PDFNet.Initialize("YOUR_APRYSE_LICENSE_KEY")         # PDFNet must be initialized before accessing any Apryse API
  doc = PDFDoc.new()
  page = doc.PageCreate()     # Start a new page
  doc.PagePushBack(page)      # Add the page to the document
  doc.Save("output.pdf", SDFDoc::E_linearized);   # Save the document as a linearized PDF
  puts "Hello World!"
```

{% endcode %}

Run your application by executing `ruby myApp.rb`. If all goes well, your console should output:

{% code lineNumbers="true" %}

```sh
PDFNet is running in demo mode.
Permission: write
Hello World!
```

{% endcode %}

Check the `output.pdf` that the program output in the same directory. It should be a PDF with one blank page.
{% endtab %}

{% tab title="Custom Wrapper" %}
This guide will help you [build your own PDFNet Ruby wrappers](#initial-setup-1) by binding a free trial of the PDFNetC library to Ruby. It will also show you how to [run Apryse samples](#run-the-samples-1) and [integrate the Apryse SDK into Ruby applications](#integrate-into-your-application-1) on macOS. Your free trial includes unlimited trial usage and support from solution engineers.

## Prerequisites

* **Ruby** version 2.x - 3.2
* [**CMake**](https://cmake.org/download/) version ≥ 2.8
* [**SWIG**](http://www.swig.org/) 2.0.4 - 2.0.12 or [**SWIG**](http://www.swig.org/) 3.0.12 or [**SWIG**](http://www.swig.org/) 4.0.2+ (Ruby 2.7+)
* Download the Apryse PDF library for macOS:

{% code lineNumbers="true" %}

```sh
curl -L -O https://downloads.apryse.com/downloads/PDFNetCMac.zip
unzip PDFNetCMac.zip
```

{% endcode %}

{% hint style="info" %}
**Run Apryse SDK in production**

A commercial license key is required for use in a production environment. Please [fill out our licensing form](https://apryse.com/form/contact-sales) if you do not have a valid license key.
{% endhint %}

{% hint style="warning" %}
**Keep your commercial license key confidential.**

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

## Initial setup

1. Make a directory to store the wrappers and navigate into that directory.
2. Clone the PDFNet Wrappers project, select the correct branch for your release afterwards. This is typically a numbered release such as `11.11`, `11.12`, `11.13` and `12.0`.

{% code lineNumbers="true" %}

```sh
git clone https://github.com/ApryseSDK/
git checkout <SDK Version>
```

{% endcode %}

3. Navigate to `PDFNetWrappers/PDFNetC`. Download the Apryse SDK using the method described in the **Prerequisites** section, and place the downloaded package in this directory and unzip it.
4. Now, to move the headers in place, make sure you're in the `PDFNetWrappers/PDFNetC` directory and execute:

{% code lineNumbers="true" %}

```sh
mv PDFNetCMac/Headers/ .
```

{% endcode %}

and

{% code lineNumbers="true" %}

```sh
mv PDFNetCMac/Lib/ .
```

{% endcode %}

to move the PDFNet libraries in place.

You can delete `PDFNetCMac.zip` to free up space.

Your `/PDFNetC` folder should be laid out like this like this:

{% code lineNumbers="true" %}

```
PDFNetC
├── Headers
├── Lib
├── PDFNetCMac
└── README.txt
```

{% endcode %}

5. Make a build directory inside `/PDFNetWrappers` and navigate to it. This guide will assume the build directory is called Build.
6. Execute:

{% code lineNumbers="true" %}

```sh
cmake -D BUILD_PDFNetRuby=ON ..
```

{% endcode %}

If all goes well, you should get a message that reads:

{% code lineNumbers="true" %}

```
Build files have been written to ~/PDFNetWrappers/Build
```

{% endcode %}

7. Execute `make` followed by `sudo make install`.
8. Next, we need to fix the `rpaths` issue on Mac. While still in the same `Build` directory, execute these lines:

{% code lineNumbers="true" %}

```sh
cp ../fix_rpaths.sh ../PDFNetC/Lib/
cd ../PDFNetC/Lib/
sudo sh ./fix_rpaths.sh
```

{% endcode %}

9. Get your Apryse trial key.

{% @apryse-license-key/apryse-license-key platform="SERVER" variant="full" %}

You are now ready to [run the samples](#run-the-samples-1) or [integrate Apryse SDK into your own application](#integrate-into-your-application-1).

## Run the samples

**Run a specific sample**

**1.** Navigate to the `RUBY` folder in the sample, for example `/Samples/AddImageTest/RUBY` and execute `./RunTest.sh`

**Run all Samples**

1. Navigate to `/Samples` and execute:

{% code lineNumbers="true" %}

```sh
./runall_ruby.sh
```

{% endcode %}

The tests will run one by one.

{% hint style="info" %}
Output files will be in `/Samples/TestFiles/Output`
{% endhint %}

## Integrate into your application

This section will show you how to use our SDK to create a simple Apryse "Hello World!" application. It will create a document with one blank page and save it as a [linearized PDF](https://apryse.com/blog/pdf-format/what-is-pdf-linearization) in its running directory.

1. Navigate to your `/Samples` directory and make a new directory called `myApp` (if it does not exist already). This guide will assume your application is named myApp. For organization, create a new directory inside `myApp` called `RUBY`.
2. Navigate inside that `RUBY` folder and create a new Ruby file called `myApp.rb`. Open it with your favorite text editor and paste this into it:

{% code lineNumbers="true" %}

```ruby
require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby
$stdout.sync = true
  PDFNet.Initialize("YOUR_APRYSE_LICENSE_KEY")         # PDFNet must be initialized before accessing any Apryse API
  doc = PDFDoc.new()
  page = doc.PageCreate()     # Start a new page
  doc.PagePushBack(page)      # Add the page to the document
  doc.Save("output.pdf", SDFDoc::E_linearized);   # Save the document as a linearized PDF
  puts "Hello World!"
```

{% endcode %}

Run your application by executing `ruby myApp.rb`. If all goes well, your console should output:

{% code lineNumbers="true" %}

```
PDFNet is running in demo mode.
Permission: write
Hello World!
```

{% endcode %}

Check the `output.pdf` that the program output in the same directory. It should be a PDF with one blank page.
{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="Linux" %}

## Ruby & Linux PDF library integration

This guide will help you [build your own PDFNet Ruby wrappers](#initial-setup-2) by binding a free trial of the PDFNetC library to Ruby. It will also show you how to [run Apryse samples](#run-the-samples-2) and [integrate the Apryse SDK into Ruby applications](#integrate-into-your-application-2) on Linux. Your free trial includes unlimited trial usage and support from solution engineers.

## Prerequisites

* Ruby version 2.x, 3.x
* [**CMake**](https://cmake.org/download/) version ≥ 2.8
* [**SWIG**](http://www.swig.org/) 2.0.4 - 2.0.12 or [**SWIG**](http://www.swig.org/) 3.0.12 or [**SWIG**](http://www.swig.org/) 4.0.2 - 4.2.1 (Ruby 2.7+) or [**SWIG**](http://www.swig.org/) 4.3.0+ (Ruby 3.2+)
* Download the Apryse Ruby SDK for Linux:

{% @apryse-download-button/apryse-download-button id="Ruby\_SDK\_64\_bit\_core\_linux" showVersion="false" %}

{% @apryse-download-button/apryse-download-button id="Ruby\_SDK\_32\_bit\_core\_linux" showVersion="false" %}

Or download from the command line:

{% tabs %}
{% tab title="64-bit Ruby SDK" %}
{% code lineNumbers="true" %}

```sh
wget https://downloads.apryse.com/downloads/PDFNetC64.tar.gz
```

{% endcode %}
{% endtab %}

{% tab title="32-bit Ruby SDK" %}
{% code lineNumbers="true" %}

```sh
wget https://downloads.apryse.com/downloads/PDFNetC.tar.gz
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Run Apryse SDK in production**

A commercial license key is required for use in a production environment. Please [contact sales](https://apryse.com/form/contact-sales) to purchase a commercial key or if you need any other license key assistance.
{% endhint %}

{% hint style="warning" %}
**Keep your commercial license key confidential.**

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

## Initial setup

1. Create a directory to store the wrappers, then navigate into it.
2. Clone the PDFNet Wrappers project, then select the correct branch for your release. This is typically a numbered release such as `11.11`, `11.12`, `11.13`, and `12.0`.

{% code lineNumbers="true" %}

```sh
git clone https://github.com/apryse.com/PDFNetWrappers
git checkout <SDK Version>
```

{% endcode %}

3. Navigate to `PDFNetWrappers/PDFNetC`. Download the Apryse Ruby SDK using one of the methods described in the **Prerequisites** section, and place the downloaded package in this directory. Ensure the SDK architecture matches your Ruby interpreter (32-bit or 64-bit).
4. Unpack `PDFNetC64.tar.gz` via `tar xvzf PDFNetC64.tar.gz`, then execute:

{% code lineNumbers="true" %}

```sh
mv PDFNetC64/Headers/ .
```

{% endcode %}

and

{% code lineNumbers="true" %}

```sh
mv PDFNetC64/Lib/ .
```

{% endcode %}

and move the PDFNet libraries in place. You can delete `PDFNetC64.tar.gz` to free up space. Your `/PDFNetC` folder should be laid out like this:

{% code lineNumbers="true" %}

```sh
PDFNetC
├── Headers
├── Lib
├── PDFNetC64
└── README.txt
```

{% endcode %}

5. Make a build directory inside `/PDFNetWrappers` and navigate to it. This guide will assume the build directory is called Build.
6. Execute:

{% code lineNumbers="true" %}

```sh
cmake -D BUILD_PDFNetRuby=ON ..
```

{% endcode %}

If all goes well, you should get a message that reads:

{% code lineNumbers="true" %}

```sh
Build files have been written to ~/PDFNetWrappers/Build
```

{% endcode %}

7. Execute `make` followed by `sudo make install`. You are now ready to [run the samples](#run-the-samples-2) or [integrate Apryse SDK into your own application](#integrate-into-your-application-2).
8. Get your Apryse trial key.

{% @apryse-license-key/apryse-license-key platform="SERVER" variant="full" %}

## Run the samples

**Run a specific sample**

1. Navigate to the `RUBY` folder in the sample, for example `/Samples/AddImageTest/RUBY` and execute `./RunTest.sh`

**Run all samples**

1. Navigate to `/Samples` and execute:

{% code lineNumbers="true" %}

```sh
./runall_ruby.sh
```

{% endcode %}

The tests will run one by one.

{% hint style="info" %}
**Output files will be in /Samples/TestFiles/Output**
{% endhint %}

## Integrate into your application

This section will show you how to use our SDK to create a simple Apryse "Hello World!" application. It will create a document with one blank page and save it as a [linearized PDF](https://apryse.com/blog/pdf-format/what-is-pdf-linearization) in its running directory.

1. Navigate to your `/Samples` directory and make a new directory called `myApp` (if it does not exist already). This guide will assume your application is named myApp. For organization, create a new directory inside `myApp` called `RUBY`.
2. Navigate inside that `RUBY` folder and create a new Ruby file called `myApp.rb`. Open it with your favorite text editor and paste this into it:

{% code lineNumbers="true" %}

```ruby
require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby

$stdout.sync = true

  PDFNet.Initialize("YOUR_APRYSE_LICENSE_KEY")         # PDFNet must be initialized before accessing any Apryse API
  doc = PDFDoc.new()
  page = doc.PageCreate()     # Start a new page
  doc.PagePushBack(page)      # Add the page to the document
  doc.Save("output.pdf", SDFDoc::E_linearized);   # Save the document as a linearized PDF
  puts "Hello World!"
```

{% endcode %}

3. Run your application by executing `ruby myApp.rb`. If all goes well, your console should output:

{% code lineNumbers="true" %}

```sh
PDFNet is running in demo mode.
Permission: write
Hello World!
```

{% endcode %}

Check the `output.pdf` that the program outputs in the same directory. It should be a PDF with one blank page.
{% endtab %}
{% endtabs %}

## Next step

<a href="https://github.com/iKettles/apryse-gitbook/tree/main/core/guides/README.md" class="button primary">Guides</a><a href="/core/get-started/samples.md" class="button primary">Samples</a>

## Troubleshooting

Check the [troubleshooting page](/core/get-started/faq.md) and our [PDFNetWrappers github](https://github.com/ApryseSDK/PDFNetWrappers/) if you run into any issues going through this document.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/get-started/languages/ruby.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
