Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, you can allow the user to input a name and then use it dynamically to generate the PDF output. For example, you can create an input field where the user can enter their name:

<label for="name">Enter your name:</label>
<input type="text" id="name" name="name">
<button onclick="generatePdf()">Generate PDF</button>

Then, in your JavaScript code, you can use the entered name to generate the PDF output:

function generatePdf() {
    // Get the entered name
    var name = document.getElementById("name").value;

    // Create a new FPDF object
    var pdf = new FPDF();

    // Add a new page
    pdf.addPage();

    // Set the font and font size
    pdf.setFont("Arial", "B", 16);

    // Add the name to the PDF
    pdf.cell(0, 10, "Hello " + name + "!", 0, 1);

    // Output the PDF as a data URI
    var pdfOutput = pdf.output("datauristring");

    // Display the PDF in the browser
    window.open(pdfOutput);
}

This way, the user can input their name and the PDF output will be dynamically generated with their name included.