DocumentViewer Class

The ASP.NET component for viewing several formats of documents.

Definition

Namespace: GleamTech.DocumentUltimate.AspNet.UI
Assembly: GleamTech.DocumentUltimate (in GleamTech.DocumentUltimate.dll) Version: 7.0.5
C#
public sealed class DocumentViewer : StatefulComponent<DocumentViewerState>
Inheritance
Object    Component    StatefulComponent    StatefulComponentDocumentViewerState    DocumentViewer

Example

C#
@using GleamTech.AspNet.Mvc
@using GleamTech.DocumentUltimate
@using GleamTech.DocumentUltimate.AspNet
@using GleamTech.DocumentUltimate.AspNet.UI

<!DOCTYPE html>
@{
    var documentViewer = new DocumentViewer
    {
        Width = 800,
        Height = 600,
        Document = "~/Documents/Document.docx"
    };
}
<html>
    <head>
        <title>Document Viewer</title>
        @this.RenderHead(documentViewer)
    </head>
    <body>
        @this.RenderBody(documentViewer)
    </body>
</html>

Note that for ASP.NET Core, you also need to add and register GleamTech in Startup.cs, please see Using DocumentUltimate in an ASP.NET Core project.

Constructors

DocumentViewer Initializes a new instance of the DocumentViewer class.
DocumentViewer(DocumentUltimateWebConfiguration) Initializes a new instance of the DocumentViewer class with custom web configuration.

Properties

AllowedPermissions Gets or sets a value that specifies the allowed permissions for the document viewer. The default is All.

DeniedPermissions take precedence over AllowedPermissions. For instance, when AllowedPermissions is set to All and DeniedPermissions is set to Download and Print, all permissions except Download and Print will be allowed.

When combining permissions, they should be separated by comma in string and by bitwise 'or' operator in code (| in C# and OR in VB).

ClientEventsGets or sets the client-side event handlers.
CursorTool Gets or sets a value that specifies the initial cursor tool in the document viewer. The default is Select.
DebugMode Gets or sets a value indicating whether to display detailed error messages for troubleshooting. Exceptions will be displayed with stack trace, inner exceptions and data.
(Inherited from StatefulComponent)
DeniedPermissions Gets or sets a value that specifies the denied permissions for the document viewer. The default is None.

DeniedPermissions take precedence over AllowedPermissions. For instance, when AllowedPermissions is set to All and DeniedPermissions is set to Download and Print, all permissions except Download and Print will be allowed.

When combining permissions, they should be separated by comma in string and by bitwise 'or' operator in code (| in C# and OR in VB).

DisplayLanguage Gets or sets the display (user interface) language of the document viewer.

It is usually set as the two-letter language names like en, de, fr etc. as the bundled languages are usually for general language names. However, it can be also set to specific cultures like en-US, de-DE, fr-FR etc. For example, if the property is set to a specific culture like de-CH (German in Switzerland), the component will first look for the language file translation-de-CH.json and if the file is not found, it will load the general (fallback) language file of that culture which is translation-de.json. If not set, the language file which matches the current UICulture of the host application will be loaded. If there is no language file which matches the current UICulture or its fallback, then the default language file translation-en.json is loaded.

DisplayModeGets or sets a value indicating whether the component is rendered as InPlace (default), Panel, Window or Viewport.
(Inherited from Component)
Document Gets or sets the document to load and display in the document viewer.

This property can be set to:

  • A plain string which contains a physical/virtual path
    (e.g. "c:\SomeFolder\SomeFile.ext", "/SomeFolder/SomeFile.ext", "~/SomeFolder/SomeFile.ext").

    This is parsed as a FileSystemFileProvider instance with a PhysicalLocation instance. Note that virtual paths can only be resolved in a web application.
    and on Linux paths starting with "/" are physical paths and not virtual paths.

  • A plain string which contains a URL or a Data URL.
    (e.g. "http://example.com/SomeFolder/SomeFile.ext", "data:image/gif;base64,...").

    Strings starting with http:// or https:// are parsed as a UrlFileProvider instance.
    Strings starting with data: are parsed as a DataUrlFileProvider instance.

  • A FileProvider instance created with one of the builtin file providers
    (e.g. FileSystemFileProvider, UrlFileProvider, DataUrlFileProvider, StreamFileProvider, MemoryFileProvider, DatabaseFileProvider, AssemblyResourceFileProvider, TemporaryFileProvider).

    You can also override FileProvider base class to implement your custom file provider.

  • A provider string which defines a specific file provider
    (e.g. "Type=FileSystem; File=SomeFile.ext; Location='Type=Physical; Path=c:\SomeFolder'").

The document viewer only needs a readable file provider as it only calls GetInfo and OpenRead.

DocumentOptions Gets or sets the options for the document loaded in the document viewer.

You can specify document format, password, watermarks, attachments etc.

FormatLanguage Gets or sets the format language of the document viewer.

Format language is used for the number and date/time formats. It is usually set as the specific cultures like en-US, de-DE, fr-FR etc. If not set, the current Culture of the host application will be used.

HeightGets or sets the height of the component.
(Inherited from Component)
Hidden Gets or sets a value indicating whether the component is displayed when page is loaded. When set to false, the component can be displayed later on client-side manually. For example, the component can be displayed via a button's click event.
(Inherited from Component)
Id Gets or sets the HTML id of the component. Also a javascript variable with the same name is automatically defined and it can be used to access the client-side implementation of the component. If omitted, Id will be automatically set to the class name of this component (e.g camel-case className) and if there are other instances on the same page, to className2 ... classNameX.
(Inherited from Component)
LoadingMessage Gets or sets a value that specifies the message displayed while the document is being prepared for the first-time viewing. For example, you can override the default message for localization purpose.
Obsolete.
MobileMode Gets or sets a value that specifies on which mobile device type to use large UI sizing for the document viewer.

Note that device features are not detected, instead browser's viewport size is used to decide the UI sizing. So if you manually resize the browser window (or emulate a device via browser's F12 dev tools), phone or tablet size can be triggered.

The default is OnAny which means phones and tablets.

PageFitMode Gets or sets a value that specifies the initial mode for fitting pages in the document viewer. The default is FitWidth.
Obsolete.
PageLayoutMode Gets or sets a value that specifies the initial mode for placing pages in the document viewer. The default is Continuous.
Obsolete.
PageRotationMode Gets or sets a value that specifies whether rotate buttons should only rotate all pages or only the currently viewed page. The default is AllPages.
Obsolete.
PageZoomLevel Gets or sets a value in percentage that specifies the initial zoom level in the document viewer. The default is 100.

For this property to be effective PageFitMode property should be set to Zoom.


Obsolete.
PanelOptionsGets or sets the panel options used for Panel mode.
(Inherited from Component)
PrintOptions Gets or sets the print options of the document viewer.

The options will be reflected as default values on the print dialog of the document viewer.

ProductInfoRenderedGets or sets a value indicating whether product info/copyright comment is rendered in html.
(Inherited from Component)
Resizable Gets or sets a value that specifies if the component can be resized when the user drags sides.
(Inherited from Component)
ResizeHandles Gets or sets a value that specifies the handles which can be used for resizing the component. Default is South, East and SouthEast. When using Window mode, set ResizeHandles which overrides this property.
(Inherited from Component)
RotationMode Gets or sets a value that specifies whether rotate buttons should only rotate all pages or only the currently viewed page. The default is AllPages.
ScrollMode Gets or sets a value that specifies the initial mode for scrolling pages in the document viewer. The default is History.
SearchOptions Gets or sets the text search options of the document viewer.

If you specify a search term, an automatic search will be done when the document is displayed, i.e. the specified term will be searched and results with clickable positions will be listed on the left pane and the term will be highlighted in the pages. For example, if you launch the document viewer from a search results page, you can pass the same search term to the document viewer.

SidebarView Gets or sets a value that specifies the initial active view in sidebar of the document viewer. The default is History.
SidebarVisible Gets or sets a value that specifies whether the left sidebar is visible. The default is true.
SidePaneTabsAtBottom Gets or sets a value that specifies whether the top tabs of the left side pane should be placed at the bottom instead. The default is false.
Obsolete.
SidePaneVisible Gets or sets a value that specifies whether the left side pane is visible. The default is true.
Obsolete.
SpreadMode Gets or sets a value that specifies the initial mode for spreading pages in the document viewer. The default is History.
StateId Gets or sets the state id of the component. This is determined automatically when state is saved to session.
(Inherited from StatefulComponent)
Theme Gets or sets the theme to use for the document viewer.

Possible values are "slate", "classic-light", "classic-dark" or the CSS class name of a custom theme. When two values separated by comma is set, the second value will be the dark theme. Dark theme is used when a user indicates their preference through an operating system setting (e.g. light or dark mode) or a user agent setting. When single value is provided, dark theme is disabled, i.e. the only provided theme will be used always even when user prefers dark mode.

The default is "slate, classic-dark".

ToolbarAtBottom Gets or sets a value that specifies whether the top toolbar should be placed at the bottom instead. The default is false.
ToolbarVisible Gets or sets a value that specifies whether the top toolbar is visible. The default is true.
Translations Gets or sets a value that specifies the custom translations for the document viewer.

The document viewer has about 111 language files, however for some few custom text which are not inside those language files, this property is used to override. For example, you can override the default "preparing document..." message for localization purpose.

VerticalToolbarVisible Gets or sets a value that specifies whether the right vertical toolbar is visible. The default is true.
WidthGets or sets the width of the component.
(Inherited from Component)
WindowOptionsGets or sets the windows options used for Window mode.
(Inherited from Component)
ZoomLevel Gets or sets a value in percentage that specifies the initial zoom level in the document viewer. The default is unset (zero) which means ZoomMode will be used instead.
ZoomMode Gets or sets a value that specifies the initial mode for zooming pages in the document viewer. The default is History.

Note that if a custom zoom level is set via ZoomLevel property then it will override this setting.

See Also