`;
}
function tsudfLoadExample() {
if(!confirm("Overwrite current form with example data?")) return;
document.getElementById('inp-mark').value = "TECHNO-SOLVE";
document.getElementById('inp-serial').value = "87/654,321";
document.getElementById('inp-owner').value = "Innovations Global LLC";
document.getElementById('inp-signer').value = "Jane A. Doe";
document.getElementById('inp-goods').value = "Computer software for data analytics (Class 9); Consulting services (Class 35)";
document.getElementById('inp-specimen-desc').value = "A screenshot of the main product sales page (www.innovations.com/techno-solve), showing the mark TECHNO-SOLVE clearly displayed in the product header and associated with the description of the software.";
// Set dates slightly in the past
const now = new Date();
const threeMonthsAgo = new Date(now.setMonth(now.getMonth() - 3)).toISOString().split('T')[0];
document.getElementById('inp-first-use').value = threeMonthsAgo;
document.getElementById('inp-commerce-use').value = threeMonthsAgo;
tsudfUpdatePreview();
tsudfSwitchTab('preview');
}
/* --- PDF Generation --- */
async function tsudfGeneratePDF() {
tsudfUpdatePreview(); // Ensure latest data
const { jsPDF } = window.jspdf;
const doc = new jsPDF({
orientation: 'p',
unit: 'pt',
format: 'letter'
});
const paperContent = document.getElementById('tsudf-preview-paper');
// Use html2canvas to capture the entire styled document content
try {
const canvas = await html2canvas(paperContent, {
scale: 2,
backgroundColor: "#ffffff",
useCORS: true
});
const imgData = canvas.toDataURL('image/jpeg', 1.0);
const pageWidth = doc.internal.pageSize.getWidth();
const pageHeight = doc.internal.pageSize.getHeight();
const imgProps = doc.getImageProperties(imgData);
// Calculate the ratio to fit within margins (1 inch margin recommended for legal docs)
const margin = 50;
const pdfWidth = pageWidth - (margin * 2);
let pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
let yPos = margin;
// Split content across multiple pages if necessary
let heightLeft = pdfHeight;
doc.addImage(imgData, 'JPEG', margin, yPos, pdfWidth, pdfHeight);
// Check if content exceeds one page and add disclaimer footer if needed
if (pdfHeight > pageHeight - margin) {
// In a real application, sophisticated image slicing would be used here.
// For this single-file constraint, we print what fits and alert if it's too long.
console.warn("Content exceeds single page limit. Image slicing required for full fidelity.");
}
const data = tsudfGetData();
doc.save(`Declaration_Use_${data.mark.replace(/\s/g, '_')}.pdf`);
} catch (err) {
console.error("PDF generation error:", err);
alert("Error creating PDF. Ensure all fields are valid and try again.");
}
}
