Merge and Split PDF, Word and PowerPoint Files in One Line of C#
Merge and Split PDF, Word and PowerPoint Files in One Line of C#
Leave feedback
On this page
GroupDocs.Merger exposes a
general-purpose Merger class for complex, multi-format jobs, and ships a separate
GroupDocs.Merger.LowCode package for everything smaller than that. Single-purpose
document assembly is a GroupDocs.Merger capability for .NET that hands each merge,
split or page-removal job to its own LowCode product, through JoinPdf, JoinDocx,
JoinPptx, SplitPdf, SplitDocx, SplitPptx and RemovePagesPdf.
A developer who needs one document operation, not a document-processing platform,
usually ends up reading more of the general Merger API than the task requires.
GroupDocs.Merger.LowCode packages seven of those single operations as their own types,
each covering its job end to end. This guide walks through five of them in six
methods against the GroupDocs.Merger 26.10 sample and the five files it ships with:
report.pdf, appendix.pdf, contract.docx, amendment.docx and deck.pptx. Each
method follows the same two steps: build the product with its source and options,
then call Save to run it.
What you’ll learn:
Joining PDF files with JoinPdf and Word documents with JoinDocx
Splitting PDF pages with SplitPdf and PowerPoint slides with SplitPptx
Removing PDF pages with RemovePagesPdf without touching the source file
What a mismatched input raises, and what changes without a license
Program.cs holds the six methods below; resources/ holds the five files they
operate on.
Method 1: Joining Two PDF Files
Format: PDF | Product:JoinPdf | Best For: appending a cover page or an
appendix to a report before archiving it
JoinPdf takes the source PDF, the files to append, and a JoinOptions instance in
its constructor. Every file passed in must already be a PDF, or the call throws
FileTypeNotSupportedException instead of writing anything; Save creates the output
folder if it does not already exist.
In our own run, joining the sample’s 2-page report.pdf with its 2-page
appendix.pdf produced a 4-page, 257987-byte report-with-appendix.pdf.
Method 2: Joining Two Word Documents
Format: DOCX | Product:JoinDocx | Best For: appending a signed
amendment to a contract
JoinDocx follows the exact constructor-then-Save shape as JoinPdf, for Word
files: the appended document lands after the last page of the source document.
In our own run, joining the 6-page contract.docx with the 1-page amendment.docx
produced a 7-page, 7915-byte contract-with-amendment.docx.
Method 3: Splitting PDF Pages
Format: PDF | Product:SplitPdf | Best For: pulling named pages out of a
report into files of their own
SplitPdf takes the source PDF and the page numbers to extract; Save writes one
file per requested page. A {0} token in the output name becomes the part number, so
report-page_{0}.pdf yields report-page_1.pdf and report-page_2.pdf; without it,
the number is appended instead.
Splitting pages 1 and 2 of report.pdf in our sample run produced report-page_1.pdf
and report-page_2.pdf, each a single page.
Method 4: Splitting PowerPoint Slides
Format: PPTX | Product:SplitPptx | Best For: sending two slides from a
sixty-slide deck to one stakeholder
SplitPptx mirrors SplitPdf for presentation decks. Without a {0} token, the part
number is appended instead, so deck-slide.pptx becomes deck-slide_1.pptx and
deck-slide_2.pptx.
Removing page 2 from report.pdf in our own run produced a 1-page, 86647-byte
report-without-page-2.pdf, while report.pdf itself stayed unchanged.
Method 6: Catching a Mismatched Join Before It Writes Anything
Format: any | Product:JoinPdf (the same check applies to every join
product) | Best For: validating unattended input before it reaches an archive
Every LowCode product checks its source and every file it is given against its own
format before writing anything. Wrap the join in a try/catch for
FileTypeNotSupportedException whenever the inputs are not guaranteed to be right.
In the sample run, where the paths are built from its resources folder, the message
read: Input format does not match the expected format 'PDF'; the joined file 'resources\contract.docx' is 'Microsoft Word Open XML Document (.docx)'. Nothing is
written to outputPath when the check fails. The exception stops only the one call it
came from; a batch of several joins still needs its own loop and its own
try/catch per item.
Choosing the Right Method
Method
Product
Operation
Format
Method 1
JoinPdf
Append a PDF to a PDF
PDF
Method 2
JoinDocx
Append a Word document to a Word document
DOCX
Method 3
SplitPdf
Extract chosen pages into files of their own
PDF
Method 4
SplitPptx
Extract chosen slides into files of their own
PPTX
Method 5
RemovePagesPdf
Drop chosen pages, leaving the source untouched
PDF
Method 6
JoinPdf
Reject a format mismatch before writing anything
any
Licensing and Evaluation Mode
A static License.Set(licensePath) call applies a metered license file or a standard
.lic file for the LowCode products. Without one, the products run in
evaluation mode: in our own unlicensed run, the joined outputs from Methods 1 and 2
were cut to 3 pages each, while all six method calls still produced output.
Frequently Asked Questions
Does GroupDocs.Merger.LowCode replace the full GroupDocs.Merger API?
No. See “Why GroupDocs.Merger.LowCode Isn’t the Full Merger Class” above for what
stays in the full API.
What happens if I run the sample without a license?
Evaluation limits apply to every GroupDocs.Merger.LowCode product once License.Set
is skipped. In our own unlicensed run, the joined PDF and Word outputs from Methods 1
and 2 were cut down to 3 pages each, shorter than their licensed results of 4 and 7
pages, while every one of the six method calls above still produced an output file.
Applying a license with License.Set removes that limit entirely.
Can I pass a stream instead of a file path?
Yes, in the same constructor position a file path would take; this guide uses file
paths throughout for clarity.
What does the {0} token in an output name do?
When present, it is replaced with the part number, as Methods 3 and 4 show. When
absent, the part number is appended to the base name instead.
Summary and When to Use Which Method
All six methods share one shape: build the product with its source and options, then
call Save. Use Method 1 or 2 to append one document to another of the same format,
Method 3 or 4 to split chosen pages or slides into files of their own, Method 5 to
drop pages without touching the source, and Method 6 to validate a join’s inputs
before anything gets written. Stay with LowCode while a job is one well-defined
operation, and move up to the full GroupDocs.Merger API once it needs a cross-format
join, a page-level join option, an output stream or document information.