我目前正在MVC Core中开发一个使用PDFTron webviewer的应用程序。有没有办法将用pdftron webviewer编辑过的pdf保存到服务器上?
pdftron有一个将注释保存到服务器的功能,但我需要将整个pdf和编辑保存到服务器。
WebViewer({
path: '/lib/WebViewer',
initialDoc: '/StaticResource/Music.pdf', fullAPI: !0, enableRedaction: !0
}, document.getElementById('viewer')).then(
function(t) {
samplesSetup(t);
var n = t.docViewer;
n.on('documentLoaded', function() {
document.getElementById('apply-redactions').onclick = function() {
t.showWarningMessage({
title: 'Apply redaction?',
message: 'This action will permanently remove all items selected for redaction. It cannot be undone.',
onConfirm: function () {
alert( );
t.docViewer.getAnnotationManager().applyRedactions()
debugger
var options = {
xfdfString: n.getAnnotationManager().exportAnnotations()
};
var doc = n.getDocument();
const data = doc.getFileData(options);
const arr = new Uint8Array(data);
const blob = new Blob([arr], { type: 'application/pdf' });
const data = new FormData();
data.append('mydoc.pdf', blob, 'mydoc.pdf');
// depending on the server, 'FormData' might not be required and can just send the Blob directly
const req = new XMLHttpRequest();
req.open("POST", '/DocumentRedaction/SaveFileOnServer', true);
req.onload = function (oEvent) {
// Uploaded.
};
req.send(data);
return Promise.resolve();
},
});
};
}),
t.setToolbarGroup('toolbarGroup-Edit'),
t.setToolMode('AnnotationCreateRedaction');
}
);当我向控制器发送请求时,我没有得到文件,它是空的
[HttpPost]
public IActionResult SaveFileOnServer(IFormFile file)
{
return Json(new { Result="ok"});
}有人能告诉我我哪里错了吗?谢谢!
发布于 2021-02-23 20:28:35
对于JavaScript异步函数,您需要等待它完成后再做其他事情。例如,对于AnnotationManager#exportAnnotations()和Document#getFileData(),AnnotationManager#applyRedactions()返回一个Promise。
对于JS异步函数,您可以查看:
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Promises https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await
因此,在这里,您可能希望使用await来等待Promise完成。
https://stackoverflow.com/questions/66315148
复制相似问题