mirror of
https://github.com/cubexy/obsidian-pdf-printer.git
synced 2026-07-22 05:48:03 +00:00
add custom image embedding and ability to add link to printed pages
This commit is contained in:
parent
7a6148cefc
commit
435f0a5c9b
1 changed files with 46 additions and 5 deletions
51
main.ts
51
main.ts
|
|
@ -17,11 +17,15 @@ import { FolderSuggest } from "utils/suggest/folderSuggest";
|
|||
interface PdfPrinterSettings {
|
||||
imageFolder: string;
|
||||
imageQuality: number;
|
||||
imageEmbedFormat: string;
|
||||
preservePdfLink: boolean;
|
||||
}
|
||||
|
||||
const DEFAULT_SETTINGS: PdfPrinterSettings = {
|
||||
imageFolder: "",
|
||||
imageQuality: 0.5,
|
||||
imageEmbedFormat: "![[${filename}]]",
|
||||
preservePdfLink: false,
|
||||
};
|
||||
|
||||
type PdfDocumentBuffer = {
|
||||
|
|
@ -63,11 +67,20 @@ export default class PdfPrinterPlugin extends Plugin {
|
|||
return;
|
||||
}
|
||||
|
||||
editor.replaceSelection(
|
||||
imagePathList
|
||||
.map((imagePath) => `![[${imagePath}]]`)
|
||||
.join("\n")
|
||||
);
|
||||
const imageLinks = imagePathList
|
||||
.map((imagePath) =>
|
||||
this.settings.imageEmbedFormat.replace(
|
||||
"${filename}",
|
||||
imagePath
|
||||
)
|
||||
)
|
||||
.join("\n");
|
||||
|
||||
const replacementText = this.settings.preservePdfLink
|
||||
? `[[${pdfFile.path}]]\n${imageLinks}`
|
||||
: `\n${imageLinks}`;
|
||||
|
||||
editor.replaceSelection(replacementText);
|
||||
|
||||
new Notice(
|
||||
`Document '${pdfFile.name}' was printed successfully.`
|
||||
|
|
@ -263,5 +276,33 @@ class PdfPrinterSettingsTab extends PluginSettingTab {
|
|||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(this.containerEl)
|
||||
.setName("Show link to original PDF above printed images")
|
||||
.setDesc(
|
||||
"Keep a link to the original PDF above the printed images as a reference."
|
||||
)
|
||||
.addToggle((cb) => {
|
||||
cb.setValue(this.plugin.settings.preservePdfLink).onChange(
|
||||
async (value) => {
|
||||
this.plugin.settings.preservePdfLink = value;
|
||||
await this.plugin.saveSettings();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
new Setting(this.containerEl)
|
||||
.setName("Image embed format")
|
||||
.setDesc(
|
||||
"Format for embedding images in the markdown file. Use ${filename} as a placeholder for the image file name."
|
||||
)
|
||||
.addText((cb) => {
|
||||
cb.setPlaceholder("![[${filename}]]")
|
||||
.setValue(this.plugin.settings.imageEmbedFormat)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.imageEmbedFormat = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue