New to Telerik ReportingStart a free 30-day trial

Select Page of TIFF Image

Environment

ProductProgress® Telerik® Reporting

Description

By default, the PictureBox report item will render the first page of the TIFF image file. This can be a problem when a multipage TIFF file is used as there would be no way to display any of the other pages.

Solution

In order to render a certain page from the TIFF file, a custom user function that selects that image is required. The function may look as bellow:

CSharp
public static Image GetPageFromTiff(string path, int page)
{
	Image tiffImage;
	List<Image> images;

	tiffImage = Image.FromFile(path);
	images = GetAllPages(tiffImage);

	return images[page];
}

private static List<Image> GetAllPages(Image multiPageImage)
{
	List<Image> images = new List<Image>();
	int count = multiPageImage.GetFrameCount(FrameDimension.Page);
	for (int i = 0; i < count; i++)
	{
		multiPageImage.SelectActiveFrame(FrameDimension.Page, i);
		MemoryStream byteStream = new MemoryStream();
		multiPageImage.Save(byteStream, ImageFormat.Tiff);
		images.Add(Image.FromStream(byteStream));
		byteStream.Dispose();
	}
	return images;
}

Then, in the Report Designer, to call the function we need to provide a path to the TIFF image and the desired page to be displayed, for example:

= Namespace.Class.GetPageFromTiff("c:\temp\test.tif", 1)

The indexing is 0-based so when we give a 1 as the second argument, the second page's image will be rendered.

See Also