Skip to content
Razor catalogue

On this page

@addTagHelper *, Webority.Ui.Razor

Files in the page

Show a PDF, image, video or audio file in the page, with paging, zoom, search and print where the file allows.

Sample PDF
Show code
<app-file-viewer src="/samples/file-viewer-sample.pdf" name="Sample.pdf" download="true" />
An image
Show code
<app-file-viewer src="/samples/file-viewer-sample.png" />
No file yet
Show code
<app-file-viewer name="Contract.pdf" />
Audio
Show code
<app-file-viewer src="/samples/file-viewer-sample.mp3" />

Jump to a point

Open a long video or recording at a point a reader names, such as a chapter or a timestamp.

Video from a point
Show code
<app-button size="WideSize.Sm" variant="Outline" data-seek="4">Jump to 0:04</app-button>
<app-file-viewer id="walkthrough" src="/files/walkthrough.mp4" />

<script>
  document.querySelector('[data-seek]').addEventListener('click', function (e) {
    document.getElementById('walkthrough').seekTo(Number(e.currentTarget.dataset.seek));
  });
</script>

Actions and download

Add a download and your own buttons to the toolbar when a reader needs the file, not only to view it.

Download with a Details action
Show code
<app-file-viewer src="/samples/file-viewer-sample.pdf" name="Sample.pdf" download="true">
  <app-file-viewer-actions>
    <app-button size="WideSize.Sm">Details</app-button>
  </app-file-viewer-actions>
</app-file-viewer>

Every option

Every value of every prop, one cell each.

src

src="/samples/file-viewer-sample.pdf"
src="/samples/file-viewer-sample.png"
src="/samples/file-viewer-sample.mp4"
src="/samples/file-viewer-sample.mp3"
src="/samples/notes.docx"
no src: draws the frame with No file to show

name

name="Quarterly report.pdf"

type

type="application/pdf"

viewKey

view-key="invoice": keeps the zoom and thumbnails in this browser

download

download="false" (default)
download="true"

print

print="true" (default)
print="false"

workerSrc

worker-src: a hosted pdf.js worker, for a strict content security policy

assetBase

asset-base: the folder of pdf.js cmaps, fonts and wasm, for unusual PDFs

captions

captions="/samples/file-viewer-sample.vtt"

actions

no actions (default)
one button in an <app-file-viewer-actions> child
two buttons in an <app-file-viewer-actions> child: Reject and Approve

onLoad

onLoad: the wui-file-viewer:load event, once the file shows, with its kind and page count

onError

onError: the wui-file-viewer:error event when the file cannot be opened

prefs

no prefs (default): the browser keeps the view
prefs (React form), on Razor use view-key

onPrefsChange

onPrefsChange: the wui-file-viewer:prefs-change event, with all the view settings

className

class="file-viewer-tall"

ref

ref (React): the element, seekTo(seconds) on an open video or audio file; Razor calls it by id

Guidance

What to do, and what to avoid.

Use it when

  • Someone needs to read a document without leaving the page: an invoice, a contract, a report.
  • A review or approval step, where the decision buttons belong next to the file.

Reach for something else when

  • Someone is choosing a file to upload. → AppFilePicker or AppFileAttachment
  • The file only needs to be downloaded. → AppButton with an href

Reference

Try every prop, read the full list, and check keyboard and screen reader behaviour.

/samples/file-viewer-sample.pdf /samples/file-viewer-sample.png /samples/file-viewer-sample.mp4 /samples/file-viewer-sample.mp3 /samples/missing-file.pdf /samples/notes.docx
none one button two buttons
React, generated from the controls
<AppFileViewer
  src="/samples/file-viewer-sample.pdf"
  name="Sample.pdf"
  download
  actions={<AppButton size="sm">Details</AppButton>}
  onLoad={(detail) => …}
  onError={(detail) => …}
/>
Razor, the same props
<app-file-viewer src="/samples/file-viewer-sample.pdf" name="Sample.pdf" download="true">
  <app-file-viewer-actions>
    <app-button size="WideSize.Sm">Details</app-button>
  </app-file-viewer-actions>
</app-file-viewer>

11 props. The 5 most used come first.

Used on most screens 5 props

PropTypeDefaultDescription
srcdefault - string - The file's URL. Changing it opens the new file. Without one the viewer draws its frame with a "No file to show." message.
namedefault - string - The name shown in the toolbar and used for printing and download. Defaults to the last part of src.
typedefault - string - The file's MIME type. Defaults to a guess from the extension of name or src.
downloaddefault false bool false Shows a download button in the toolbar.
printdefault true bool true Shows the print button for a PDF or an image. Pass false to hide it.

Less common 6 props

PropTypeDefaultDescription
view-keydefault - string - Remembers the view settings (zoom, two-page view, thumbnails) in this browser under this key. Without it they last for the viewer's life.
worker-srcdefault - string - URL of a hosted pdf.js worker, for a site whose content security policy refuses blob: workers. Defaults to the bundled copy.
asset-basedefault beside the viewer script string beside the viewer script Folder holding pdf.js's cmaps/, standard_fonts/ and wasm/, which unusual PDFs need (Asian text, fonts a file does not embed, some scanned images).
captionsdefault - string - A WebVTT captions file for a video; adds a captions button to the player.
classdefault - string - Extra classes on the element; passes through as a plain HTML attribute.
styledefault - string - Inline style on the element. Set a height here to size the viewer.

Screen reader

3 notes
  • The toolbar buttons carry accessible names.
  • The settings menus use the menu role with menuitemradio rows and respond to the keyboard.
  • The React wrapper adds no roles of its own; the element draws the toolbar and the file.