v0.3.1 - use modified pdfkit to generate PDF

This commit is contained in:
Xmader 2019-12-01 03:57:54 -05:00
parent 53ae364a7a
commit eb6c13ce60
4 changed files with 22012 additions and 64279 deletions

86243
dist/main.js vendored

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "musescore-downloader",
"version": "0.3.0",
"version": "0.3.1",
"description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro免费下载 musescore.com 上的曲谱",
"main": "dist/main.js",
"repository": {
@ -14,14 +14,15 @@
},
"homepage": "https://github.com/Xmader/musescore-downloader#readme",
"dependencies": {
"pdfmake": "^0.1.62"
"pdfkit": "git+https://github.com/Xmader/pdfkit.git"
},
"devDependencies": {
"@rollup/plugin-json": "^4.0.0",
"@types/pdfmake": "^0.1.8",
"@types/pdfkit": "^0.10.4",
"rollup": "^1.26.3",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-typescript": "^1.0.1",
"tslib": "^1.10.0",

View file

@ -2,6 +2,7 @@ import typescript from "rollup-plugin-typescript"
import resolve from "rollup-plugin-node-resolve"
import commonjs from "rollup-plugin-commonjs"
import builtins from "rollup-plugin-node-builtins"
import nodeGlobals from "rollup-plugin-node-globals"
import json from "@rollup/plugin-json"
import fs from "fs"
@ -20,11 +21,13 @@ export default {
format: "iife",
sourcemap: false,
banner: getBannerText,
// intro: "const global = typeof window === 'object' && window.window === window ? window : typeof self === 'object' && self.self === self ? self : typeof commonjsGlobal === 'object' && commonjsGlobal.global === commonjsGlobal ? commonjsGlobal : void 0"
},
plugins: [
typescript({
target: "ES6",
sourceMap: false,
allowJs: true,
lib: [
"ES6",
"dom"
@ -40,5 +43,10 @@ export default {
}),
json(),
builtins(),
nodeGlobals({
dirname: false,
filename: false,
baseDir: false,
})
]
}

View file

@ -3,7 +3,7 @@ import "./meta"
import { ScorePlayerData } from "./types"
import { waitForDocumentLoaded } from "./utils"
import pdfmake from "pdfmake/build/pdfmake"
import PDFDocument from "pdfkit/lib/document"
const generatePDF = (name?: string) => {
const scoreImgs: NodeListOf<HTMLImageElement> = document.querySelectorAll("img[id^=score_]")
@ -25,26 +25,25 @@ const generatePDF = (name?: string) => {
return canvas.toDataURL("image/png")
})
const pdf = pdfmake.createPdf({
pageMargins: 0,
// @ts-ignore
pageOrientation: "PORTRAIT",
pageSize: { width, height },
// @ts-ignore
const pdf = new (PDFDocument as typeof import("pdfkit"))({
// compress: true,
content: [
...imgDataList.map((data) => {
return {
image: data,
width,
height,
}
})
]
size: [width, height],
autoFirstPage: false,
margin: 0,
layout: "portrait",
})
return new Promise((resolve) => {
pdf.download(`${name}.pdf`, resolve)
imgDataList.forEach((data) => {
pdf.addPage()
pdf.image(data,{
width,
height,
})
})
// @ts-ignore
return pdf.download(`${name}.pdf`)
}
const getTitle = (scorePlayerData: ScorePlayerData) => {