Customizing the Client Preview
Example: Add additional viewers
This code can be used until version 8.16 LTS.
"preview": { "fileSizeLimit": 10485760, "viewers": [ { "mimeType": ["audio/mp3", "video/mp4"], "fileExtension": ["mp3", "mp4"], "viewer": "assets/video/index.html?file=${path}#lang=${lang}" } ] },
"preview": { "fileSizeLimit": 10485760, "viewers": [ { "fileExtension": ["js", "json"], "viewer": "assets/_default/api/monaco/?path=${path}&mimeType=${mimeType}&fileExtension=${fileExtension}&lang=${lang}&theme=${theme}&language=javascript" }, { "mimeType": ["application/json"], "viewer": "assets/_default/api/monaco/?path=${path}&mimeType=${mimeType}&fileExtension=${fileExtension}&lang=${lang}&theme=${theme}&language=javascript" }, { "mimeType": ["text/plain"], "viewer": "assets/_default/api/monaco/?path=${path}&mimeType=${mimeType}&fileExtension=${fileExtension}&lang=${lang}&theme=${theme}" }, { "mimeType": ["text/xml"], "viewer": "assets/_default/api/monaco/?path=${path}&mimeType=${mimeType}&fileExtension=${fileExtension}&lang=${lang}&theme=${theme}&language=xml" }, { "mimeType": ["text/java"], "viewer": "assets/_default/api/monaco/?path=${path}&mimeType=${mimeType}&fileExtension=${fileExtension}&lang=${lang}&theme=${theme}&language=java" }, { "mimeType": ["text/javascript"], "viewer": "assets/_default/api/monaco/?path=${path}&mimeType=${mimeType}&fileExtension=${fileExtension}&lang=${lang}&theme=${theme}&language=javascript" }, { "mimeType": ["text/html"], "viewer": "assets/_default/api/monaco/?path=${path}&mimeType=${mimeType}&fileExtension=${fileExtension}&lang=${lang}&theme=${theme}&language=html" }, { "mimeType": ["text/markdown", "text/x-web-markdown", "text/x-markdown"], "viewer": "assets/_default/api/monaco/?path=${path}&mimeType=${mimeType}&fileExtension=${fileExtension}&lang=${lang}&theme=${theme}&language=markdown" }, { "mimeType": ["audio/mp3", "audio/webm", "audio/ogg", "audio/mpeg", "video/mp4", "video/webm", "video/ogg", "application/ogg"], "viewer": "assets/_default/api/video/?path=${path}&mimeType=${mimeType}&fileExtension=${fileExtension}&lang=${lang}&theme=${theme}" }, { "mimeType": ["image/jpeg", "image/png", "image/apng", "image/gif", "image/svg+xml", "image/webp"], "viewer": "assets/_default/api/img/?path=${path}&mimeType=${mimeType}&fileExtension=${fileExtension}&lang=${lang}&theme=${theme}" }, { "viewer": "() => parameters.defaultViewer + '#'" }, { "error": true, "viewer": "assets/_default/api/error/?path=${path}&mimeType=${mimeType}&fileExtension=${fileExtension}&lang=${lang}&theme=${theme}" } ] },
Example: Resolve the viewer path dynamically
In case you need to resolve the viewer path dynamically, use the arrow function and it will be resolved at runtime with additional parameters (component, dmsObject, parameters, api).
"preview": { "viewers": [ { "fileExtension": ["pdf"], "viewer": "() => {var user = api.session.getUser(); var id = dmsObject.id; return parameters.defaultViewer + '#/' + user + '/' + id}" } ] },
"preview": { "viewers": [ { "fileExtension": ["pdf"], "viewer": "${originalPath}" } ] },
Example: Scripting
The following configuration example shows how to use scripting to control an additional viewer-service. For a pdf formatted file the custom microservice stampservice
is called to include a watermark onto each page.
"viewers": [{ "fileExtension": ["pdf"], "viewer": "() => {var viewerUrl = parameters.defaultViewer; var obj = dmsObject; if (['docdocrule','docdrawing','docreport','docchorder'].includes(obj.typeName)) {var user = api.session.getUser(); var url = '/ecm/stampservice/api/stamp/pdf/' + obj.content.id + '?user=' + user.name + '&version=' + obj.version; viewerUrl = viewerUrl.replace('${pathPdf}', encodeURIComponent(url));} return viewerUrl + '#'}" }]
"viewers": [{ "mimeType": ["text/xml"], "viewer": "() => {var obj = dmsObject; var url = location.origin + '/ecm/xmlformatservice/api/format/xml/' + obj.id + '?version=' + obj.version; return 'viewer/view/api/monaco/?path=' + encodeURIComponent(url) + '&mimeType=${mimeType}&fileExtension=${fileExtension}&lang=${lang}&theme=${theme}&language=xml'}" }]
Object | Description |
---|---|
dmsObject | Contains the object with all its properties and attributes |
location | Contains the path where the client is hosted, origin, port, protocol |
version | Contains the version number of the dmsObject that should be previewed |
mimeType | Contains the mimetype of the document file of the referenced dmsObject |
fileExtension | Contains the file extension of the document file |
path | Contains the complete path to load the document file |
lang | Contains the language code that the user has set, e.g. en or de |
user | Contains the user with all his attributes |
This section is under work.
"viewers": [{ "type": "extend", "viewer": "() => { <script example> }" }]
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Video</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1" /> </head> <body style="margin:0;"> <video id="video" controls="" name="media" style="width:100%;height:auto;outline:none;"></video> <script> window.addEventListener('load', function() { document.querySelector('#video').setAttribute('src', decodeURIComponent(window.location.search.replace('?file=', ''))); }) </script> </body> </html>