Jump to content

download page as pdf by WRITEHTML


mdvignesh

Recommended Posts

How to download the page to pdf with changing alignment

 

I need to align the columns for the table

 

pur_report.php

 

<?php
$cnn = mysql_connect("localhost","root","");
mysql_select_db("stock",$cnn);
?>
<html><head>
<script src="jquery.min.js" type="text/javascript"></script>

<script type="text/javascript" src="datetimepicker.js"> </script>

<script src="js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">$(function() { 
    $("#from_purchase_date").date_input();
   $("#to_purchase_date").date_input();
});
function purchase_report_fn() 
{ 
window.open("view2.php?from_purchase_date="+$('#from_purchase_date').val()+"&to_purchase_date="+$('#to_purchase_date').val(),"myNewWinsr","width=800,height=600,toolbar=0,menubar=no,status=no,resizable=yes,location=no,directories=no,scrollbars=yes");
} 
</script>
</head>
<body>
<form method="get">
<input type="text" id="from_purchase_date" name="from_purchase_date">
<a href="javascript:NewCal('from_purchase_date','ddmmyyyy')">
<img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>

<input name="to_purchase_date" id="to_purchase_date" type="text">
<a href="javascript:NewCal('to_purchase_date','ddmmyyyy')">
<img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
<input type="button" onClick="purchase_report_fn();" value="Go">
</form>
</body>
</html>

 

view2.php

<?php
$cnn = mysql_connect("localhost","root","");
mysql_select_db("chms",$cnn);
?>
<html>
<head>
<style type="text/css">
table{width:100%;}
</style>
</head>
<body><?php if($_GET['from_purchase_date'] && $_GET['to_purchase_date']) { ?>
<div align="center"><b>Purchase Report</b></div>
<input name="prt" type="button" value="Print" onClick="javascript:window.print()" />
<hr/>
<?php 	
echo "From : ".$_GET['from_purchase_date'] ." "." 
To : ".$_GET['to_purchase_date']; 
?>
<hr/>
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th scope="col" align="center">Bill Number</th>
    <th scope="col" align="center">Supplier Name</th>
    <th scope="col" align="center">Quantity</th>
<th scope="col" align="center">Cost Price</th>
<th scope="col" align="center">Rate</th>
<th scope="col" align="center">Paid</th>
<th scope="col" align="center">Balance</th>
<th scope="col" align="center">Date</th>
<th scope="col" align="center">Due Date</th>
  </tr>
  <?php
  	$start = $_GET['from_purchase_date'];
$end = $_GET['to_purchase_date'];

$mysqldfor = array();
$fromDateTS = strtotime($start);
$toDateTS = strtotime($end);

for ($currentDateTS = $fromDateTS; $currentDateTS <= $toDateTS; $currentDateTS += (60 * 60 * 24)) {
	$currentDateStr = date("Y-m-d",$currentDateTS);
	$mysqldfor[] = $currentDateStr;
}
function dateconvert($date,$func) {	
if ($func == 2){ //output conversion
list($year, $month, $day) = explode('-', $date); 
$date = "$day-$month-$year"; 
return $date;
}
}
for($b = 0; $b < count($mysqldfor); $b++) {
	$gett = mysql_query("SELECT * FROM stock_entries where date between 
	'".$mysqldfor[$b]."' and '".$mysqldfor[$b]."' ");
	if(!$gett) die(mysql_error());
  while($dsa = mysql_fetch_array($gett)) { ?>
	<tr><td align="center"><?php echo $dsa['billnumber']; ?></td>
	<td align="center"><?php echo $dsa['stock_supplier_name']; ?></td>
	<td align="center"><?php echo $dsa['quantity']; ?></td>
	<td align="center"><?php echo $dsa['cost_price']; ?></td>
	<td align="center"><?php echo $dsa['total']; ?></td>
	<td align="center"><?php echo $dsa['payment']; ?></td>
	<td align="center"><?php echo $dsa['balance']; ?></td>
	<td align="center"><?php echo $newdate=dateconvert($dsa['date'],2)."<br/>";?></td>
	<td align="center"><?php echo $newdue=dateconvert($dsa['due'],2)."<br/>";?></td>
	</tr>
  <?php 
  }
  	} //closing for loop
  ?>
</table> <a href="download.php">download</a>
<?php
}
else
echo "No from and to dates";
?>
</body>
</html>

 

 

download.php

 

<?php
ob_start();
require('WriteHTML.php');
$pdf=new PDF_HTML();

$pdf->AddPage();
$pdf->SetFont('Arial');
$pdf->WriteHTML('<html> <body> <b>Purchase Report</b></div>
<hr/>
From : 9-3-2012  
To : 12-3-2012	<hr/>
<table border="0" cellspacing="0" cellpadding="0">

  <tr>
    <th scope="col" align="center">Bill Number</th>
    <th scope="col" align="center">Supplier Name</th>
    <th scope="col" align="center">Quantity</th>
<th scope="col" align="center">Cost Price</th>
<th scope="col" align="center">Rate</th>

<th scope="col" align="center">Paid</th>
<th scope="col" align="center">Balance</th>
<th scope="col" align="center">Date</th>
<th scope="col" align="center">Due Date</th>
  </tr>
  		<tr><td align="center">BN10007</td>

	<td align="center">xyz</td>
	<td align="center">5</td>
	<td align="center">10.00</td>
	<td align="center">50.00</td>
	<td align="center">0.00</td>
	<td align="center">50.00</td>

	<td align="center">09-03-2012<br/></td>
	<td align="center">09-03-2012<br/></td>
	</tr>
	</table>');

$pdf->Output("sample.pdf",'D');
ob_end_flush();
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.