PSPDFKit Server Example – Rails
This example shows how to integrate PSPDFKit Server and PSPDFKit for Web into a Rails app.
Note: This example demonstrates the usage of PSPDFKit for Web in a Rails application and is not optimized for production deployments. For information on how to set up PSPDFKit for Web in production, please refer to our guides instead.
Prerequisites
We recommend you use Docker to get all components up and running quickly.
You can easily run the example in trial mode without need for a license or activation key. Just make sure to check out this repository locally. The provided docker-compose.yml
and Dockerfile
will allow you to edit the example app on your host, and it will live-reload:
$ git clone https://github.com/PSPDFKit/pspdfkit-server-example-rails.git
$ cd pspdfkit-server-example-rails
$ docker-compose up
The example is now running on http://localhost:3000. You can access the PSPDFKit Server dashboard at http://localhost:5000/dashboard using dashboard
// secret
.
Upload a PDF via the button in the top-left, then click on the cover image to see PSPDFKit for Web in action.
Using a license
If you have a PSPDFKit Server license you can use it as well by going through the following steps:
-
Open the
docker-compose.yml
file in an editor of your choice and replace theYOUR_LICENSE_KEY_GOES_HERE
placeholder with your standalone license key. -
Start environment with your PSPDFKit Server activation key:
$ ACTIVATION_KEY=YOUR_ACTIVATION_KEY_GOES_HERE docker-compose up
If you are using Windows make sure to set the environment variables accordingly. For this replace the line starting with ACTIVATION_KEY="...
with:
$ SET "ACTIVATION_KEY=YOUR_ACTIVATION_KEY_GOES_HERE"
$ docker-compose up
Make sure to replace YOUR_ACTIVATION_KEY_GOES_HERE
with your PSPDFKit Server activation key. You only have to provide the activation key once, after that the server will remain activated until you reset it.
Resetting the server
You can reset the server by first tearing down its containers and volumes and then recreating them.
$ docker-compose down --volumes
$ docker-compose up
If using an activation key, you'd need to set it again so as to recreate the containers:
$ docker-compose down --volumes
$ ACTIVATION_KEY=YOUR_ACTIVATION_KEY_GOES_HERE docker-compose up
If you are using Windows make sure to set the environment variables accordingly. For this replace the line starting with ACTIVATION_KEY="...
with:
$ SET "ACTIVATION_KEY=YOUR_ACTIVATION_KEY_GOES_HERE"
$ docker-compose up
Running the example locally
You can also run the example app directly on your machine, outside of a Docker container.
Prerequisites
- Ruby 2.7.2 or newer (The sample is a Rails 6.1 app)
- PSPDFKit Server running on http://localhost:4000 with the default configuration
Getting Started
$ git clone https://github.com/PSPDFKit/pspdfkit-server-example-rails.git
$ cd pspdfkit-server-example-rails
$ bundle
$ bin/rails db:migrate
$ bin/rails server
The example app is now running on http://localhost:3000.
Login using any user name and upload a PDF, then click on the cover image to see PSPDFKit Web in action.
You can also selectively share PDFs with other users you have created.
You can quit the running containers with Ctrl-C.
If you want to test PSPDFKit for Web on different devices in your local network, you need
to edit the PSPDFKIT_SERVER_EXTERNAL_URL
environment variable in the docker-compose.yml
and set it to an address that's reachable from your device.
Troubleshooting
Occasionally running the docker-compose
scripts will result in errors because some containers are in a broken state. To resolve this, you can reset all containers and their attached volumes by running the following command:
docker-compose down --volumes
If you have further troubles, you can always reach out to us via our support platform.
Support, Issues and License Questions
PSPDFKit offers support for customers with an active SDK license via https://pspdfkit.com/support/request/
Are you evaluating our SDK? That's great, we're happy to help out! To make sure this is fast, please use a work email and have someone from your company fill out our sales form: https://pspdfkit.com/sales/
License
This software is licensed under a modified BSD license.
Contributing
Please ensure you signed our CLA so we can accept your contributions.
Any contribution must successfully pass bin/ci
checks.