Skip to content

Commit

Permalink
Use upgraded PDF.js fork with the new text analyzer implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed May 27, 2024
1 parent b05d24b commit fae5c69
Show file tree
Hide file tree
Showing 21 changed files with 7,407 additions and 4,535 deletions.
16 changes: 0 additions & 16 deletions .babelrc-es

This file was deleted.

28 changes: 15 additions & 13 deletions examples/web-worker/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
pageIndex: 0,
rects: [[100, 100, 120, 120]]
},
color: '#FF0000',
tags: [],
comment: 'A test note',
authorName: 'John',
dateModified: '2019-04-19T08:21:13.011Z'
Expand All @@ -24,21 +26,21 @@
let promiseId = 0;
let waitingPromises = {};

let worker = new Worker('../../build/pdf-worker.js');
async function query(op, data, transfer) {
let worker = new Worker('../../build/worker.js');

async function query(action, data, transfer) {
return new Promise(function (resolve) {
promiseId++;
waitingPromises[promiseId] = resolve;
worker.postMessage({ id: promiseId, op, data }, transfer);
worker.postMessage({ id: promiseId, action, data }, transfer);
});
}

worker.onmessage = async function (e) {
let message = e.data;
console.log('Message received', message);
if (message.responseId) {
let resolve = waitingPromises[message.responseId];
if (message.responseID) {
let resolve = waitingPromises[message.responseID];
if (resolve) {
resolve(message.data);
}
Expand All @@ -53,27 +55,27 @@
cMapData: new Uint8Array(await (await fetch('../../build/cmaps/' + message.data + '.bcmap')).arrayBuffer())
};
}
worker.postMessage({ responseId: e.data.id, data: respData });
worker.postMessage({ responseID: e.data.id, data: respData });
return;
}
}

function handleFile() {
let file = document.querySelector('input[type=file]').files[0];
let arrayBuffer;
let fileReader = new FileReader();
fileReader.onload = async function (event) {
arrayBuffer = event.target.result;
let buf = arrayBuffer.slice();
let extractedAnnotations = await query('read', { buf }, [buf]);
let extractedAnnotations = await query('import', { buf, existingAnnotations: [] }, [buf]);
console.log('Extracted annotations', extractedAnnotations);

buf = arrayBuffer.slice();
let fulltext = await query('fulltext', { buf }, [buf]);
let fulltext = await query('getFulltext', { buf }, [buf]);
console.log('Extracted fulltext', fulltext);

buf = arrayBuffer.slice();
let data = await query('write', { buf, annotations }, [buf]);
let data = await query('export', { buf, annotations, password: '' }, [buf]);
downloadFile(data.buf, 'test.pdf', 'application/pdf')
};
fileReader.readAsArrayBuffer(file);
Expand Down
Loading

0 comments on commit fae5c69

Please sign in to comment.