Basics to process PDF

It’s time to start with PDF processing but if you still don’t know how to create a project and authenticate it please refer to the Getting started guide

The PDF processing workflow with iLovePDF API is very simple for all its tools and consists in 4 basic instructions: Start task, Upload files, Process files and Download files. Once the API have executed this steps, you should have your PDF files processed with your desired tool and downloaded anywhere you like.

The iLovePDF API offers many options and custom functions for every tool but for now in this page we will focus only on how to perform a simple task with very few code lines. Once you are done with this guide we recommend you to take a look on the common attributes you can set on any task in the Common features guide.

Start task

To start a new task you need to create it with the function newTask(). This will check which server is assigned to your task and create it. You can do this by simply assign which tool of the many that iLovePDF API offers to process PDF’s we like to execute on our files. For this example we will compress our three files:

Download the PHP library from GitHub
Download the Ruby library from GitHub
Download the .Net library from GitHub

Please note that the first two lines were set in order to authenticate our project with the API servers so you only need to authenticate once per project not for every task you create!

Upload files

The next step is to assign all the files that you (or your users) want to upload by adding these files to the task like in this code example:

Download the PHP library from GitHub
Download the Ruby library from GitHub
Download the .Net library from GitHub

This example adds the path to the task and the name of three files to upload and the addFile() function will upload them automatically. You will see in further guides that you can upload files from URL using dedicated functions for this.

Process files

Now it’s time to execute your process:

Download the PHP library from GitHub
Download the Ruby library from GitHub
Download the .Net library from GitHub

Download

Finally assign to the task the action to download your files and you'll have compressed three PDF files in only 9 lines of code.

Download the PHP library from GitHub
Download the Ruby library from GitHub
Download the .Net library from GitHub

Full code

And this is how the full code looks like:

Download the PHP library from GitHub
Download the Ruby library from GitHub
Download the .Net library from GitHub

Open tasks limitation

Due to security matters and to avoid requests to the API to overflow, you must know that there's a limitation to the maximum tasks that can be opened at a time of 10% of your monthly file limit subscription. A task is opened since you upload a file and until you process it (*see password protected files exception) and usually you shouldn't have many open tasks at same time as long as you process immediately all your uploaded files. Take into account this limitation for possible code and or design errors of your apps.

*Note that for password protected files a task will not be processed (therefore not closed) until a password won't be set for these files.

Test a library

If you prefer, you can download this example here in any of the compatible API languages.

Now you’re ready to visit our Common features guide for a more advanced usage of PDF processing tools