Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda