Document preview

GroupDocs.Watermark library equipped with the capability to generate preview images for every page of your documents, simplifying your workflow and enhancing efficiency. With this feature, users can effortlessly preview their documents with a glance, enabling swift navigation and ensuring seamless accessibility to crucial content.

Generate document preview

To create document preview:

  1. Create an instance of the Watermarker class for a local file or file stream;

  2. Instantiate the PreviewOptions object with the delegate for stream creation (see event handler CreatePageStream); If you need to implement custom image preview stream disposing you have to pass additional argument ReleasePageStream to clean up resources.

  3. Specify PreviewFormat - PNG / JPG / BMP, and other properties like PageNumbers for which you want to generate preview. Additionaly for most of documents you can use specific PreviewOptions overloads, like PdfPreviewOptions, SpreadsheetPreviewOptions which allows to configure the resolution for the generated images in dots per inch.

  4. Call method GeneratePreview method of the Watermarker object and pass PreviewOptions to it.

string documentPath = Constants.InDocumentPdf;
string outputDirectory = Constants.GetOutputDirectoryPath();

using (Watermarker watermarker = new Watermarker(documentPath))
    CreatePageStream createPageStreamDelegate = delegate(int number)
        string previewImageFileName = Path.Combine(outputDirectory, string.Format("page{0}.png", number));
        return File.OpenWrite(previewImageFileName);

    ReleasePageStream releasePageStreamDelegate = delegate(int number, Stream stream)

    PreviewOptions previewOptions = new PreviewOptions(createPageStreamDelegate, releasePageStreamDelegate)
        PreviewFormat = PreviewOptions.PreviewFormats.PNG,
        PageNumbers = new []{1, 2}

Run the program. It will create images in the outputDirectory corresponding to the pages of the document.