Skip to main content

Merge PDFs by Alternating Pages Interleave pages from two PDF documents alternately.

PDF Interleave illustration
📄

PDF Interleave

Interleave pages from two PDF documents alternately.

1

Upload Two PDFs

Drop PDF A (odd positions) and PDF B (even positions).

2

Interleave

Pages are alternated: A1, B1, A2, B2, etc.

3

Download

Get the interleaved PDF document.

Loading tool...

What Is PDF Interleave?

A PDF Interleave is a process that combines two PDF files by alternating their pages, effectively merging them into a single document where the pages from each original file are interleaved. This functionality is particularly useful for users who need to reassemble double-sided scans or collate pdf pages from separate documents, such as researchers and office administrators working with large volumes of scanned or printed materials. One specific problem it solves is handling PDFs that were originally part of a single document but were scanned or printed in two separate parts, allowing users to easily merge pdf alternating pages back into their original order.

The tool's ability to handle PDFs of different lengths and page counts makes it especially useful for tasks like reassembling double-sided scans where one side may have more pages than the other. What sets this implementation apart is its use of the `pdf-lib` library to load and manipulate the PDF documents, allowing it to accurately count the number of pages in each file and interleave them correctly, even if they are not the same length. It also provides a clear and user-friendly interface for loading the PDF files, tracking progress, and downloading the resulting merged document, making it easy to perform tasks like merging two related documents page by page or alternate pdf pages from separate scans.

By using this tool to interleave pdf pages, users can easily create a single, cohesive document that combines the contents of two original files in an alternating pattern, with the remaining pages appended at the end if one file is longer than the other. This makes it ideal for applications where documents need to be reassembled or collated from separate scans or prints, such as in academic research or office administration, and supports tasks like pdf page interleave and merge pdf alternating pages with ease.

Why Use PDF Interleave?

  • Perfect for reassembling double-sided scans
  • Handles unequal page counts gracefully
  • Simple two-file drag and drop interface
  • Maintains original page quality

Common Use Cases

Scanner Reassembly

Combine separate front/back scan batches into proper page order.

Comparison Documents

Alternate original and revised pages for review.

Bilingual Documents

Interleave translations with original pages.

Study Materials

Alternate question and answer pages.

Technical Guide

The tool works under the hood by utilizing the `pdf-lib` library to load and manipulate PDF documents. When a user drops two PDF files into the interface, it triggers the `loadFile` function which uses `arrayBuffer` to read the file contents and then loads the PDF document using `PDFDocument.load`. This process ignores any encryption on the PDFs, allowing it to accurately count the number of pages in each file. The page counts are stored in the component's state as `pagesA` and `pagesB`.

When the user initiates the interleaving process, the tool uses `Promise.all` to load both PDF documents into memory simultaneously, ensuring that both files are fully loaded before proceeding. It then creates a new merged document using `PDFDocument.create`. The tool iterates through the pages of both documents using the maximum page count of either document as the loop limit. For each index, it copies the page from document A (if available) and then document B (if available) into the new document using `copyPages`, which faithfully reproduces the original pages without modifying their contents.

The resulting merged document is saved to a blob using `merged.save`, and its URL is created with `URL.createObjectURL`. This allows the user to download the interleaved PDF directly from the browser. Throughout this process, the tool handles potential errors by catching exceptions and displaying error messages to the user. It also cleans up object URLs when the component unmounts to prevent memory leaks, using `useEffect` to revoke the object URL when it is no longer needed.

The use of `useState`, `useCallback`, and `useRef` hooks in the tool enables efficient management of its state and side effects, ensuring that the interface remains responsive even during resource-intensive operations like PDF merging. By leveraging these React features and the capabilities of `pdf-lib`, the tool provides a reliable and user-friendly solution for interleaving PDF pages from separate documents.

Tips & Best Practices

  • 1
    PDF A pages appear in odd positions (1, 3, 5...)
  • 2
    PDF B pages appear in even positions (2, 4, 6...)
  • 3
    Works with different page sizes between documents
  • 4
    For reversed back pages, rotate PDF B first

Related Tools

Frequently Asked Questions

Q What if the PDFs have different page counts?
Extra pages from the longer PDF are appended at the end.
Q Can I interleave more than two PDFs?
This tool handles two PDFs. For more, interleave twice.
Q Does page size matter?
No, pages maintain their original sizes even if different between documents.
Q Can I reverse the order?
Yes, swap which file you upload as PDF A vs PDF B.
Q Is the interleave always 1:1?
Yes, one page from each PDF alternately.

About This Tool

PDF Interleave is a free online tool by FreeToolkit.ai. All processing happens directly in your browser — your data never leaves your device. No registration or installation required.