首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用ASP.net PDFTron核心将整个编辑后的pdf保存到服务器

如何使用ASP.net PDFTron核心将整个编辑后的pdf保存到服务器
EN

Stack Overflow用户
提问于 2021-02-22 19:48:01
回答 1查看 162关注 0票数 0

我目前正在MVC Core中开发一个使用PDFTron webviewer的应用程序。有没有办法将用pdftron webviewer编辑过的pdf保存到服务器上?

pdftron有一个将注释保存到服务器的功能,但我需要将整个pdf和编辑保存到服务器。

代码语言:javascript
复制
 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');
      }
    );

当我向控制器发送请求时,我没有得到文件,它是空的

代码语言:javascript
复制
 [HttpPost]
        public IActionResult SaveFileOnServer(IFormFile file)
        {
            
            return    Json(new { Result="ok"});
        }

有人能告诉我我哪里错了吗?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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完成。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66315148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档