Export RadFixedPage to image

Product Version Product Author
2020.1.310 RadPdfProcessing Martin Velikov
2020.1.309 RadPdfViewer

Description

How to export RadFixedPage to TIFF file.

Solution

To achieve this we can use the RadPdfViewer control form the UI for WPF suite to create images from the RadFixedDocument pages using the ThumbnailFactory class.

byte[] data = GetDocumentData(); 
 
RadPdfViewer pdfViewer = new RadPdfViewer(); 
 
PdfFormatProvider provider = new PdfFormatProvider(new MemoryStream(data), FormatProviderSettings.ReadAllAtOnce); 
pdfViewer.Document = provider.Import(); 
 
int pageNumber = 0; 
RadFixedPage page = pdfViewer.Document.Pages[pageNumber]; 
 
ThumbnailFactory factory = new ThumbnailFactory(); 
 
ImageSource imageSource = factory.CreateThumbnail(page, page.Size); 
 
Image image = new Image(); 
image.Source = imageSource; 
 
Grid container = new Grid(); 
container.Background = Brushes.White; 
container.Children.Add(image); 
container.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); 
container.Arrange(new Rect(new Point(0, 0), container.DesiredSize)); 
 
RenderTargetBitmap bitmap = new RenderTargetBitmap((int)PageLayoutHelper.GetActualWidth(page), (int)PageLayoutHelper.GetActualHeight(page), 96, 96, PixelFormats.Pbgra32); 
bitmap.Render(container); 
 
string exportedFileName = "Exported.tiff"; 
using (FileStream fileStream = new FileStream(exportedFileName, FileMode.Create)) 
{ 
    BitmapEncoder encoder = new TiffBitmapEncoder(); 
    encoder.Frames.Add(BitmapFrame.Create(bitmap)); 
    encoder.Save(fileStream); 
} 
In this article
Not finding the help you need? Improve this article