Apache PDFBox - Merge PDFs
🔧 Operation Name
Apache PDFBox - Merge PDFs
mergePdfs
🧾 Description
Combines two or more PDF documents into a single unified PDF. Each input file is processed in-memory using PDFBox's random-access buffering to ensure full compatibility with PDFBox 3.0.x.
Ideal for combining related documents before delivery, archiving, or downstream transformation.
✅ Inputs
PDF Files [List of Binary] (
List<InputStream>
) A list of PDF streams to merge. Must contain at least two. Provided via a DataWeave expression or flow variable (e.g.,#[payload]
,#[vars.myList]
).
📤 Output
Payload:
InputStream
(binary stream) A single merged PDF containing all input documents, in the order provided.Attributes:
PdfBoxFileAttributes
Metadata from the merged output which will be from the FIRST pdf except total page count will be the combined page total of merged pdf: total page count, file size, title, author, etc.
🧪 MuleSoft Flow Example
Here’s how to call this operation in a MuleSoft flow:

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:pdfbox="http://www.mulesoft.org/schema/mule/pdfbox"
xmlns:file="http://www.mulesoft.org/schema/mule/file" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/pdfbox http://www.mulesoft.org/schema/mule/pdfbox/current/mule-pdfbox.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
<flow name="main">
<scheduler doc:name="Scheduler" doc:id="cjvhev" >
<scheduling-strategy>
<fixed-frequency timeUnit="HOURS"/>
</scheduling-strategy>
</scheduler>
<flow-ref name="apacheApache PDFBox - Merge PDFs"/>
</flow>
<sub-flow name="apacheApache PDFBox - Merge PDFs">
<ee:transform doc:name="Transform" doc:id="llryqt" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
[
readUrl("https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf", "application/octet-stream") as Binary,
readUrl("https://pdfobject.com/pdf/pdf_open_parameters_acro8.pdf", "application/octet-stream") as Binary
]]]></ee:set-payload>
</ee:message>
</ee:transform>
<pdfbox:merge-pdfs doc:name="Apache PDFBox - Merge PDFs" doc:id="otleor" />
<logger doc:name="Logger" doc:id="dulyhd" message='#[%dw 2.0
output text
---
"\n\n Apache PDFBox - Merge PDFs"
++ "\n\n⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄"
++ "\n\nMerge PDFs Attributes: " ++ (write(attributes, "application/json")) as String
++ "\n\n^^^^^^^^^^^^^^^^^^^^"
++ "\n\n Apache PDFBox - Merge PDFs"
++ "\n\n"]'/>
<file:write path="test.pdf" doc:name="Write" doc:id="lfnruk" />
</sub-flow>
</mule>
Example Dataweave for Input Array of Binaries:

%dw 2.0
output application/java
---
[
readUrl("https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf", "application/octet-stream") as Binary,
readUrl("https://pdfobject.com/pdf/pdf_open_parameters_acro8.pdf", "application/octet-stream") as Binary
]
Advised: Add MuleSoftForge Apache PDFBox - Merge pdfs component and make no change

🔍 Notes
Input must contain at least two PDF files, or the operation will throw an error.
The merge order follows the order of the
List<InputStream>
provided — be careful with how your list is constructed.All documents are merged in memory using
RandomAccessReadBuffer
, compatible with PDFBox 3.0.4.If input streams are empty (0 bytes), they will still be processed unless you add a pre-filter.
Ideal for combining invoices, attachments, or generating consolidated output PDFs
Underlying Application Interface:
Last updated