diff --git a/src/lib/components/layout/Navbar/Menu.svelte b/src/lib/components/layout/Navbar/Menu.svelte index eb3d292c7b..62a980bcd4 100644 --- a/src/lib/components/layout/Navbar/Menu.svelte +++ b/src/lib/components/layout/Navbar/Menu.svelte @@ -77,6 +77,7 @@ await downloadChatPdf({ title: chat.chat.title, stylizedPdfExport: $settings?.stylizedPdfExport ?? true, + containerElementId: 'full-messages-container', chatText: await getChatAsText(), async onBeforeRender() { showFullMessages = true; diff --git a/src/lib/components/layout/Sidebar/ChatMenu.svelte b/src/lib/components/layout/Sidebar/ChatMenu.svelte index bb4629786f..c7b4c19172 100644 --- a/src/lib/components/layout/Sidebar/ChatMenu.svelte +++ b/src/lib/components/layout/Sidebar/ChatMenu.svelte @@ -88,6 +88,7 @@ await downloadChatPdf({ title: chat.chat.title, stylizedPdfExport: $settings?.stylizedPdfExport ?? true, + containerElementId: 'full-messages-container', chatText: await getChatAsText(chat), async onBeforeRender() { showFullMessages = true; diff --git a/src/lib/utils/pdf.ts b/src/lib/utils/pdf.ts index d667d0bbfe..d68575bde1 100644 --- a/src/lib/utils/pdf.ts +++ b/src/lib/utils/pdf.ts @@ -375,7 +375,7 @@ export const downloadNotePdf = async (note: NoteData): Promise => { * Plain text mode: Exports chat content as plain text with basic formatting. * * @param options - Configuration object - * @param options.containerElementId - ID of the container element to render (for stylized mode). Defaults to 'full-messages-container' + * @param options.containerElementId - ID of the container element to render (for stylized mode). * @param options.chatText - Plain text content (required for plain text mode) * @param options.title - PDF filename (without .pdf extension) * @param options.stylizedPdfExport - Whether to use stylized PDF export (default: true) @@ -386,12 +386,10 @@ export const downloadNotePdf = async (note: NoteData): Promise => { export const downloadChatPdf = async (options: ChatPdfOptions): Promise => { console.log('Downloading PDF', options); - if (options.stylizedPdfExport ?? true) { + if ((options.stylizedPdfExport ?? true) && options.containerElementId) { await options.onBeforeRender?.(); - const containerElement = document.getElementById( - options.containerElementId || 'full-messages-container' - ); + const containerElement = document.getElementById(options.containerElementId); try { if (containerElement) { const virtualWidth = DEFAULT_VIRTUAL_WIDTH; @@ -423,10 +421,10 @@ export const downloadChatPdf = async (options: ChatPdfOptions): Promise => return; } - if (!options.chatText) { - console.error('chatText is required for plain text PDF export'); + if (options.chatText) { + await exportPlainTextToPdf(options.chatText, `chat-${options.title}.pdf`); return; } - await exportPlainTextToPdf(options.chatText, `chat-${options.title}.pdf`); + throw new Error('Either containerElementId or chatText is required'); };