mirror of
https://github.com/cubexy/obsidian-pdf-printer.git
synced 2026-07-22 05:48:03 +00:00
add Promise.all to fetch tasks
This commit is contained in:
parent
789311bc99
commit
ea1694a798
1 changed files with 9 additions and 11 deletions
20
main.ts
20
main.ts
|
|
@ -3,7 +3,6 @@ import {
|
|||
App,
|
||||
Editor,
|
||||
MarkdownView,
|
||||
Modal,
|
||||
Notice,
|
||||
Plugin,
|
||||
PluginSettingTab,
|
||||
|
|
@ -41,7 +40,6 @@ export default class MyPlugin extends Plugin {
|
|||
const statusBarItemEl = this.addStatusBarItem();
|
||||
statusBarItemEl.setText("Status Bar Text");
|
||||
|
||||
// This adds an editor command that can perform some operation on the current editor instance
|
||||
this.addCommand({
|
||||
id: "convert-pdf-to-images",
|
||||
name: "Convert PDF to images",
|
||||
|
|
@ -58,7 +56,9 @@ export default class MyPlugin extends Plugin {
|
|||
});
|
||||
|
||||
editor.replaceSelection(
|
||||
imagePathList.map((f) => `![[${f}]]`).join("\n")
|
||||
imagePathList
|
||||
.map((imagePath) => `![[${imagePath}]]`)
|
||||
.join("\n")
|
||||
);
|
||||
},
|
||||
});
|
||||
|
|
@ -195,14 +195,12 @@ export default class MyPlugin extends Plugin {
|
|||
private async convertPDFBufferToImages(
|
||||
pdfBuffer: PDFDocumentBuffer
|
||||
): Promise<string[]> {
|
||||
const pngFilePaths: string[] = [];
|
||||
for (const page of pdfBuffer.pages) {
|
||||
const pngFileName = `${pdfBuffer.fileName}-${page.pageNumber}.png`;
|
||||
const pngFilePath = `${pngFileName}`;
|
||||
await this.app.vault.createBinary(pngFilePath, page.buffer);
|
||||
pngFilePaths.push(pngFilePath);
|
||||
}
|
||||
return pngFilePaths;
|
||||
const writeTasks = pdfBuffer.pages.map(async (page) => {
|
||||
const name = `${pdfBuffer.fileName}-${page.pageNumber}.png`;
|
||||
await this.app.vault.createBinary(name, page.buffer);
|
||||
return name;
|
||||
});
|
||||
return Promise.all(writeTasks);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue