let annotationManager, adobeDCView function listenForFileUpload() { var fileToRead = document.getElementById("file-picker"); fileToRead.addEventListener("change", function (event) { var files = fileToRead.files; if (files.length > 0 && isValidPDF(files[0])) { var reader = new FileReader(); reader.onloadend = function (e) { var filePromise = Promise.resolve(e.target.result); previewFileUsingFilePromise(filePromise).then(adobe => { adobe.getAnnotationManager().then(async annotManager => { annotationManager = annotManager annotManager.setConfig({ downloadWithAnnotations: true, printWithAnnotations: true }) annotManager.addAnnotationsInPDF(annotations) .then(() => annotationManager.registerEventListener(eventAnnotation => { annotationEventListener(eventAnnotation) })) }) }) }; reader.readAsArrayBuffer(files[0]); } }, false); } function previewFileUsingFilePromise (filePromise) { adobeDCView = new AdobeDC.View({ clientId: "", divId: "adobe-dc-view" }) const profile = { userProfile: { name: 'Administrador', id: 'administrador@looplex.com.br' } } adobeDCView.registerCallback( AdobeDC.View.Enum.CallbackType.GET_USER_PROFILE_API, function () { return new Promise(resolve => { resolve({ code: window.AdobeDC.View.Enum.ApiResponseCode.SUCCESS, data: profile }) }) }, {} ) return adobeDCView.previewFile({ content: { promise: filePromise }, metaData: { fileName: 'Formulário de Referência 2020-páginas-375-452', id: '2075' } }, { dockPageControls: false, enableAnnotationAPIs: true, includePDFAnnotations: true, showLeftHandPanel: false }) } function isValidPDF(file) { if (file.type === "application/pdf") { return true; } if (file.type === "" && file.name) { var fileName = file.name; var lastDotIndex = fileName.lastIndexOf("."); return !(lastDotIndex === -1 || fileName.substr(lastDotIndex).toUpperCase() !== "PDF"); } return false; } async function annotationEventListener (event) { const annotation = event.data console.log(event) if (event.type === 'ANNOTATION_ADDED') { if (annotation.bodyValue === '' && annotation.target.selector.subtype === 'shape') { const custom = Object.assign({}, annotation) const [x0, y0, xf, yf] = annotation.target.selector.boundingBox custom.target.selector.inkList = boundingBoxInkListRect([x0, y0], [xf, yf]) annotationManager.updateAnnotation(annotation) } } } function boundingBoxInkListRect ([x0, y0], [xf, yf]) { return [[x0, y0, xf, y0], [xf, y0, xf, yf], [xf, yf, x0, yf], [x0, yf, x0, y0]] }