Skip to content

Instantly share code, notes, and snippets.

Created May 27, 2021
What would you like to do?
Download PDF from
async function downloadBook(aid, bid) {
const [title, myreader, kime, fime] = await getBookKey(aid, bid)
const r = await fetch(`${aid}&bid=${bid}&kime=${kime}&fime=${fime}`, { method: "POST", headers: { myreader: myreader }})
const d = await r.arrayBuffer()
saveByteArray(title + ".pdf", d)
async function getBookKey(aid, bid) {
const r = await fetch(`${aid}&bid=${bid}`)
const d = await r.text()
const title = /var title = \'(.+?)\'/.exec(d)[1]
const myreader = /tokenKey=\"(\w+)\"/.exec(d)[1]
const kime = /timeKey=\"(\w+)\"/.exec(d)[1]
const fime = /timeFlag=\"(\w+)\"/.exec(d)[1]
return [title, myreader, kime, fime]
function saveByteArray(reportName, byte) {
var blob = new Blob([byte], {type: "application/pdf"});
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
var fileName = reportName; = fileName;;
downloadBook("403", "8179.0")
// To be executed at in the browser console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment