Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created June 9, 2023 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/58f2955e70f0c2778e09c3d7a19387a9 to your computer and use it in GitHub Desktop.
Save bjoerntx/58f2955e70f0c2778e09c3d7a19387a9 to your computer and use it in GitHub Desktop.
@model ClaimView
@using TXTextControl.Web.MVC.DocumentViewer
<div style="width: 100%; height: 600px;">
@Html.TXTextControl().DocumentViewer(settings => {
settings.DocumentData = Convert.ToBase64String(Model.Document);
settings.Dock = DocumentViewerSettings.DockStyle.Fill;
settings.SignatureSettings = new SignatureSettings() {
OwnerName = "Happy Insurance",
SignerName = Model.Claim.name,
SignatureBoxes = new SignatureBox[] {
new SignatureBox("txsign") {
SigningRequired = true,
Style = SignatureBox.SignatureBoxStyle.Signature }},
ShowSignatureBar = true,
RedirectUrlAfterSignature = this.Url.Action(
"ExportPDF",
"Home",
null,
Context.Request.Scheme, Context.Request.Host.ToString())
};
}).Render()
</div>
<script>
window.addEventListener("documentViewerLoaded", function () {
TXDocumentViewer.signatures.setSubmitCallback(exportPDF);
});
function exportPDF(data) {
// create temporary link to download document
var element = document.createElement('a');
element.setAttribute('href', 'data:application/octet-stream;base64,' + data);
element.setAttribute('download', "result.pdf");
element.style.display = 'none';
document.body.appendChild(element);
// simulate click
element.click();
// remove the link
document.body.removeChild(element);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment