Ask Your Question
1

Can the fpdf output be adjusted to allow the user to change the name according to their input?

asked 2021-12-18 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-09-20 22:00:00 +0000

pufferfish gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-12-18 11:00:00 +0000

Seen: 11 times

Last updated: Sep 20 '22