User-Entered Holdings Subset:
CRITICAL DISCLAIMER: ${disclaimer_pdf}
`;
document.body.appendChild(pdfContentEl);
html2canvas(pdfContentEl, { scale: 2, useCORS: true, logging:true, windowWidth: pdfContentEl.scrollWidth, windowHeight: pdfContentEl.scrollHeight }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
let numPages = Math.ceil(canvas.height / ( (pdfHeight - 40) * (canvas.width / (pdfWidth - 40)) ) );
let pageCanvasHeight = (pdfHeight - 40) * (canvas.width / (pdfWidth - 40));
for (let i = 0; i < numPages; i++) {
if (i > 0) pdf.addPage();
let sourceY = i * pageCanvasHeight;
let sourceHeight = Math.min(pageCanvasHeight, canvas.height - sourceY);
const tempCanvas = document.createElement('canvas');
tempCanvas.width = canvas.width;
tempCanvas.height = sourceHeight;
const ctx = tempCanvas.getContext('2d');
ctx.drawImage(canvas, 0, sourceY, canvas.width, sourceHeight, 0, 0, canvas.width, sourceHeight);
const pageImgData = tempCanvas.toDataURL('image/png');
const pageImgHeight = (sourceHeight * (pdfWidth - 40)) / canvas.width;
pdf.addImage(pageImgData, 'PNG', 20, 20, pdfWidth - 40, pageImgHeight, undefined, 'FAST');
}
pdf.save(`${(inputs.fundName || "13F_Snapshot").replace(/[^a-z0-9]/gi, '_')}.pdf`);
if(document.body.contains(pdfContentEl)) document.body.removeChild(pdfContentEl);
}).catch(err => {
console.error("13F Snapshot PDF Error:", err); alert("Error generating PDF. See console.");
if(document.body.contains(pdfContentEl)) document.body.removeChild(pdfContentEl);
});
}
document.addEventListener('DOMContentLoaded', function() {
hfc_generateHoldingInputs(); // Initialize with default number of holding inputs
hfc_openTab({}, 'hfc_tab_intro');
if (!document.getElementById('hfc_fundName')) {
console.error("Critical input 'hfc_fundName' not found.");
}
// Add event listener to the select for number of holdings
const numHoldingsSelect = document.getElementById('hfc_numHoldings');
if (numHoldingsSelect) {
// No need to call hfc_generateHoldingInputs here again, it's called on DOMContentLoaded
// and its onchange calls it too.
}
// Ensure "Add Another Holding" button is managed correctly
const addBtn = document.getElementById('hfc_addHoldingButton');
if(addBtn) {
const numSelected = parseInt(document.getElementById('hfc_numHoldings').value);
addBtn.style.display = numSelected < 10 ? 'inline-block' : 'none';
// The select's onchange now calls hfc_generateHoldingInputs, which will also manage this button.
// The hfc_addHoldingRowDynamic function adds one by one if select is not used initially.
}
});
