Skip to content
Coding India Lab
  • PDF Tools
    JPG to PDF

    JPG to PDF

    PNG to PDF

    PNG to PDF

    WEBP to PDF

    WEBP to PDF

    Protect PDF File

    Protect PDF File

  • Category

    SVG Converter

    • PNG to SVG
    • JPG to SVG
    • WEBP to SVG
    • AVIF to SVG

    SEO Tool

    • HTML Heading Checker
    • Word Counter
    • Keyword Density Checker
    • Internal Link Checker
    • Meta Tags Analyzer
    • Meta Tags Generator

    Excel Converter

    • Excel to XML
    • Excel to HTML
    • Excel to JSON
    • JSON to Excel

    Social Downloader

    • Instagram Reel
    • Facebook Reel
    • Facebook Video
    • YouTube Thumbnail
    • Vimeo Thumbnail

    Text Converter

    • Lower Case To Upper Case
    • Remove Duplicate Words
    • Auto Capitalize Sentences
    • Online Text Editor

    Colors Converter

    • Hex To Pantone
    • RGB To Pantone
    • RGB to HEX
    • CSS Gradient Generator

    WEBP Converter

    • JPG To WEBP
    • PNG To WEBP
    • WEBP To JPG
    • WEBP To PNG

    Minify Generator

    • CSS Minify
    • HTML Minify
    • JS Minify
  • Calculator Tools
    • Cubic Feet
    • Volumetric weight
    • KG to Pound
    • Length unit converter
  • Pages
    • About Us
    • Privacy and Policy
    • Terms and Conditions
    • Disclaimer
    • Contact Us
  • Blog
How-to-Convert-Multiple-JPG-images-to-WEBP-1

How to Convert HTML table to JPG image using html CSS jQuery ?

admin, August 10, 2024February 22, 2025

Create an HTML to JPG Converter using HTML CSS JavaScript

In this blog, We have learn a simple application to convert HTML content or table to JPG image. To do this, we have used PHP for server-side logic, HTML codes, CSS for styling, and JavaScript for the conversion process.

Step 1: Setting Up the Project Structure

Create a new folder on your local system for your project and inside it, create the following files:

  • index.php
  • style.css
  • script.js

Your project structure should look like this:

/html-to-jpg
|– index.php
|– style.css
|– script.js

Step 2: HTML Details (index.php)

Go inside your folder open index.php and add the following code:

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>HTML to JPG Converter</title>
<link rel=”stylesheet” href=”style.css”>
<link rel=”stylesheet” href=”https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css”>
<script src=”https://cdnjs.cloudflare.com/ajax/libs/dom-to-image/2.6.0/dom-to-image.min.js”></script>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js”></script>
</head>
<body>
<main id=”main” class=”container main”>
<section class=”section dashboard”>
<div class=”row justify-content-center”>
<div class=”col-lg-10″>
<div class=”card p-4″>
<h1 class=”text-center”>HTML to JPG</h1>
<form action=”” method=”POST”>
<div class=”row mb-4″>
<div class=”col-md-8″>
<input type=”text” name=”product_title” id=”model_check” class=”form-control” autocomplete=”off” placeholder=”Search Here” value=””>
</div>
<div class=”col-md-4″>
<input type=”submit” name=”submit” value=”Convert” class=”button_check w-100″>
</div>
</div>
</form>
<?php if(isset($_POST[‘submit’])): ?>
<div id=”main_text”>
<div class=”text-end mb-3″>
<button id=”dw_bt”>Download to JPG</button>
</div>
<div id=”invoice” class=”box p-4 border rounded bg-white”>
<h2 class=”post_title mb-4″><?php echo htmlspecialchars($_POST[‘product_title’]); ?></h2>
<div class=”text-center mb-4″>

</div>
<div class=”row”>
<div class=”col-lg-6″>
<table class=”table table-bordered”>
<thead>
<tr>
<th colspan=”2″>Test One</th>
</tr>
</thead>
<tbody>
<tr>
<td>Conding India</td>
<td>Coding India Lab</td>
</tr>
<tr>
<td>Conding India</td>
<td>Coding India Lab</td>
</tr>
<!– Add more rows as needed –>
</tbody>
</table>
</div>
<div class=”col-lg-6″>
<table class=”table table-bordered”>
<thead>
<tr>
<th colspan=”2″>Test Two</th>
</tr>
</thead>
<tbody>
<tr>
<td>Conding India</td>
<td>Coding India Lab</td>
</tr>
<tr>
<td>Conding India</td>
<td>Coding India Lab</td>
</tr>
<!– Add more rows as needed –>
</tbody>
</table>
</div>
</div>
<div class=”row”>
<div class=”col-lg-6″>
<table class=”table table-bordered”>
<thead>
<tr>
<th colspan=”2″>Test Three</th>
</tr>
</thead>
<tbody>
<tr>
<td>Conding India</td>
<td>Coding India Lab</td>
</tr>
<tr>
<td>Conding India</td>
<td>Coding India Lab</td>
</tr>
<!– Add more rows as needed –>
</tbody>
</table>
</div>
<div class=”col-lg-6″>
<table class=”table table-bordered”>
<thead>
<tr>
<th colspan=”2″>Test Four</th>
</tr>
</thead>
<tbody>
<tr>
<td>Conding India</td>
<td>Coding India Lab</td>
</tr>
<tr>
<td>Conding India</td>
<td>Coding India Lab</td>
</tr>
<!– Add more rows as needed –>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</section>
</main>

Step 3: Adding CSS for Styling (style.css)

Open style.css and add the following code to style your page:

body {
background-color: #f8f9fa;
font-family: Arial, sans-serif;
}
.main {
margin-top: 50px;
}
.card {
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
font-weight: bold;
margin-bottom: 20px;
}
.form-control {
border-radius: 0;
box-shadow: none;
border: 1px solid #ced4da;
}
.button_check {
background-color: #007bff;
color: #fff;
border: none;
padding: 10px 20px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.button_check:hover {
background-color: #0056b3;
}
.image_data {
max-width: 100%;
height: auto;
margin-bottom: 20px;
}
.table th, .table td {
text-align: center;
vertical-align: middle;
padding: 15px;
border-color: #dee2e6;
}
.table th {
background-color: #007bff;
color: #fff;
}
.table {
margin-bottom: 30px;
}
#dw_bt {
background-color: #28a745;
color: #fff;
padding: 10px 20px;
border: none;
cursor: pointer;
border-radius: 5px;
transition: background-color 0.3s ease;
}
#dw_bt:hover {
background-color: #218838;
}

Step 4: JavaScript Details(script.js)

Open the script.js and add the following code to handle the conversion of HTML to JPG:

document.addEventListener(“DOMContentLoaded”, function() {
var ticket = document.getElementsByClassName(“box”)[0];
var download_button = document.getElementById(“dw_bt”);

if (ticket && download_button) {
download_button.addEventListener(“click”, () => {
domtoimage.toJpeg(ticket)
.then((data) => {
var link = document.createElement(“a”);
link.download = “download.jpg”;
link.href = data;
link.click();
})
.catch((error) => {
console.error(“An error occurred while generating the image:”, error);
});
});
} else {
console.error(“Element not found. Ensure that the element with class ‘box’ and the download button are rendered correctly.”);
}
});

 

Step 5: Run or test the HTML to JPG converter application on your local server or live server.
To run this application you have to open and run your local server xampp or you can upload all the files on your live server.

For the local server, Open a browser and navigate to http://localhost/html-to-jpg/. and for the live server go to your public_html root directory upload the all files on the server, and run https://yourdomain.com/html-to-jpg/. After running, you can enter the test in the input field and click on the button. After clicking you will see the HTML data and you can download it in JPG image format.

 

Output

HTML-to-JPG

html jquery php

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How Do I Copy Text from an Image?
  • How do you merge two PDF documents into one?
  • How to Bulk Convert Images to WebP For Free?
  • How to create a QR code for free?
  • How to Calculate Interest Rate Per Month?
  • Convert HTML Table To JPG Image Using Javascript
  • Convert Images Into WEBP Free Unlimited
  • Convert JPG Image To WEBP Format Using PHP Mysqli JQuery
  • Create GIF Images Using HTML JQuery
  • Resize Your Images Online Unlimited
  • How To Change PNG To WEBP Using PHP JQuery
  • Image To Video Converter Using HTML JQuery

Categories

  • birthday wishes
  • html
  • jquery
  • php
  • seo
  • social
  • tools
  • WordPress

Social Tools

  • Facebook Reel Downloader
  • Facebook Video Downloader
  • YouTube Thumbnail Downloader
  • Vimeo Thumbnail Downloader

Image Converter

  • Bulk JPEG To WEBP
  • Bulk JPG to WEBP
  • Bulk PNG to WEBP
  • Bulk WEBP to PNG
  • Bulk WEBP Converter

Text Converter

  • Character counter
  • Remove Duplicate Words
  • Word Counter
  • Small Text Generator
  • Reverse Text Generator

PDF Tools

  • JPG to PDF
  • PNG to PDF
  • WEBP to PDF
  • Protect PDF file
©2025 Blog | WordPress Theme by SuperbThemes

Copyright © 2025 Coding India Lab. All rights reserved.