|
| 1 | + |
| 2 | + |
| 3 | +## Tutorial: Getting Started with n8n, pdfRest, & Drobox Integration |
| 4 | + |
| 5 | +### Objective |
| 6 | + |
| 7 | +In this post we'll cover how to: |
| 8 | + |
| 9 | +1. Retrieve a JPEG from a Dropbox URL |
| 10 | +2. Upload the image to the pdfRest API Toolkit service |
| 11 | +3. Convert the image to a .pdf document |
| 12 | +4. Upload the newly converted PDF file back into Dropbox |
| 13 | +6. Merge that PDF file with another |
| 14 | + |
| 15 | +--- |
| 16 | +### Step 1: Uploading the Image |
| 17 | + |
| 18 | +Files intended for the pdfRest API service will first need to be retrieved from somewhere. The file storage service **Dropbox**, used in this tutorial, is one of many options available within n8n. In the example below we download the file `image.jpeg` and stored that in the n8n workflow as `dropbox_jpeg`. |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +The next step is to create an **HTTP Request** that uploads the file to pdfRest using the **/upload** endpoint. |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +For the **HTTP Request**, set up a **POST** to `https://api.pdfrest.com/upload`. Leave **Authentication** set to `None`. Authorization will be done in the Header further down this guide. |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +Create one **Header Parameter** for `api-key` and set your API Key in the value. Your API Key can be found, when logged in, at the very bottom of the [Account page](https://pdfrest.com/account). |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +Lastly create a **Form-Data body type**. The only **Parameter Type** that we need here is a **n8n Binary File** referencing `dropbox_jpeg` from first step. |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +When run, the steps above will output a JSON formatted response from pdfRest with the `name` and `id` of the uploaded file(s), to be used later inside by n8n. This is an example of the output: |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +--- |
| 43 | +### Step 2: Converting the Image to PDF |
| 44 | + |
| 45 | +Create another **HTTP Request** step, this time to convert the image to a PDF. This will be a **POST** to `https://api.pdfrest.com/pdf`. |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +Use the same Header Parameter for `api-key` as in the Upload call above. |
| 50 | + |
| 51 | +This time we will have a **JSON Body Content Type**. Create a **Body Paramter** for `id`. The value of `id` will come from the JSON response of Upload call above. Note that you can click and drag on the `id` field in the **Schema** tab drop the correct variable directly into the `Value` tab (`{{ $json.files[0].id }}` in the image below). |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +The JSON output of this API call to /pdf will contain: |
| 56 | +- The `inputId` of our previously uploaded image file |
| 57 | +- The `outputId` of the newly converted PDF file |
| 58 | +- The `outputUrl` to download the converted PDF file |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +--- |
| 63 | +### Step 3: Downloading the PDF |
| 64 | + |
| 65 | +In order to retrieve the newly converted PDF you will create a GET **HTTP Request** using the value of the `outputUrl`. No body or header needed for this step. This will produce a binary file data object (in this case, a technical way of saying a .pdf file) to be sent wherever you wish. In this example, we are downloading the results back into Dropbox. |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +--- |
| 71 | +### Step 4: Merging PDFs with n8n |
| 72 | + |
| 73 | +Next we will use the `/merged-pdf` endpoint to merge the converted PDF with another PDF. |
| 74 | + |
| 75 | +The first step is to download the new PDF from Dropbox just like we did before with the JPEG. Again, the files in your workflow can come from anywhere, we are using Dropbox in this example. |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +Make another **HTTP Request** to `https://api.pdfrest.com/upload` with the same `api-key` Header Parameter as before and the only difference being that we are uploading the PDF from Dropbox this time. The new **Input Data Field Name** will be `dropbox_pdf`. |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +To merge the files we will make an **HTTP Request** to `https://api.pdfrest.com/merged-pdf`. This will use the POST **Method** with the `api-key` Header set as before. |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +For the **Body Parameters**, set the **Content Type** to `JSON` and set **Specify Body** to `Using JSON`. In this merge example, we will be sending two PDF files using their `id` values, merging page 1 of each file into a new 2-page document. The `id` values are pulled from the `outputId` from the Convert to PDF from JPEG step, and the `id` of the Upload PDF to pdfRest step. Again, you can drag and drop the values, indicated by the red arrows in the image below: |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +Since the `id` values are being pulled from existing steps, they will be dynamically generated every time the workflow runs. This is an example of our JSON: |
| 92 | + |
| 93 | + |
| 94 | +``` |
| 95 | +{ |
| 96 | + "id": [ |
| 97 | + "132143265-bbac-445d-80f0-43629d94a97e", |
| 98 | + "21abec90f-7c2e-4447-8711-85f470362940" |
| 99 | + ], |
| 100 | + "type": [ |
| 101 | + "id", |
| 102 | + "id" |
| 103 | + ], |
| 104 | + "pages": [ |
| 105 | + 1, |
| 106 | + 1 |
| 107 | + ] |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +Just as when we called `/pdf` above, this **HTTP Request** will result in a JSON object with `inputId`s, an `outputId`, and an `outputUrl` that can be used to download the final, merged document. |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | +If you have any trouble getting this set up or would like more information about how pdfRest can solve your PDF processing challenges, please [let us know](https://pdfrest.com/support/) how we can help! |
| 117 | + |
| 118 | +--- |
0 commit comments