MCPcopy
hub / github.com/LibreScore/dl-librescore / exportPDF

Function exportPDF

src/pdf.ts:47–85  ·  view source on GitHub ↗
(
    scoreinfo: ScoreInfo,
    sheet: SheetInfo,
    scoreUrl = "",
    setText: (str: string) => void
)

Source from the content-addressed store, hash-verified

45};
46
47export const exportPDF = async (
48 scoreinfo: ScoreInfo,
49 sheet: SheetInfo,
50 scoreUrl = "",
51 setText: (str: string) => void
52): Promise<ArrayBuffer> => {
53 const imgType = sheet.imgType;
54 const pageCount = sheet.pageCount;
55
56 const rs = Array.from({ length: pageCount }).map(async (_, i) => {
57 let url;
58 if (i === 0) {
59 // The url to the first page is static. We don't need to use API to obtain it.
60 url = sheet.thumbnailUrl;
61 if (setText) {
62 setText(`${Math.round((1 / pageCount) * 83)}%`);
63 }
64 } else {
65 // obtain image urls using the API
66 url = await getFileUrl(
67 scoreinfo.id,
68 "img",
69 scoreUrl,
70 i,
71 undefined,
72 setText,
73 pageCount
74 );
75 }
76 return url;
77 });
78 const sheetImgURLs = await Promise.all(rs);
79 const args = [sheetImgURLs, imgType, sheet.dimensions] as const;
80 if (!isNodeJs) {
81 return _exportPDFBrowser(...args, setText);
82 } else {
83 return _exportPDFNode(...args);
84 }
85};
86
87let pdfBlob: Blob;
88export const downloadPDF = async (

Callers 2

cli.tsFile · 0.90
downloadPDFFunction · 0.85

Calls 3

getFileUrlFunction · 0.90
_exportPDFBrowserFunction · 0.85
_exportPDFNodeFunction · 0.85

Tested by

no test coverage detected