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

173
Views
PDF borroso con la biblioteca pdf.js

Estoy usando la biblioteca pdf.js para representar mi archivo pdf en el lienzo. Primero estaba buscando una solución para renderizar pdf con el tamaño del elemento principal del lienzo. Lo he encontrado y funciona bien. Luego resuelvo el problema de renderizar TODAS las páginas a la vez. Finalmente, mi código ahora se ve de esta manera:

 pdfjsLib.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.js`; class PdfLoader { currPage = 1; numPages = -1; doc = null; constructor($container) { this.$container = $container; } load(path) { // reset when using more than once this.currPage = 1; this.promise = new Promise(resolve => this.promiseResolve = resolve); this.$container.innerHTML = ""; pdfjsLib.getDocument(path).promise.then(pdf => { this.doc = pdf; this.numPages = pdf.numPages; pdf.getPage(1).then(this._handlePage.bind(this)); }); return this; } _handlePage(page) { let viewport = page.getViewport({scale: 1}); const scale = this.$container.clientWidth/viewport.width; // const outputScale = window.devicePixelRatio || 1; const outputScale = 1; viewport = page.getViewport({scale}); const cnv = document.createElement("canvas"); const ctx = cnv.getContext("2d"); const width = Math.floor(viewport.width); const height = Math.floor(viewport.height); cnv.width = Math.floor(width * outputScale); cnv.height = Math.floor(height * outputScale); cnv.style.width = `${width}px`; cnv.style.height = `${height}px`; const transform = (outputScale !== 1) ? [outputScale, 0, 0, outputScale, 0, 0] : null; page.render({ canvasContext: ctx, transform: transform, viewport: viewport, }); this.$container.appendChild(cnv); this.currPage++; if (this.doc !== null && this.currPage <= this.numPages) { this.doc.getPage(this.currPage).then(this._handlePage.bind(this)); } else { this.promiseResolve(); } } } const $pages = document.getElementById("pages"); const pdfLoader = new PdfLoader($pages); pdfLoader.load("extendedReport.pdf").promise .then(initReport); let arrow = null; function initReport() { // my other stuff }

Y ahora mi problema es que cuando veo el pdf renderizado, parece que su calidad es muy baja y el texto está borroso, por lo que el documento es ilegible en dispositivos móviles. Intenté cambiar la escala pasada como dicen en internet, pero no es eso. ¿Podrías ayudarme, por favor? ¿Qué me estoy perdiendo?

baja calidad de pdf

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!