Split & Merge PDF – How To Edit PDF Files Via API

API
Image by http://bit.ly/2ejxaXS

Converting from and to PDF is nice, but you want more?

With the API of Online-Convert.com you can now edit PDF documents! Using Postman and our API you can now merge or split PDF files. You don’t have to be a developer for this either. Check out our tutorial on how to use Postman to test our API and start editing!

In this blog article, we will show you how to perform these three easy operations on a PDF document:

  • Merge two or more PDFs into one
  • Split a PDF to create several PDFs

 

How To Edit PDFs Via API

In order to perform these editing functions, you should be familiar with postman and have access to the Online-Convert.com API. This article will show you how to do this, including a link to the necessary collection file.

Of course you can also check out our video tutorial on how to use the Online-Convert.com API.

 

Once you got the basics down, we can have a look at how to edit PDFs using the API. Following, we will talk about both functions mentioned above in detail.

In order to do so, we always need a “default” command we will send to the API:

{
    "input": [{
         "type": "remote",
         "source": "https://cdn.online-convert.com/example-file/document/pdf/example.pdf"
     }],
     "conversion": [{
     "target": "pdf",
     "category": "document"
     }]
 }

This simple POST command will convert our example PDF file into another PDF. Now we can add options using the following command:

"options": {
}

 

Merge PDF Files

In order to merge PDF files you, obviously, need several files as input. In order to do so, you need a POST command like the following:

{
    "input": [{
        "type": "remote",
        "source": "https://cdn.online-convert.com/example-file/document/pdf/example.pdf"
    },
    {
        "type": "remote",
        "source": "https://cdn.online-convert.com/example-file/document/pdf/example_multipage.pdf"
    }],
    "conversion": [{
        "target": "pdf"
        "category": "document"
    }]
}

In this example, we try to merge two PDF files. Of course you can specify more than two files in your call.

 

The general command for merging files is:

"merge": {
    "type": "boolean",
    "description": "Merges the input files in one output file using the order as they appears in the input section of the message."
}

The value that can be added here is, once more, true or false. Furthermore, please note that the files will be merged in the order specified in the input.

 

This is a full POST command that would merge our two PDF files:

{
    "input": [{
        "type": "remote",
        "source": "https://cdn.online-convert.com/example-file/document/pdf/example.pdf"
    },
    {
        "type": "remote",
        "source": "https://cdn.online-convert.com/example-file/document/pdf/example_multipage.pdf"
    }],
    "conversion": [{
        "target": "pdf",
        "category": "document",
        "options": {
            "merge": true
        }
    }]
}

The output of this conversion after your GET is a single PDF file that contains both files you have merged.

 

Split PDF Files

If you want to split a PDF into several output files, your file has to contain more than one page of content. If this is the case, you can use the following command to split this file into several PDFs:

"split": {
    "type": "string",
    "pattern": "^(\\d+-?\\d*)(, ?(\\d+-?\\d*))*$",
    "description": "The pages where to split the original file. E.g. in a 30 pages document, an entry of 10,20 will results in three output files with pages 1-10, 11-20, 21-30"
}

The string to enter for the split function should contain the numbers of the pages after which you would like to split the document.

E.g. specifying 5 would result into a cut after page no 3 of your document. The resulting PDFs will contain pages 1 to 3 (output no 1) and 4 to end (output no 2).

 

The following command is what your complete POST to split a PDF should look like:

{
    "input": [{
        "type": "remote",
        "source": "https://cdn.online-convert.com/example-file/document/pdf/example_multipage.pdf"
    }],
    "conversion": [{
        "target": "pdf",
        "category": "document",
        "options": {
            "split": "3"
        }
    }]
}

With this command, we successfully split our 7-pages document after the third page, resulting in two PDFs (one containing page 1 to 3 and the other containing page 4 to 7). Both PDFs will be packed into a ZIP archive for your convenience.

If you want to split your document into more than two output files, simply add all the pages you want the cut to appear after divided by a comma:

[...]
"options": {
            "split": "3,5"
        }
[...]

This command fill split your PDF after pages 3 and 5, resulting in the following output:

  • PDF 1: pages 1 to 3
  • PDF 2: pages 4 to 5
  • PDF 3: 5 to 7

 

Got any questions?

If you have any questions regarding the API of Online-Convert.com or how to split and merge PDF files using it, feel free to contact us! Our friendly support team will lend you a hand with whatever you may need.

 

Further Information