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:
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.