How to embed PDF in Excel using GroupDocs.Merger for .NET
Introduction
Embedding PDF in Excel lets you keep supporting documents—such as contracts, reports, or specifications—right where the data lives. With GroupDocs.Merger for .NET, you can add OLE objects to cells in just a few lines of code, turning a plain spreadsheet into an interactive, self‑contained workbook. This tutorial walks you through everything you need to know, from installation to troubleshooting.
What you’ll learn
- How to set up GroupDocs.Merger for .NET in a C# project
- The exact steps to embed a PDF (or any OLE‑compatible file) into an Excel cell
- Configuration options, performance tips, and common pitfalls
Let’s confirm you have everything ready before we start.
Quick answers
- Can I embed any file type? Yes—any format supported as an OLE object (PDF, Word, image, etc.).
- Do I need a license for development? A free trial works for testing; a permanent license is required for production.
- Which .NET versions are supported? .NET Framework 4.5+, .NET Core 3.1+, .NET 5/6/7+.
- Will the Excel file size increase dramatically? Only by the size of the embedded document; keep files under a few MB for best performance.
- Is there a limit on the number of OLE objects? Practically none, but very large workbooks may affect load time.
What is embed PDF in Excel?
Embedding PDF in Excel inserts the entire PDF as an OLE object that can be opened directly from the spreadsheet. Users click the icon and view the original document without leaving Excel. This approach preserves the original layout, enables quick reference, and eliminates the need to manage separate files. The embedded PDF behaves like any other OLE object, allowing users to double‑click the icon to launch the PDF viewer while staying within the Excel environment.
Why embed OLE objects in Excel?
GroupDocs.Merger supports 120+ input and output formats and can embed objects without loading the whole file into memory, enabling fast processing of multi‑hundred‑page PDFs. This reduces the need for separate file repositories and keeps related data together. It also simplifies version control and ensures that all relevant documentation travels with the workbook, improving collaboration across teams.
Prerequisites
- GroupDocs.Merger for .NET (latest NuGet package)
- .NET Framework 4.5+ or .NET Core/5+/6+
- Visual Studio 2022 or later
- Basic C# knowledge and familiarity with file I/O
Setting up GroupDocs.Merger for .NET
Installation
Add the package using one of the following methods:
.NET CLI
dotnet add package GroupDocs.Merger
Package Manager
Install-Package GroupDocs.Merger
NuGet Package Manager UI
Search for “GroupDocs.Merger” and install the latest version.
License acquisition
- Free trial – test the library without cost.
- Temporary license – request a temporary license on the temporary‑license page.
- Purchase – consider purchasing a license on the GroupDocs purchase page.
Basic initialization
Merger is the entry point for all operations.
using (Merger merger = new Merger("path_to_your_spreadsheet.xlsx"))
{
// Your code to work with the document
}
How to embed OLE objects in Excel?
Load your source workbook, configure the OLE options, and let Merger insert the object. The following sections give you a concise, ready‑to‑run workflow.
Overview of the feature
Embedding OLE objects lets you store a complete PDF inside a cell, preserving the original layout and enabling one‑click access from Excel.
Step‑by‑step implementation
1. Set paths and page number
Specify the spreadsheet, the file to embed, and the target cell address.
string filePath = "YOUR_DOCUMENT_DIRECTORY/SAMPLE_XLSX";
string embeddedFilePath = "YOUR_DOCUMENT_DIRECTORY/SAMPLE_PDF";
int pageNumber = 2; // The specific page to embed
// Output path for the modified spreadsheet
string filePathOut = Path.Combine("YOUR_OUTPUT_DIRECTORY", "OUT_SAMPLE_NAME.xlsx");
2. Configure OleSpreadsheetOptions
OleSpreadsheetOptions defines where the OLE object will be placed in the worksheet and how its icon appears.
// Specify row and column indices for embedding
OleSpreadsheetOptions oleCellsOptions = new OleSpreadsheetOptions(embeddedFilePath, pageNumber)
{
RowIndex = 2,
ColumnIndex = 2
};
3. Initialize Merger and perform embedding
The Merger class handles the actual insertion. After the call, the workbook contains the OLE icon.
using (Merger merger = new Merger(filePath))
{
merger.ImportDocument(oleCellsOptions); // Import the specified document as an OLE object into the spreadsheet
merger.Save(filePathOut); // Save the modified document
}
Common troubleshooting tips
- Verify that all file paths are absolute or correctly resolved relative to the executable.
- Ensure the page number you specify exists in the source PDF; otherwise an exception is thrown.
- If the embedded object does not display, confirm that the target Excel version supports OLE (most modern versions do).
Practical applications
Embedding PDF in Excel is useful for:
- Financial reports – attach audited statements directly beside summary tables.
- Project documentation – keep design specs, risk analyses, or contracts within a master tracker.
- Training dashboards – embed user manuals or policy PDFs for quick reference by staff.
Performance considerations
- File size – keep embedded PDFs under 5 MB to avoid bloating the workbook.
- Memory usage –
GroupDocs.Mergerstreams data, so memory consumption stays low even with large source files. - Dispose objects – always call
Dispose()onMergerinstances to release file handles promptly.
Frequently asked questions
Q: What is an OLE object?
A: An OLE (Object Linking and Embedding) object stores another file (PDF, Word, image, etc.) inside a host document, allowing in‑place editing or opening.
Q: Can I embed OLE objects in other Office formats?
A: Yes—GroupDocs.Merger also supports Word, PowerPoint, and Visio files.
Q: How do I handle password‑protected PDFs?
A: Provide the password when creating the OleSpreadsheetOptions instance; the library will decrypt the file automatically.
Q: Is there a size limitation for embedded PDFs?
A: Technically no hard limit, but files larger than 10 MB may noticeably increase workbook load time.
Q: Where can I find more examples?
A: Visit the official GroupDocs Documentation for additional code samples and API references.
Additional resources
- Documentation: GroupDocs.Merger .NET Docs
- API reference: GroupDocs API Reference
- Downloads: GroupDocs Releases
- License purchase: Buy GroupDocs License
- Free trial: Try GroupDocs Free Trial
- Temporary license: Request Temporary License
- Support forum: GroupDocs Support Forum
Last Updated: 2026-09-21
Tested with: GroupDocs.Merger 23.12 for .NET
Author: GroupDocs