Public
Edited
Jan 22, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
rects

Insert cell
//
// Reactive cell to load a pdf file when pdfFiles becomes available
//
loadPdfFile = {
if (pdfFile) {
mutable buf = (await pdfFile.blob()).arrayBuffer();
mutable inputRects = [];
mutable Audios_List = [];
}
}
Insert cell
//
// Reactive cell to load a zip file when inputZipFile becomes available
//
loadZipFile = {
if (inputZipFile) {
let readerUp = await zipreader(inputZipFile, { type: "arraybuffer" });
const dir = [...readerUp.keys()];
console.log("dir", dir);
mutable buf = await readerUp.get( dir.filter(word => word.includes(".pdf"))[0]);
let audios = dir.filter(word => word.includes(".ogg")).sort();
console.log ("audios", audios);
var aud_list = []
for (let i in audios){
let aud = await readerUp.get( audios[i]);
let blb = new Blob([aud], { type: "audio/ogg; codecs=opus" })
console.log("blb", blb);
aud_list.push(blb);
}
mutable Audios_List = aud_list;
readerUp = await zipreader(inputZipFile);
mutable inputRects = JSON.parse(await readerUp.get(dir.filter(word => word.includes(".json"))[0]));
}
}
Insert cell
//
// Callback for the save zip button
//
async function saveZipFile() {
const theZip = zip();
theZip.file("document.pdf", await pdfDocument.getData());
theZip.file("rects.json", JSON.stringify( rects.sort(function(a, b){return a.y - b.y})));
var audios = DictaphoneObj.getAudios();
for (let i in audios){
console.log("audio", fetch(audios[i].src).then(res => res.blob()));
theZip.file(`${i}.ogg`, fetch(audios[i].src).then(res => res.blob()));
}
const blob = await theZip.generateAsync({ type: "blob" });
const link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = `annotatedPdf.zip`;
link.click();
}
Insert cell
defaultPdfUrl = // A default pdf file
"https://static.observableusercontent.com/files/7c017ecb74bcfc40c27ab7eece42a036a4e91b2c85e855277b42424f70d6312bac5e95c18d67c783ff0979d8a85150c57987873ac4b2357ca34cb20a2624000e"
Insert cell
teddyASketchingInterfaceFor3dFreeformDesign = FileAttachment("Teddy A Sketching Interface for 3D Freeform Design.pdf")

Insert cell
//
// Array buffer containing the pdf document
//
mutable buf = teddyASketchingInterfaceFor3dFreeformDesign.arrayBuffer();
Insert cell
//
// selection rects used as input
//
mutable inputRects = []
Insert cell
mutable Audios_List = []
Insert cell
//
// The pdf document to be annotated
//
pdfDocument = pdfjs.getDocument(buf).promise
Insert cell
DictaphoneObj = await Dictaphone.build( );
Insert cell
## Dependencies
Insert cell
import { pdfjs, rectViewer, selectRects } from "6de75d56115bcaf2"
Insert cell
import { zip, zipreader } from "@fil/jszip"
Insert cell
import {Dictaphone} from "3a1a35b62fdb644d"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more