Splitting Bulk PDF Files: How to Separate Invoices & Payslips

Every month, payroll departments receive one massive 500-page PDF containing all employee payslips. Finance teams get bulk invoices from vendors in a single file. HR gets benefit statements bundled together.

The problem? You need to email each person their individual document. Opening the PDF manually and exporting page by page is not an option when you have hundreds of documents.

In this tutorial, we will use the aPDF.io Split API to "burst" a bulk PDF into individual files automatically. Each file becomes a separate, downloadable PDF.

The Quick Solution

If every page is a separate document (one invoice per page), here is the simplest approach using JavaScript:
const data = new FormData();
data.append('file', 'https://your-server.com/bulk-invoices.pdf');
data.append('pages', 'n1'); // Split every 1 page

fetch('https://apdf.io/api/pdf/file/split', {
    headers: {
        'Authorization': 'Bearer YOUR_API_TOKEN',
        'Accept': 'application/json'
    },
    method: 'POST',
    body: data
})
.then(response => response.json())
.then(files => {
    // Array of individual PDFs
    files.forEach((pdf, i) => {
        console.log(`Invoice ${i + 1}: ${pdf.file}`);
    });
});

That is it. A 500-page PDF becomes 500 individual download links.

Understanding the Pages Parameter

The pages parameter is powerful. It controls how your PDF gets split:

  • n1 - Every page becomes its own PDF (common for single-page invoices)
  • n2 - Every 2 pages becomes a PDF (useful for 2-page statements)
  • n3 - Every 3 pages becomes a PDF (for multi-page reports)
  • 1,2-5,6-z - Custom splits: page 1, then pages 2-5, then page 6 to end

Most bulk payslips and invoices are one page each. Use n1 for those.

Step 1: Get Your API Token

  1. Sign up at aPDF.io (it's free).
  2. Copy your API Token from the dashboard.

Option A: Node.js Implementation

Here is a complete Node.js script that splits a bulk PDF and logs each resulting file:

const API_TOKEN = 'YOUR_API_TOKEN_HERE';
const API_URL = 'https://apdf.io/api/pdf/file/split';

// The bulk PDF containing all invoices/payslips
const bulkPdfUrl = 'https://your-server.com/monthly-payslips-november-2025.pdf';

async function splitBulkPdf() {
    try {
        console.log('Splitting bulk PDF into individual files...');

        const data = new FormData();
        data.append('file', bulkPdfUrl);
        data.append('pages', 'n1'); // One page per file

        const response = await fetch(API_URL, {
            method: 'POST',
            headers: {
                'Authorization': `Bearer ${API_TOKEN}`,
                'Accept': 'application/json'
            },
            body: data
        });

        if (!response.ok) {
            throw new Error(`HTTP error: ${response.status}`);
        }

        const files = await response.json();

        console.log(`Success! Split into ${files.length} individual PDFs:`);

        files.forEach((pdf, index) => {
            console.log(`  [${index + 1}] ${pdf.file}`);
            console.log(`      Pages: ${pdf.pages}, Size: ${pdf.size} bytes`);
        });

        return files;

    } catch (error) {
        console.error('Error:', error.message);
    }
}

splitBulkPdf();

Option B: Go Implementation

For backend services written in Go, here is the equivalent implementation:

package main

import (
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "net/url"
    "strings"
)

const apiToken = "YOUR_API_TOKEN_HERE"
const apiURL = "https://apdf.io/api/pdf/file/split"

type SplitResult struct {
    File       string `json:"file"`
    Expiration string `json:"expiration"`
    Pages      int    `json:"pages"`
    Size       int    `json:"size"`
}

func main() {
    bulkPdfUrl := "https://your-server.com/monthly-payslips-november-2025.pdf"

    fmt.Println("Splitting bulk PDF into individual files...")

    // Prepare form data
    formData := url.Values{}
    formData.Set("file", bulkPdfUrl)
    formData.Set("pages", "n1") // One page per file

    // Create request
    req, err := http.NewRequest("POST", apiURL, strings.NewReader(formData.Encode()))
    if err != nil {
        fmt.Println("Error creating request:", err)
        return
    }

    req.Header.Set("Authorization", "Bearer "+apiToken)
    req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
    req.Header.Set("Accept", "application/json")

    // Send request
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        fmt.Println("Error sending request:", err)
        return
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)

    if resp.StatusCode != 200 {
        fmt.Printf("Error %d: %s\n", resp.StatusCode, string(body))
        return
    }

    // Parse response
    var files []SplitResult
    json.Unmarshal(body, &files)

    fmt.Printf("Success! Split into %d individual PDFs:\n", len(files))

    for i, pdf := range files {
        fmt.Printf("  [%d] %s\n", i+1, pdf.File)
        fmt.Printf("      Pages: %d, Size: %d bytes\n", pdf.Pages, pdf.Size)
    }
}

Real-World Example: Payroll Processing

Let us say you have a 3-page PDF where each employee payslip is exactly 1 page. After splitting with n1, you get an array of results:

[
  {
    "file": "https://apdf-files.s3.eu-central-1.amazonaws.com/abc123-1.pdf",
    "pages": 1,
    "size": 45230
  },
  {
    "file": "https://apdf-files.s3.eu-central-1.amazonaws.com/abc123-2.pdf",
    "pages": 1,
    "size": 44891
  },
  {
    "file": "https://apdf-files.s3.eu-central-1.amazonaws.com/abc123-3.pdf",
    "pages": 1,
    "size": 46102
  }
]

Each URL is ready to be downloaded for 1 hour.

Handling Multi-Page Documents

What if each invoice is 2 pages (e.g., a summary page + a line-item detail page)? Simply change the pages parameter:

data.append('pages', 'n2'); // Every 2 pages becomes one PDF

A 100-page PDF becomes 50 two-page invoices.

Conclusion

Splitting bulk PDFs used to require expensive enterprise software or manual work. With the aPDF.io Split API, you can automate this in a few lines of code.

Whether it is 50 invoices or 5,000 payslips, the API handles the heavy lifting while your application stays lightweight.

Next Steps

Once you have split your documents, consider these follow-up actions:
  • Secure Individual Files: Use the Password Protection endpoint to encrypt each payslip with the employee's ID.
  • Merge Related Documents: Need to combine a cover letter with each split invoice? Use the Merge endpoint.
Ready to build?
Get your free API token here
Most APIs charge you per document. aPDF.io is built to be a developer-friendly, free alternative that handles the heavy lifting without the monthly subscription.