Sign a PDF

Sign a PDF

or drop PDF or Word files here · up to 50 MB

Integrations: webhooks and Zapier

'; return new Uint8Array(await (await Studio.apiRaw('/api/pdf', { method: 'POST', body: { html: page } })).arrayBuffer()); } if (!/\.pdf$/i.test(f.name) && f.type !== 'application/pdf') throw new Error(t('err.type')); return new Uint8Array(await f.arrayBuffer()); } async function upload(files) { files = Array.prototype.slice.call(files || []); if (!files.length) return; $('err').hidden = true; try { if (files.some(function (f) { return f.size > MAX; })) throw new Error(t('err.big')); $('pick').textContent = t('list.uploading'); $('hint').hidden = true; var out = PDFLib.PDFDocument.create ? await PDFLib.PDFDocument.create() : null, parts = []; for (var i = 0; i < files.length; i++) { var bytes = await asPdf(files[i]); try { parts.push({ name: files[i].name, doc: await PDFLib.PDFDocument.load(bytes), bytes: bytes }); } catch (e) { throw new Error(/encrypt/i.test(e.message) ? t('err.locked', { name: files[i].name }) : t('err.read', { name: files[i].name })); } } var final; if (parts.length === 1) final = parts[0].bytes; else { for (var j = 0; j < parts.length; j++) (await out.copyPages(parts[j].doc, parts[j].doc.getPageIndices())).forEach(function (p) { out.addPage(p); }); final = await out.save(); } var pages = parts.reduce(function (n, p) { return n + p.doc.getPageCount(); }, 0); if (pages > 300) throw new Error(t('err.pages', { n: pages })); if (final.length > MAX) throw new Error(t('err.big')); var title = parts[0].name.replace(/\.(pdf|docx)$/i, ''); var r = await Studio.api('/api/esign', { method: 'POST', body: { action: 'create', title: title, pdf: b64(final), lang: I18n.lang, self: SELF } }); location.href = '/sign/edit/' + r.id; } catch (e) { if (!e.refused) fail(e.message); } } $('file').addEventListener('change', function () { upload(this.files); this.value = ''; }); var drop = $('drop'); drop.addEventListener('click', function (e) { if (e.target.closest('#err')) return; $('file').click(); }); ['dragenter', 'dragover'].forEach(function (ev) { drop.addEventListener(ev, function (e) { e.preventDefault(); drop.classList.add('over'); }); }); ['dragleave', 'drop'].forEach(function (ev) { drop.addEventListener(ev, function (e) { e.preventDefault(); drop.classList.remove('over'); }); }); drop.addEventListener('drop', function (e) { upload(e.dataTransfer.files); }); window.SOSignUpload = upload; // catch-up Phase 3 · drive-dropbox-import: /sign/import.js hands a picked file to the same path })();