ViewerConfig

Client viewer widget options

ViewerConfig (namespace Doconut) describes the browser viewer's appearance and behavior. It does not affect document rendering quality; use a format config for that. The C# class and the long-standing JavaScript widget have different defaults, so map values explicitly.

Two client-side changes in this release fail silently. Handler functions are passed as options — the widget no longer derives global function names from the container id — and ResPath must point at the resources prefix rather than the application root. Both leave the server working perfectly and report nothing in the browser console. If you are carrying a page forward from the previous library, read Callbacks and Path checklist before anything else.

C# properties

TypePropertyDefaultDescription
boolShowThumbstrueShow the thumbnail panel.
boolAutoLoadfalseAutomatically load after initialization. The normal token flow calls View(token) explicitly.
boolAutoFocustrueMove browser focus/scroll to the viewer during initialization.
boolAutoPageFocustrueKeep the current thumbnail visible while pages change.
intPageZoom100Initial zoom percentage.
intZoomStep10Percentage added or removed by zoom commands.
intMaxZoom300Maximum zoom percentage.
boolShowToolTiptrueShow the page-position tooltip while scrolling.
stringToolTipPageText"Page "Prefix used in the page tooltip.
boolCacheEnabledfalseRetain a moving window of page images in browser memory. It does not use localStorage.
boolLargeDocfalseAppend page elements in timed batches for large documents.
boolShowHyperlinksfalseRender hyperlink overlays when the server config extracted them.
boolFixedZoomtrueUse a fixed zoom percentage rather than responsive recalculation.
intFixedZoomPercent100Fixed desktop zoom.
intFixedZoomPercentMobile75Fixed mobile zoom.
stringBasePath"/"Branch where the host maps UseDoconut().
stringResPath"doconut-res"Resource base used by the widget. In a normal setup point it to <ResourcesPath>/images.
stringFitType"width""width", "height", or empty for no automatic fit. "page" is not accepted by the current widget.
boolRetryOn409falseEnable polling when asynchronous/distributed page production responds 202 Accepted; 409 is also accepted for compatibility with older servers. Not needed by the normal synchronous viewer.
csharp
var config = new ViewerConfig
{
    ShowThumbs = true,
    AutoLoad = false,
    PageZoom = 100,
    MaxZoom = 300,
    FitType = "width",
    BasePath = "/doconut",
    ResPath = "/doconut-res/images",
    ShowHyperlinks = true
};

C# to JavaScript mapping

Do not pass a directly serialized ViewerConfig to docViewer(...). Most widget keys are camelCase, while three established path/fit keys are PascalCase.

C#JavaScript
ShowThumbsshowThumbs
AutoLoadautoLoad
AutoFocusautoFocus
AutoPageFocusautoPageFocus
PageZoompageZoom
ZoomStepzoomStep
MaxZoommaxZoom
ShowToolTipshowToolTip
ToolTipPageTexttoolTipPageText
CacheEnabledcacheEnabled
LargeDoclargeDoc
ShowHyperlinksshowHyperlinks
FixedZoomfixedZoom
FixedZoomPercentfixedZoomPercent
FixedZoomPercentMobilefixedZoomPercentMobile
BasePathBasePath
ResPathResPath
FitTypeFitType
RetryOn409retryOn409

JavaScript defaults

The widget has older defaults that differ from the C# class. The following values come from the current docViewer.js implementation.

OptionDefaultNotes
leftMinWidth / leftMaxWidth220 / 800Thumbnail pane width bounds.
showThumbstrueInitial thumbnail visibility.
autoFocus / autoPageFocustrue / falseautoPageFocus differs from the C# default.
thumbWidth / thumbHeight / thumbPadding150 / 200 / 10Thumbnail geometry in pixels.
pageZoom / zoomStep / maxZoom100 / 10 / 200JavaScript maxZoom differs from C# (300).
showToolTip / toolTipPageTexttrue / "Page "Page-position tooltip.
format / doc / AccessToken"" / 0 / ""Internal initialization values; normally populated by View(token).
debugModefalseAdditional client diagnostics.
FitType""No automatic fit unless supplied.
BasePath"DocImage.axd"Historical client default retained for compatibility. Current ASP.NET Core hosts must set it explicitly to the mapped middleware branch.
ResPath""Set explicitly to the embedded images path.
cacheEnabled / cacheCount / cacheDelayfalse / 3 / 3In-memory page preloading window and delay.
autoLoadfalseExplicit token flow is recommended.
largeDoctrueDiffers from the C# default.
fixedZoomfalseDiffers from the C# default.
fixedZoomPercent / fixedZoomPercentMobile100 / 50Mobile value differs from C# (75).
showHyperlinkstrueRequires server-side extraction to produce overlays.

Set all behaviorally important values instead of relying on either set of defaults:

html
<div id="divDocViewer"><div id="div_ctlDoc"></div></div>

<script>
const objViewer = $('#div_ctlDoc').docViewer({
    showThumbs: true,
    autoLoad: false,
    autoFocus: true,
    autoPageFocus: true,
    pageZoom: 100,
    zoomStep: 10,
    maxZoom: 300,
    FitType: 'width',
    cacheEnabled: false,
    largeDoc: false,
    showHyperlinks: true,
    fixedZoom: true,
    fixedZoomPercent: 100,
    fixedZoomPercentMobile: 75,
    BasePath: '/doconut',
    ResPath: '/doconut-res/images',
    onViewerReady: function () {},
    onError: function (message) { console.error('DocViewer:', message); }
});
</script>

Callbacks

CallbackArgumentsPurpose
onPageLoadingpageNumA page request is starting.
onPageLoadedpageNumA page image finished loading.
onThumbnailClickedpageNumThe user selected a thumbnail.
onPageClickedpageNumThe user selected a page.
onDoubleClicknoneThe viewer received a double-click.
onViewerBusynoneThe viewer entered a busy state.
onViewerReadynoneInitialization completed.
onViewerErrornoneThe viewer entered its error state.
onErrormessageAn operation returned an error message.
onCopydataText-copy data is available.
onAutoLoadStatuspageNumAuto-loading progressed to a page.
onThumbsShownnoneThe thumbnail panel became visible.
onAnnLoadednoneAnnotation data loaded.
onAnnSavednoneAnnotation data saved.
onAnnSaveErrornoneAnnotation saving failed.
onAnnClosednoneAnnotation UI closed.

Keep callbacks fast; send telemetry asynchronously and do not block page rendering.

Every one of these is an option on the init object. The previous viewer looked up global functions whose names it derived from the container id — a page with <div id="div_ctlDoc"> only had to declare function ctlDoc_OnViewerReady(). That lookup is gone. Pass the function explicitly:

javascript
objctlDoc = $('#div_ctlDoc').docViewer({
    // ... your existing options ...
    onViewerBusy:     ctlDoc_OnViewerBusy,      // was found by name
    onViewerReady:    ctlDoc_OnViewerReady,     // was found by name
    onCopy:           ctlDoc_Copy,              // was ctlDoc_Copy(text)
    onAutoLoadStatus: ctlDoc_AutoLoadStatus     // was ctlDoc_AutoLoadStatus(page)
});

The old lookup was wrapped in an empty catch, so nothing was ever reported. On this release the functions simply never run: the usual symptom is a busy spinner that never stops, because the handler that hid it was onViewerReady. The document behind it is rendering correctly.

There is no link-click callback — hyperlink handling is built in and driven by showHyperlinks.

Public method groups

GroupCommon methods
LifecycleView(token, accessToken?), Close(server?), Token(), Init(), IsLoaded()
NavigationGotoPage(page), ShowPage(page, focus?), Next(next), CurrentPage(), TotalPages()
Zoom and fitZoom(zoomIn), CurrentZoom(), FitType(value), Refit()
OrientationRotate(page, angle), Flip(page, flipType)
ThumbnailsHideThumbs(hide), ThumbSize(size), ReloadThumbs(width), ScrollToThumb(thumb)
SearchCanSearch(), Search(...), SearchMatchCount(), SearchSummary(...), GotoSearchMatch(...)
AnnotationSaveAnnotations(), GetAnnotations(), PushAnnotations(...), CloseAnnotations(...), ShowAnnotations(...)
CopyCopy(...), CopyPage(pageNumber), CopyMode(enabled)

The JavaScript file contains internal helpers too. Treat only methods used by the reference UI and documented here or in the feature guides as stable integration points.

Retry while a distributed page is still rendering

retryOn409 retains its historical name. It is for asynchronous page production and retries the current 202 Accepted readiness response as well as the older 409 Conflict signal. When enabled, the widget polls with these JavaScript defaults:

OptionDefault
retryInitialDelayMs250
retryBackoffFactor1.6
retryMaxDelayMs2500
retryMaxAttempts60
retryMaxTotalMs120000

Leave it disabled for the normal single-node viewer. Enabling it cannot make an unsupported synchronous render asynchronous.

Enable it when pages are served from shared storage with FirstPagePriority, where later pages legitimately answer 202 Accepted until they are written. A client that does not retry shows broken tiles for pages still rendering — see Distributed Deployments.

Path checklist

  • DoconutOptions.MiddlewarePath must describe the branch you actually map.
  • BasePath must target that branch. The reference application keeps the historic DocImage.axd request shape on a MapWhen branch and therefore sets BasePath: '/'.
  • DoconutOptions.ResourcesPath is the embedded resource route.
  • ResPath normally targets its /images subfolder — 'doconut-res/images' with the default prefix. An empty ResPath was correct in the previous library, where resources came from the application root; it is not correct here, and it fails without an error.
  • ExtractHyperlinks must be enabled in the server format config before showHyperlinks can display anything.

หน้านี้เป็นประโยชน์หรือไม่?