Estoy intentando obtener los llamados highlights (o subrayados) de los PDF. Estoy utilizando PDFJS para obtener los datos del PDF del lado del servidor, hasta ahora puedo obtener las notas (o post-it) del texto subrayado, más no obtengo el texto que subrayó el usuario previamente. Este código lo escribí probando y "funciona"
var data = new Uint8Array(fs.readFileSync('./pdftests/test1.pdf'));
PDFJS.getDocument(data).then(function (pdfDoc_) {
pdfDoc = pdfDoc_;
pdfDoc.getPage(1).then(function(stuff) {
stuff.getTextContent().then( function(textContent){
console.log("textContent: " + JSON.stringify(textContent));
});
stuff.getAnnotations().then(function(annotations){
console.log("getAnnotations: "+ JSON.stringify(annotations));
});
}).catch(function(err) {
console.log('Error data');
console.log(err);
});
}).catch(function(err) {
console.log(err);
});
Lo impreso por el console.log en getAnnotations es lo siguiente:
[ { id: '18R',
subtype: 'Highlight',
annotationFlags: 4,
rect: [ 126, 617.856, 237.3855, 631.26 ],
color: Uint8Array [ 247, 220, 0 ],
borderStyle:
{ width: 0,
style: 1,
dashArray: [Object],
horizontalCornerRadius: 0,
verticalCornerRadius: 0 },
hasAppearance: true,
annotationType: 9,
hasPopup: true,
title: '',
contents: 'PRUEBA\n' },
{ id: '19R',
subtype: 'Popup',
annotationFlags: 0,
rect: [ 241.3855, 617.856, 369.3855, 689.856 ],
color: Uint8Array [ 0, 0, 0 ],
borderStyle:
{ width: 0,
style: 1,
dashArray: [Object],
horizontalCornerRadius: 0,
verticalCornerRadius: 0 },
hasAppearance: false,
annotationType: 16 } ]
No hallo la forma de saber cual es el texto que está resaltado.
Buscando encontré un JSFiddle que hace lo que "en sí" quiero: http://jsfiddle.net/seikichi/RuDvz/2/
Sin embargo, al importar ese código a mi controlador, la línea 38 me da error, detallando que no hay un método fromData:
var annotation = PDFJS.Annotation.fromData(data);
La documentación de PDFJS no me ha ayudado mucho.