Search
 
SCRIPT & CODE EXAMPLE
 

PHP

HTML to PDF in PHP

<?php require 'vendor/autoload.php';
use SpipuHtml2PdfHtml2Pdf;
$html2pdf = new Html2Pdf();
ob_start();
include('data.php');
$html_code = ob_get_clean();
$html2pdf->writeHTML($html_code);
$html2pdf->output();
?>
Comment

php html to pdf

Try php mpdf

  
CMD :    composer require mpdf/mpdf
  
  // Require composer autoload
require_once __DIR__ . '/vendor/autoload.php';
// Create an instance of the class:
$mpdf = new MpdfMpdf();

// Write some HTML code:
$mpdf->WriteHTML('Hello World');

// Output a PDF file directly to the browser
$mpdf->Output();
Comment

convert html to pdf using php.php

<?php
  //Step 1. Make a HTML file and define markup

  echo '
  <html>
<head>
<link href="style.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div id="wrapper">

<div id="html_div">
 <form action="generate_pdf.php" method="post">
  <input type="text" name="name" placeholder="Enter Name">
  <br>
  <input type="text" name="email" placeholder="Enter Email">
  <br>
  <input type="text" name="age" placeholder="Enter Age">
  <br>
  <input type="text" name="country" placeholder="Enter Country">
  <br>
  <input type="submit" name="submit_val" value="GENERATE PDF">
 </form>
</div>

</div>
</body>
</html>
';

//Step 2. Make a PHP file to generate PDF
namespace Dompdf;
require_once 'dompdf/autoload.inc.php';

if(isset($_POST['submit_val']))
{
$dompdf = new Dompdf(); 
$dompdf->loadHtml('
<table border=1 align=center width=400>
<tr><td>Name : </td><td>'.$_POST['name'].'</td></tr>
<tr><td>Email : </td><td>'.$_POST['email'].'</td></tr>
<tr><td>Age : </td><td>'.$_POST['age'].'</td></tr>
<tr><td>Country : </td><td>'.$_POST['country'].'</td></tr>
</table>
');
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream("",array("Attachment" => false));
exit(0);
}
?>
//CSS
body
{
 margin:0 auto;
 padding:0px;
 text-align:center;
 width:100%;
 font-family: "Myriad Pro","Helvetica Neue",Helvetica,Arial,Sans-Serif;
}
#wrapper
{
 margin:0 auto;
 padding:0px;
 text-align:center;
 width:995px;
}
#wrapper h1
{
 margin-top:50px;
 font-size:45px;
 color:#585858
}
#wrapper h1 p
{
 font-size:18px;
}
#wrapper a
{
 color:blue;
 font-size:20px;
}
#html_div input[type="text"]
{
 margin-top:5px;
 width:250px;
 height:35px;
 padding:10px;
}
#html_div input[type="submit"]
{
 background-color:#585858;
 width:250px;
 height:35px;
 border:none;
 margin-top:5px;
 color:white;
 margin-left:-5px;
}
Comment

convert html to pdf php

Important: Please note that this answer was written in 2009 and it might not be the most cost-effective solution today in 2019. Online alternatives are better today at this than they were back then.

Here are some online services that you can use:

PDFShift
Restpack
PDF Layer
DocRaptor
HTMLPDFAPI
HTML to PDF Rocket
Have a look at PrinceXML.

It's definitely the best HTML/CSS to PDF converter out there, although it's not free (But hey, your programming might not be free either, so if it saves you 10 hours of work, you're home free (since you also need to take into account that the alternative solutions will require you to setup a dedicated server with the right software)

Oh yeah, did I mention that this is the first (and probably only) HTML2PDF solution that does full ACID2 ?

PrinceXML Samples
Comment

PREVIOUS NEXT
Code Example
Php :: input if not null laravel 
Php :: php ternary operator good example 
Php :: get firstwod php 
Php :: how to update dropdown value in laravel 
Php :: PHP OOP - Abstract Classes 
Php :: stored procedure laravel 
Php :: phpdoc example 
Php :: laravel routes 
Php :: how to create object in php 
Php :: laravel request query logger 
Php :: laravel debugbar ServiceProvider to the providers 
Php :: upload image in laravel 8 store in database and folder 
Php :: inner pages not found yii 
Php :: readable var dump php 
Php :: formidableforms limit only 2 submissions per user 
Php :: Export database to sql dump in php 
Php :: movies -inurl:(htm|html|php|pls|txt) intitle:index.of “last modified” (mp4|wma|aac|avi) 
Php :: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:xampphtdocsJob Verificationlogin esult.php on line 38 
Php :: digitalocean php as text 
Php :: woocommerce php same skus 
Php :: Befreie den WordPress-Header von unnötigen Einträgen 
Php :: SQLSTATE[42S02]: Base table or view not found: 1146 Table many to many in laravel 
Php :: laravel request 
Php :: wordpress plugin public page 
Php :: import facade laravel 
Php :: Movie Name -inurl:(htm|html|php|pls|txt) intitle:index.of "last modified" (mp4|wma|aac|avi) 
Php :: how to remove public folder from url in laravel 8 
Php :: fix-wordpress-limit-permalink 
Php :: php curl fail verbosly 
Php :: php store html in varible 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =