Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: resolve PDF export error by properly accessing jsPDF and html2canvas in Vite environment (#758)

LearningCircuitada919787bb5
diff --git a/src/local_deep_research/web/static/js/services/pdf.js b/src/local_deep_research/web/static/js/services/pdf.js
index 27e78f315b..2855e8344f 100644
--- a/src/local_deep_research/web/static/js/services/pdf.js
+++ b/src/local_deep_research/web/static/js/services/pdf.js
@@ -11,15 +11,19 @@
* @returns {Promise<Blob>} A promise resolving to the generated PDF blob
*/
async function generatePdf(title, content, metadata = {}) {
- // Check if necessary libraries are loaded
- if (typeof jsPDF === 'undefined') {
+ // Check if necessary libraries are loaded (check window object for Vite compatibility)
+ if (typeof jsPDF === 'undefined' && typeof window.jsPDF === 'undefined') {
throw new Error('PDF generation libraries not loaded (jsPDF missing)');
}
- if (typeof html2canvas === 'undefined') {
+ if (typeof html2canvas === 'undefined' && typeof window.html2canvas === 'undefined') {
throw new Error('PDF generation libraries not loaded (html2canvas missing)');
}
+ // Use the global versions if local ones aren't available
+ const jsPDFLib = typeof jsPDF !== 'undefined' ? jsPDF : window.jsPDF;
+ const html2canvasLib = typeof html2canvas !== 'undefined' ? html2canvas : window.html2canvas;
+
// Ensure content is a string
content = String(content || '');
@@ -155,7 +159,7 @@ async function generatePdf(title, content, metadata = {}) {
try {
// Create a new PDF document
- const pdf = new jsPDF('p', 'pt', 'letter');
+ const pdf = new jsPDFLib('p', 'pt', 'letter');
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
const margin = 40;
@@ -765,7 +769,7 @@ async function generatePdf(title, content, metadata = {}) {
} else {
// Only use html2canvas as a last resort for elements with no text content
try {
- const canvas = await html2canvas(element, {
+ const canvas = await html2canvasLib(element, {
scale: 2,
useCORS: true,
logging: false,