Document

The document component is used to display an HTML or Email document in a field. Documents can be downloaded and printed in PDF format. Additionally, you can view the PDF in a PDF viewer, email the PDF, and download the document XML used to populate the XSLT (only if user has one of the Dev Roles specified in the field definition).

MAUI Variation

When the component is loaded on a MAUI device, specifically a Phone or Tablet the Download and Print buttons will not be available. This is because saving files to those device types through MAUI is not supported.

Component code

The first section of the code includes the various variables required for the document component.

OnParametersSetAsync()

This method is called when the component initializes and when there’s an update to the parent component. This method is used to fetch and assigns the default Document Template GUID. It also fetches and assigns all additional Document Templates to the availableDocuments list.

Finally it evaluates if there’s a default document specified, if one is then it’s rendered by calling RenderDocument().

RenderDocument()

This method is used to render a document. It achieves this by creating a DocumentInformation object and populating it with the current instances UserGUID, SessionGUID, and InstanceGUID. The DocumentTemplateGUID property will equal the GUID value of the currentDocumentGUID variable. The last property is the CommandName which is assigned the value GetHTML.

An API call is then made, if the document was successfully retrieved it’s added to the B64HTML property of the DocumentInformation object and displayed to the user.

Task<DocumentInformation> GetDocumentData()

This method is used to get an updated DocumentInformation object and return it. This method is called as part of the RenderDocument process.

DownloadPDF(PdfViewerDownloadEventArgs args = null)

This method is used to download the document in a PDF format. Firstly, it needs to determine if the PDF format of the document the user wishes to download is currently stored in the active DocumentInformation’s B64PDF property. If not, an API call is made to retrieve it. Once it has the documents HTML it makes a call to the helper.js class in the UX-WASM-SA project, specifically the downloadFromByteArray function using JS Interop.

The downloadFromByteArray will initiate the download of the selected document in a PDF format.

PrintPDF()

This method is used to print the document in a PDF format. The first step is to check if the PDF format of the document is already stored in the current DocumentInformation’s B64PDF property, if not an API call is made to get it. Once the PDF format of the document has been acquired then a call to the IPrintingService interface is made which initiates the printing of the document.

DownloadXML()

This method is called when the Download XML button is selected. Its purpose is to download the XML used to populate the documents XSLT in an XML file. The download button is only visible if the user has at least one of the specified Dev Roles defined in the field definition.

OpenPDFViewer()

This method is called when the View PDF button is selected. Its purpose is to open the PDF version of the document in a PDF viewer in a popup window.

SendEmail()

This method is called when the Send Email button is selected in the email popup window. Its purpose is to validate the entered email address and required fields in the field definition have a value. Once validated it will make an API call that will attempt to send the PDF file to the specified email address.

Updated on March 14, 2024

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support

Leave a Comment