# Copying Images from RadFixedDocument to Windows Clipboard

## Environment

| Version    | Product          | Author                                                                |
| ---------- | ---------------- | --------------------------------------------------------------------- |
| 2026.1.304 | RadPdfProcessing | [Yoan Karamanov](https://www.telerik.com/blogs/author/yoan-karamanov) |

## Description

How to extract multiple images from a [`RadFixedDocument`](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/radfixeddocument) and copy them to the Windows clipboard in a format that allows pasting into MS Word or other applications. The goal is to paste all images at once into MS Word as a single clipboard instance.

This KB article also answers the following questions:

* How do I copy all images from a PDF to the clipboard?
* How do I paste multiple images from a clipboard into MS Word?
* How do I convert images in a `RadFixedDocument` to HTML format for clipboard use?

## Solution

To copy images from a [`RadFixedDocument`](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/radfixeddocument) to the clipboard and paste them into MS Word, follow these steps:

1. Extract all images from the document pages.
2. Convert each image to PNG format and embed it in an HTML fragment as Base64 data URIs.
3. Set both HTML and bitmap formats on the clipboard.

The following code snippet demonstrates the implementation:

```csharp
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
using Telerik.Windows.Documents.Fixed.Model;
using Telerik.Windows.Documents.Fixed.Model.Objects;

[STAThread]
static void Main(string[] args)
{
    string pdfFilePath = "PDF with images.pdf";

    PdfFormatProvider pdfProvider = new PdfFormatProvider();
    RadFixedDocument document;

    using (FileStream stream = File.OpenRead(pdfFilePath))
    {
        document = pdfProvider.Import(stream, null);
    }

    var data = new DataObject();
    var bitmapSources = new List<BitmapSource>();

    foreach (RadFixedPage page in document.Pages)
    {
        var images = page.Content.Where(e => e is Image)
                                 .Cast<Image>();

        foreach (var image in images)
        {
            ImageSource imageSource = image.ImageSource;
            var bitmapSource = imageSource.GetBitmapSource();
            bitmapSources.Add(bitmapSource);
        }
    }

    string htmlFragment = CreateHtmlFragmentWithImages(bitmapSources);
    data.SetData(DataFormats.Html, htmlFragment);

    if (bitmapSources.Count > 0)
    {
        data.SetImage(bitmapSources[0]);
    }

    Clipboard.SetDataObject(data, true);
}

static string CreateHtmlFragmentWithImages(List<BitmapSource> images)
{
    var html = new System.Text.StringBuilder();
    html.AppendLine("<html><body>");

    foreach (var bitmapSource in images)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            PngBitmapEncoder encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
            encoder.Save(ms);

            string base64 = Convert.ToBase64String(ms.ToArray());
            html.AppendLine($"<img src=\"data:image/png;base64,{base64}\" /><br/>");
        }
    }

    html.AppendLine("</body></html>");
    return CreateHtmlFormat(html.ToString());
}

static string CreateHtmlFormat(string html)
{
    string header = "Version:0.9\r\nStartHTML:{0:000000}\r\nEndHTML:{1:000000}\r\nStartFragment:{2:000000}\r\nEndFragment:{3:000000}\r\n";
    string startFragment = "";
    string endFragment = "";

    string htmlFragment = startFragment + html + endFragment;
    int startHTML = header.Length;
    int endHTML = startHTML + htmlFragment.Length;
    int startFragment_idx = startHTML + htmlFragment.IndexOf(startFragment);
    int endFragment_idx = startHTML + htmlFragment.IndexOf(endFragment);

    return string.Format(header, startHTML, endHTML, startFragment_idx, endFragment_idx) + htmlFragment;
}
```

**Notes:**

* The HTML format allows the clipboard to hold multiple images as Base64 data URIs.
* Applications that support HTML clipboard format, such as MS Word, paste all images simultaneously.
* The [`GetBitmapSource`](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/imagesource#methods) method extracts images from the PDF.

## See Also

* [RadFixedDocument](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/radfixeddocument)
* [RadFixedPage](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/radfixedpage)
* [ImageSource](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/imagesource)
* [Image](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/image)
