Need to set name from top margin 90px in pdf
I am using viewer supplied with pdf.js same available here https://mozilla.github.io/pdf.js/web/viewer.html
Tried to set text content using following code but not working
page.getTextContent().then(function(textContent){
var textLayer = new TextLayerBuilder({
textLayerDiv : $textLayerDiv.get(0),
pageIndex : page_num - 1,
viewport : viewport
});
textLayer.setTextContent(textContent);
});
Also, tried to modify pdf.js file to append "Test" at the end of every span tag rendered which shows text updated using inspect element but same not rendered in viewer
function appendText(task, geom, styles, ctx) {
geom.str += "Test";
const textDiv = document.createElement("span");
const textDivProperties = {
angle: 0,
canvasWidth: 0,
isWhitespace: false,
originalTransform: null,
paddingBottom: 0,
paddingLeft: 0,
paddingRight: 0,
paddingTop: 0,
scale: 1
};
Also, applied text content inside textLayer directly in viewer.js facing same issue not reflected in pdf rendered
const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
paintTask.onRenderContinue = renderContinueCallback;
this.paintTask = paintTask;
const resultPromise = paintTask.promise.then(function () {
return finishPaintTask(null).then(function () {
if (textLayer) {
const readableStream = pdfPage.streamTextContent({
normalizeWhitespace: true
});
textLayer.textContentItemsStr[4] = "Test";
textLayer.setTextContentStream(readableStream);
textLayer.render();
}
});
}, function (reason) {
return finishPaintTask(reason);
});