PreviewOptions

PreviewOptions class

Provides options to sets requirements and stream delegates for preview generation.

public class PreviewOptions

Constructors

Name Description
PreviewOptions(CreatePageStream) Initializes a new instance of PreviewOptions class, causing the output stream to be closed.
PreviewOptions(CreatePageStream, ReleasePageStream) Initializes a new instance of PreviewOptions class, causing the output stream to be returned to the client for further use.

Properties

Name Description
CreatePageStream { get; set; } Gets or sets an instance of page stream creation delegate.
Height { get; set; } Gets or sets page preview height.
PageNumbers { get; set; } Gets or sets an array of page numbers to generate preview.
PreviewFormat { get; set; } Gets or sets preview image format.
ReleasePageStream { get; set; } Gets or sets an instance of page preview completion delegate.
Width { get; set; } Gets or sets page preview width.

Examples

The following example demonstrates how get a document preview using PreviewOptions and CreatePageStream delegate.

    CreatePageStream createDelegate = delegate (int pageNumber)
    {
        var pagePath = System.IO.Path.Combine(@"C:\Temp", string.Format("page_{0}.png", pageNumber));
        return System.IO.File.Create(pagePath);
    };
    var previewOptions = new PreviewOptions(createDelegate);
    previewOptions.PreviewFormat = PreviewOptions.PreviewFormats.PNG;
    previewOptions.Height = 640;
    previewOptions.Width = 480;
    previewOptions.PageNumbers = new int[] { 1 };
    using (var redactor = new Redactor("C:\Temp\SourceFile.pdf"))
    {
        redactor.GeneratePreview(previewOptions);
    }

The following example demonstrates how get a document preview using PreviewOptions and both delegates.

    CreatePageStream createDelegate = delegate (int pageNumber)
    {
        var pagePath = System.IO.Path.Combine(@"C:\Temp", string.Format("page_{0}.png", pageNumber));
        return System.IO.File.Create(pagePath);
    };
    ReleasePageStream releaseDelegate = delegate (int pageNumber, System.IO.Stream pageStream)
    {
        // do anything with Stream, containing page preview
        pageStream.Close();
    };
    var previewOptions = new PreviewOptions(createDelegate, releaseDelegate);
    previewOptions.PreviewFormat = PreviewOptions.PreviewFormats.PNG;
    previewOptions.Height = 640;
    previewOptions.Width = 480;
    previewOptions.PageNumbers = new int[] { 1 };
    using (var redactor = new Redactor("C:\Temp\SourceFile.pdf"))
    {
        redactor.GeneratePreview(previewOptions);
    }

See Also