function exportPDF() {
    const { jsPDF } = window.jspdf;
    const element = document.getElementById("page");

    // 1. Remove WebGL / embedded content
    const removed = [];

    element.querySelectorAll("embed, canvas").forEach(el => {
        const placeholder = document.createComment("removed-for-pdf");
        el.parentNode.replaceChild(placeholder, el);
        removed.push({ el, placeholder });
    });

    // 2. Render remaining DOM
    html2canvas(element, {
        scale: 2,
        backgroundColor: "#ffffff"
    }).then(canvas => {

        const imgData = canvas.toDataURL("image/png");
        const pdf = new jsPDF("p", "mm", "a4");

        const pageWidth = pdf.internal.pageSize.getWidth();
        const pageHeight = pdf.internal.pageSize.getHeight();

        const imgWidth = pageWidth;
        const imgHeight = (canvas.height * imgWidth) / canvas.width;

        let heightLeft = imgHeight;
        let position = 0;

        pdf.addImage(imgData, "PNG", 0, position, imgWidth, imgHeight);
        heightLeft -= pageHeight;

        while (heightLeft > 0) {
            position -= pageHeight;
            pdf.addPage();
            pdf.addImage(imgData, "PNG", 0, position, imgWidth, imgHeight);
            heightLeft -= pageHeight;
        }

        pdf.save("page-content.pdf");

        // 3. Restore removed elements
        removed.forEach(({ el, placeholder }) => {
            placeholder.parentNode.replaceChild(el, placeholder);
        });
    });
}