2023年10月26日 星期四

[javascript]Scribd PDF下載語法

 

Scribd使用以下javascript下載後的jpg圖檔可再透過 https://subhra74.github.io/img2pdf/

將圖檔合併轉為PDF檔

var imgs = document.querySelectorAll('.absimg');

var subject = "下載檔名-P";

for (var i = 0; i < imgs.length; i++) {

  var img = imgs[i];

  

var src = "";

if( typeof  img.attributes['orig'] !== "undefined" && img.attributes['orig'] != ''){

      src =img.attributes['orig'].value.replace("',","");

}

else if(typeof  img.src !== "undefined" && img.src != '' ) src = img.src

else  if(typeof  img.currentSrc !== "undefined" && img.currentSrc != '' ) src = img.currentSrc;    

   

    if(src){

    try{

src = src.replace("http:/","https:/");

console.log(src);

const fetchResponse = await fetch(src);

const blob = await fetchResponse.blob();

const mimeType = blob.type;


const start = src.lastIndexOf('/') + 1;

const end = src.indexOf('-', start);

let pg = src.substring(start, end === -1 ? undefined : end);

if(pg.length == 1) pg = "0" + pg;

let name = subject + pg + ".jpg";


const a = document.createElement('a');

a.setAttribute('href', URL.createObjectURL(blob));

a.setAttribute('download', name);

a.click();

}catch(e){

    console.log(e);

}

}

}

console.log(o);