Resurrecting my old post here...
To answer my original question, I had to build the text layer object using a built in function, then I could pass it to build out the text layer. Here is my final code
FYI: My context is that i have a single page loaded into the canvas at a time. I have external forward and back buttons. When a forward or back button is pressed the following function is fired:
function renderPage(num) {
// Using promise to fetch the page
pdfDoc.getPage(num).then(function(page) {
var viewport = page.getViewport(scale);
canvas.height = viewport.height;
canvas.width = viewport.width;
// Other code custom to my scenario was removed here
// prep text layer object
var textLayerDiv = null;
$('#textLayer').html(''); // clear text layer
if (!PDFJS.disableTextLayer) {
textLayerDiv = document.getElementById('textLayer');
textLayerDiv.className = 'textLayer';
document.getElementById('canvas-container').appendChild(textLayerDiv);
}
// Create the textlayer object using the builder
var textLayer =
textLayerDiv ? new TextLayerBuilder(textLayerDiv,
this.id - 1) : null;
// Render PDF page into cancvas context
// USE the text layer object here
var renderContext = {
canvasContext: ctx,
textLayer: textLayer,
viewport: viewport
};
page.render(renderContext).then(function() {
working = false;
});
// Extract page text and load it to the text layer
page.getTextContent().then(
function textContentResolved(textContent) {
textLayer.setTextContent(textContent);
},
function pdfPageRenderError(error) {
console.log("PAGE RENDER ERROR: " + error);
}
);
});
}
On Thursday, January 31, 2013 3:11:18 PM UTC-6, Rick Lashes wrote: