New to Telerik Document ProcessingStart a free 30-day trial

Merge PDF files while preserving their annotations

Updated on Feb 19, 2026
Product VersionProductAuthor
2023.2.713PdfProcessingYoan Karamanov

Description

This article describes how to merge PDF documents without loss of supported annotations with the help of the PdfStreamWriter and PdfFileSource.

Solution

The following approach takes a collection of paths, creates a new RadFixedDocument instance, appends the documents from those paths to the newly created RadFixedDocument and returns it as a result.

__Merge PDF files

csharp

    public static RadFixedDocument MergeDocuments(string[] pathsCollection)
	{
	RadFixedDocument resultFile;
	Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider pdfFormatProvider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
 
	using (MemoryStream stream = new MemoryStream())
	{
		using (PdfStreamWriter fileWriter = new PdfStreamWriter(stream, leaveStreamOpen: true))
		{
			foreach (string path in pathsCollection)
			{
				using (PdfFileSource fileSource = new PdfFileSource(new MemoryStream(File.ReadAllBytes(path))))
				{
					for (int i = 0; i < fileSource.Pages.Length; i++)
					{
						PdfPageSource sourcePage = fileSource.Pages[i];
						using (PdfPageStreamWriter resultPage = fileWriter.BeginPage(sourcePage.Size))
						{
							// set content                     
							resultPage.WriteContent(sourcePage);
						}
					}
				}
			}
		}
  		resultFile = pdfFormatProvider.Import(stream);
	}

	return resultFile;
	}
In this article
DescriptionSolution
Not finding the help you need?
Contact Support