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

144
Views
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
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!