diff --git a/demo/tiff-preprocessor.js b/demo/tiff-preprocessor.js new file mode 100644 index 0000000..f2febc4 --- /dev/null +++ b/demo/tiff-preprocessor.js @@ -0,0 +1,16 @@ +async function preprocessTiff(blob) { + let zip = await JSZip.loadAsync(blob); + const tiffs = zip.file(/[.]tiff?$/); + + if (tiffs.length == 0) + return blob; + + for (let f of tiffs) { + const buffer = await f.async("uint8array"); + const tiff = new Tiff({ buffer }); + const blob = await new Promise(res => tiff.toCanvas().toBlob(blob => res(blob), "image/png")); + zip.file(f.name, blob); + } + + return await zip.generateAsync({ type: "blob" }); +} \ No newline at end of file diff --git a/index.html b/index.html index e08c541..406023e 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,8 @@ + + @@ -55,7 +57,11 @@ let currentDocument = null; const docxOptions = Object.assign(docx.defaultOptions, { debug: true, - experimental: true + experimental: true, + processMedia: (...args) => { + console.log(args); + return args[0]; + } }); const container = document.querySelector("#document-container"); @@ -63,17 +69,18 @@ const loadButton = document.querySelector("#loadButton"); const testDocuments = document.querySelector("#testDocuments"); - function renderDocx(file) { + async function renderDocx(file) { currentDocument = file; if (!currentDocument) return; - docx.renderAsync(currentDocument, container, null, docxOptions) - .then((x) => { - renderThumbnails(container, document.querySelector("#thumbnails-container")); - console.log(x); - }); + let blob = preprocessTiff(currentDocument); + let doc = await docx.parseAsync(blob, docxOptions); + await docx.renderDocument(doc, container, null, docxOptions); + + renderThumbnails(container, document.querySelector("#thumbnails-container")); + console.log(doc); } fileInput.addEventListener("change", ev => {