What's new

Welcome to the forum 👋, Visitor

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

Making a html form from pdf

pintu1228

New member
Joined
Dec 14, 2023
Messages
1
Reaction score
0
HTML Coins
0
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


Thanks
 
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.

Code:
<?php

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:

Theme customization system

You can customize some areas of the forum theme from this menu.

  • Wide/Narrow view

    You can control a structure that you can use to use your theme wide or narrow.

    Grid view forum list

    You can control the layout of the forum list in a grid or ordinary listing style structure.

    Picture grid mode

    You can control the structure where you can open/close images in the grid forum list.

    Close sidebar

    You can get rid of the crowded view in the forum by closing the sidebar.

    Fixed sidebar

    You can make it more useful and easier to access by pinning the sidebar.

    Close radius

    You can use the radius at the corners of the blocks according to your taste by closing/opening it.

  • Choose the color combination that reflects your taste
    Background images
    Color gradient backgrounds
Back