New to Telerik Document ProcessingStart a free 30-day trial

Merge PDF files while preserving their annotations

Updated on Jun 9, 2026

Environment

Product VersionProductAuthor
2023.2.713PdfProcessingYoan Karamanov

Description

This article shows how to merge PDF documents without loss of supported annotations by using 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.

Example 1: 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;
	}

See Also