Common functions

If you have read the Basics to process a PDF guide, you know now the very basics of how to process a PDF. In this guide you will learn how to execute common functions for all API tools and set attributes, some of them, while not essential, can be very helpful to use for the Upload, Process and Download instructions.

Functions and attributes for Upload

You can upload files from the following storage types:

  • Local
  • Web

Upload from local

For local files you must use addFile() function and it is mandatory to set always local path filename to upload.

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

Upload from Web

Upload from Web works exactly the same as from local, only need to set an URL on an addURLFile() function.

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

File attributes

We can control two file attributes:

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

Set a password for protected files

setPassword() is used to open password protected files (PDFs and Office) and needs to receive the file's password as a parameter. If a file needs a password and it's not provided or has a wrong password provided, the API will inform about a Bad request Error 400 indicating which file/s need a password. The task won’t be closed so you can send a password again at any time.

However, it is possible to run the task by ignoring those files which require password and process only those which don’t need it with the function setIgnorePassword(boolean).

Rotate a file

It's possible to rotate the orientation of any uploaded file by using setRotation() function with one of four directions parameters (Up = 0, Right = 90, Down = 180, Left = 270);

Delete files

You may need to delete previously uploaded files from a task. In this case use the following delete function:

Advanced processing

We have seen how to process PDF’s in a very basic way before. In addition, processing instructions have some advanced and common options to consider. You will see advanced processing customizations for every tool but here we will focus on those common to all the tools.

Example code:

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

Ignore password protected files

As explained a few lines above in Uploaded file properties you can ignore password protected files with setIgnorePassword(boolean) when processing your task.

Ignore file errors

Some of the uploaded files may be damaged and won’t be able to process. setIgnoreErrors(boolean) allows to ignore those damaged files and force the task to process the good ones.

Tasks have setIgnoreErrors(true) by default so you won’t need this function unless you want to force an error message for any damaged file.

Try file to repair a damaged PDF

One of the newest ILovePDF features is the possibility to repair damaged PDF files. By default the API tries to repair any damaged file but it is allowed to disable this behaviour with:

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

Set output filename

As a rule, the output filename of files will be the same as the input filename in many cases. Some others depend on the used tool. But you can also customize the output filename with setOutputFilename()

This function, accepts a single string to the the filename besides the following predefined vars:

{filename}=original filename
{n}=file number
{date}=current date
{tool}=the current processing action

So the final output name could be:

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

Set a package filename

ILovePDF API will always pack multiple output files in a single compressed file. You can set this package filename with setPackageFilename() adn the following predefined vars:

{filename}=original filename
{date}=current date
{tool}=the current processing action

So the final output name could be:

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

Only keys with sizes of 16, 24 or 32 chars are supported.

Functions for download

Download functions are exactly the same that the basic upload functions and allows you to download your output files to local with downloadLocal().

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

These are all the common advanced features for Upload, Process and Download instructions and now you are ready to dive into the functioning of the iLovePDF Tools.