Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
Add text content to pdf before displaying in pdf viewer using pdf.js

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);
                    });
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!