How to Save PDFs back to a Web Server with PDF SDK for Web
Foxit PDF SDK for Web allows you save PDF files to a web server easily with a short code. Please add the code below to do so:
var FRAGMENT_ACTION = UIExtension.UIConsts.FRAGMENT_ACTIONar FRAGMENT_ACTION = UIExtension.UIConsts.FRAGMENT_ACTION var pdfui = new PDFUI({ fragments: [{ target: 'download-file-button', action: FRAGMENT_ACTION.AFTER, template: '<xbutton icon-class="customers-save-button-icon-css-class" name="upload-to-server-button"></xbutton>', config: [{ target: 'upload-to-server-button', callback: function() { this.getPDFUI() .getPDFViewer() .then(pdfViewer => { pdfViewer.setActiveElement(null); const buffers = []; return pdfViewer.currentPDFDoc .getStream(({ arrayBuffer }) => { buffers.push(arrayBuffer); }) .then(_ => { return [buffers, pdfViewer.currentPDFDoc.getFileName()]; }); }) .then(([buffers, fileName]) => { if (!fileName || fileName.length === 0) { fileName = "unknown.pdf"; } const blob = new Blob(buffers, {type: 'application/pdf'}) console.info('start uploading', blob); // ajax upload here }); } }] }] })
You can add the upload code to the “// ajax upload here” section and then you’re all set.
Updated on August 11, 2021