Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created October 18, 2023 10:25
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/a0f66e268c4c875a04d78cc6b476a12e to your computer and use it in GitHub Desktop.
Save bjoerntx/a0f66e268c4c875a04d78cc6b476a12e to your computer and use it in GitHub Desktop.
async function saveDocument() {
try {
const saveSettings = { mergeFormFields: true, embedAnnotations: false };
const result = await TXDocumentViewer.saveDocument(
TXDocumentViewer.StreamType.InternalUnicodeFormat,
saveSettings);
const base64 = await result.base64();
const data = { document: base64 };
const { success, error } = await saveDocumentAjax(data);
if (success) {
alert("Document saved.");
} else {
alert("Error saving document.");
}
} catch (error) {
console.error("An error occurred:", error);
}
}
async function saveDocumentAjax(data) {
return new Promise((resolve) => {
$.ajax({
type: "POST",
url: "/Home/receiveDocument",
data: data,
success: (data) => resolve({ success: true, data }),
error: (xhr, ajaxOptions, thrownError) => resolve({ success: false, error: thrownError }),
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment