Personal Reflection Journal

Journal Entry

My Journal Entries

${prjEscapeHtml(entry.content.substring(0, 150))}${entry.content.length > 150 ? '...' : ''}

`; entryDiv.innerHTML = html; prjEntryListAreaEl.appendChild(entryDiv); }); } function prjViewFullEntry(dateKey) { if (prjJournalEntries[dateKey]) { prjEntryDateEl.value = dateKey; prjLoadEntryForSelectedDate(); // This will populate Tab 1 prjTabButtons[0].click(); // Switch to Tab 1 } } function prjEscapeHtml(unsafe) { if (typeof unsafe !== 'string') return ''; return unsafe.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'"); } // PDF Download function prjDownloadPDF() { const startDate = prjFilterStartDateEl.value; const endDate = prjFilterEndDateEl.value; const filterTags = prjFilterTagsEl.value.trim().toLowerCase().split(',').map(t => t.trim()).filter(t => t); let entriesToExport = []; Object.keys(prjJournalEntries).forEach(dateKey => { if ((!startDate || dateKey >= startDate) && (!endDate || dateKey <= endDate)) { const entry = prjJournalEntries[dateKey]; let matchesTags = true; if (filterTags.length > 0) { matchesTags = filterTags.every(ft => (entry.tags || []).some(et => et.toLowerCase().includes(ft))); } if (matchesTags) entriesToExport.push(entry); } }); entriesToExport.sort((a, b) => new Date(a.date) - new Date(b.date)); // Chronological for PDF if (entriesToExport.length === 0) { alert("No entries matching current filters to export."); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF('p', 'pt', 'a4'); const primaryColorPDF = getComputedStyle(document.documentElement).getPropertyValue('--prj-primary-color').trim(); const textColorPDF = getComputedStyle(document.documentElement).getPropertyValue('--prj-text-color-dark').trim(); let yPos = 40; const leftMargin = 40; const contentWidth = doc.internal.pageSize.getWidth() - (2 * leftMargin); const lineSpacing = 14; doc.setFontSize(18); doc.setTextColor(primaryColorPDF); doc.text("Personal Reflection Journal", doc.internal.pageSize.getWidth() / 2, yPos, { align: 'center' }); yPos += 20; doc.setFontSize(10); doc.setTextColor(textColorPDF); const periodString = (startDate || endDate) ? `Entries from: ${startDate ? new Date(startDate+'T00:00:00Z').toLocaleDateString() : 'Beginning'} To: ${endDate ? new Date(endDate+'T00:00:00Z').toLocaleDateString() : 'End'}` : "All Entries"; doc.text(periodString, doc.internal.pageSize.getWidth() / 2, yPos, { align: 'center' }); if(filterTags.length > 0) { yPos += lineSpacing; doc.text(`Filtered by Tags: ${filterTags.join(', ')}`, doc.internal.pageSize.getWidth() / 2, yPos, { align: 'center' }); } yPos += 30; entriesToExport.forEach((entry, index) => { if (index > 0) { // Add separator for multiple entries yPos = checkPdfPageBreak(doc, yPos, 20 + lineSpacing); doc.setDrawColor(200); // Light grey line doc.line(leftMargin, yPos - (lineSpacing/2), leftMargin + contentWidth, yPos - (lineSpacing/2) ); } yPos = checkPdfPageBreak(doc, yPos, 30); doc.setFontSize(14); doc.setFont(undefined, 'bold'); doc.setTextColor(primaryColorPDF); doc.text(new Date(entry.date+'T00:00:00Z').toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }), leftMargin, yPos); yPos += 18; if (entry.title) { doc.setFontSize(12); doc.setTextColor(getComputedStyle(document.documentElement).getPropertyValue('--prj-secondary-color').trim()); doc.text(entry.title, leftMargin, yPos); yPos += 16; } doc.setFontSize(9); doc.setFont(undefined, 'normal'); doc.setTextColor(textColorPDF); let metaInfo = []; if (entry.mood) metaInfo.push(`Mood: ${entry.mood}`); if (entry.tags && entry.tags.length > 0) metaInfo.push(`Tags: ${entry.tags.join(', ')}`); if (metaInfo.length > 0) { doc.text(metaInfo.join(' | '), leftMargin, yPos); yPos += lineSpacing * 1.2; } doc.setFontSize(10); const contentLines = doc.splitTextToSize(entry.content, contentWidth); contentLines.forEach(line => { yPos = checkPdfPageBreak(doc, yPos, lineSpacing * 0.9); doc.text(line, leftMargin, yPos); yPos += lineSpacing * 0.9; }); yPos += lineSpacing; // Extra space after each entry }); doc.save("Personal_Reflection_Journal.pdf"); } function checkPdfPageBreak(doc, currentY, spaceNeeded) { if (currentY + spaceNeeded > doc.internal.pageSize.getHeight() - 40) { doc.addPage(); return 40; } return currentY; }
Scroll to Top