What's new
HTML Forums | An HTML and CSS Coding Community

Welcome to HTMLForums; home of web development discussion! Please sign in or register your free account to get involved. Once registered you will be able to connect with other members, send and receive private messages, reply to topics and create your very own. Our registration process is hassle-free and takes no time at all!

Making a html form from pdf


New member
Hi everyone, I'm very new to HTML/CSS and am trying to figure out how to do this. I have a pdf which I want to make into html form and have created the backend to where the fields are submitted (mysql database) so I have created fields from pdf. How do I make the form look like this? How do I put borders around all fields and adjust the spacing between each field?

Screenshot 2023-12-14 125756.png

Honestly your best bet is to make this form fillable using an online PDF editor. Then embed the editor into a webpage and use PHP to instruct the site to provide a blank from the master of this form for each new applicant. Then instruct the PHP to automatically save this form under a specified file name in each applicant's home directory or web directory, after a user fills it out, to be accessible later. Using html and CSS is going to be difficult at best to make this look the same especially in regards to responsiveness and the like.

This would also remove the need to utilize a SQL database to store your responses. You would still need the database to handle users and authentication as well as storing whether or not a specific user has already filled the form out and where the completed forms and the master form is located.

By doing this way, you would also save yourself a legal headache as it is easier and more convenient to print a filled pdf rather than an HTML page with the responses.
However, if you truly want it to be the way you are describing, you can utilize PHP to parse the form data from the pdf and dynamically generate the HTML form fields based off the pdf. The following code is a basic example of what you can do but it is a very complex and time consuming process.


require_once 'vendor/autoload.php'; // Include PDF parsing library (e.g., Spatie\PdfParser\PdfParser)

function pdfToForm($pdfPath) {
  // Parse the PDF
  $parser = new PdfParser($pdfPath);
  $pages = $parser->getPages();

  // Initialize empty form
  $form = '<form method="post">';

  // Loop through pages and extract form fields
  foreach ($pages as $page) {
    $text = $page->getText();
    $fields = [];

    // Regular expression to match field names and values (adjust as needed)
    preg_match_all('/^(.*?):\s*(.*?)$/m', $text, $matches, PREG_SET_ORDER);

    foreach ($matches as $match) {
      $fieldName = trim($match[1]);
      $fieldValue = trim($match[2]);

      // Determine field type based on name (e.g., checkbox, radio)
      $fieldType = 'text';
      if (stripos($fieldName, '[]') !== false) {
        $fieldType = 'checkbox';

      // Generate HTML form element
      $fieldHtml = '<label for="' . $fieldName . '">' . $fieldName . '</label>';
      $fieldHtml .= '<input type="' . $fieldType . '" name="' . $fieldName . '" value="' . $fieldValue . '">';

      // Add field to the form
      $fields[] = $fieldHtml;

    // Add page fields to the form
    $form .= '<fieldset>';
    $form .= implode('<br>', $fields);
    $form .= '</fieldset>';

  // Close the form
  $form .= '</form>';

  // Return the generated HTML form
  return $form;

// Example usage
$pdfPath = 'path/to/your/pdf.pdf';
$htmlForm = pdfToForm($pdfPath);

// Output the HTML form
echo $htmlForm;

Last edited: