mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-14 21:35:19 +00:00
refactor: refactor PDF export logic
This commit is contained in:
parent
333cbb8a27
commit
4d80bf889d
3 changed files with 8 additions and 8 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ export const downloadNotePdf = async (note: NoteData): Promise<void> => {
|
|||
* 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<void> => {
|
|||
export const downloadChatPdf = async (options: ChatPdfOptions): Promise<void> => {
|
||||
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<void> =>
|
|||
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');
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue