Generate document preview

If you need to implement a UI for your application it can be useful to generate image previews for a document the users are going to work with. Such previews can be easily displayed on a web page or in an appropriate component of a desktop/mobile application. The code sample below demonstrates how to generate image previews for certain document pages.

Here are the steps to generate a document preview for a particular page:

  1. Load a document to preview
  2. Specify a delegate that will be used to create the page streams (please see the CreatePageStream delegate for more information)
  3. Specify the page numbers
  4. Generate previews for desired pages using the GeneratePreview method of the Metadata class

BasicUsage.GenerateFilePreview

using (Metadata metadata = new Metadata(Constants.InputDocx))
{
	PreviewOptions previewOptions = new PreviewOptions(pageNumber => File.Create($"{Constants.OutputPath}\\result_{pageNumber}.png"));
	previewOptions.PreviewFormat = PreviewOptions.PreviewFormats.PNG;
	previewOptions.PageNumbers = new int[] { 1 };
	metadata.GeneratePreview(previewOptions);
}

More resources

Advanced usage topics

To learn more about document watermarking features and get familiar how to manage watermarks and more, please refer to the advanced usage section.

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document metadata management App

Along with full featured .NET library we provide simple, but powerful free Apps. You are welcome to view and edit metadata of PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, emails, images and more with our free online Free Online Document Metadata Viewing and Editing App.