Skip to content

Build your personal knowledge base with Trilium Notes

feat(pdf): support as template

Elian Doran62eb825e529f
diff --git a/apps/server/src/services/notes.ts b/apps/server/src/services/notes.ts
index 13a0955774..09686481e4 100644
--- a/apps/server/src/services/notes.ts
+++ b/apps/server/src/services/notes.ts
@@ -196,6 +196,17 @@ function createNewNote(params: NoteParams): {
throw new Error(error);
}
+ // When creating from a template, inherit the template's type and mime if not explicitly provided.
+ // This ensures binary types (PDF, images, etc.) get the correct mime from the start.
+ if (params.templateNoteId) {
+ const templateNote = becca.getNote(params.templateNoteId);
+ if (templateNote) {
+ if (!params.mime) {
+ params.mime = templateNote.mime;
+ }
+ }
+ }
+
return sql.transactional(() => {
let note, branch, isEntityEventsDisabled;
@@ -252,6 +263,15 @@ function createNewNote(params: NoteParams): {
throw new Error(`Template note '${params.templateNoteId}' does not exist.`);
}
+ // for binary content types (PDF, images, etc.), copy the template's content directly
+ // since the event handler in handlers.ts only handles string content
+ if (!templateNote.hasStringContent()) {
+ const templateContent = templateNote.getContent();
+ if (templateContent) {
+ note.setContent(templateContent);
+ }
+ }
+
note.addRelation("template", params.templateNoteId);
copyAttachments(templateNote, note);