Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
Some trouble with PDFJS during creating extension(chromeAPI)

I have tried to create simple chrome extension to help myself download manga to ebook.
How it works - i get img sources as a string separated by space from website to extension side and split that into the table. And now my function attached below should check every single image(page) of manga, redraw it to canvas, and recreate it again to raw img(cause its should be like that for pdfjs).

My problem:

  1. console show its skips to last file
  2. my for loop ends faster than recreate process lasts - it saves 3kb pdf (propably empty
  3. manual saving PDF file from console still not works (file is bigger - +-size of image, but wont starts - shows errors).
function preparedownloadPDF(imagelist){
    var page = 0;
    console.log(imagelist);
    var doc = new jsPDF();
    var imageArray = imagelist.split(" ");
    console.log(imageArray);
    for(var i = 0; i < imageArray.length; i++)
    {
        if(imageArray[i] != "")
        {
            pdf.getImgFromUrl(imageArray[i]);
            //pdf.generatePDF();
        }
    }
    pdf.saveFile("123.pdf")
}



var pdf = {
    page: 0,
    img: null,
    options: {orientation: 'p', unit: 'mm', format: "custom"},
    doc: new jsPDF(this.options),
    getImgFromUrl: function(base_url){
        this.img = new Image();
        this.img.src = base_url;
        console.log(this.img.src + " baseurl: "+ base_url)
        this.img.onload = function () {
            pdf.generatePDF();
        };
    }, 
    generatePDF: function(){

        //redrawing image to canvas, to later recreate this as a BASE64 string(RAW data)
        var canvas = document.createElement("canvas");
        canvas.width = this.img.width;
        canvas.height = this.img.height;

        console.log("canvas")
        console.log(canvas.width + "x" + canvas.height)

        canvas.getContext("2d").drawImage(this.img, 0, 0);

        var image = document.createElement("img");
        image.src = canvas.toDataURL();

        document.body.appendChild(image);
        
        if(this.page++ != 0)
            pdf.doc.addPage();

        pdf.doc.addImage(this.img, 10, 10);
    },
    saveFile: function(name){
        this.doc.save(name)
        this.page = 0;
    }
}

Any tips?

@

I not attach code of validation URL,etc. I use as valid phoenix-scans pl website.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda