0

Good day all:

Is there a mechanism through which I can have a button on my html form which on click calls a script that converts the form (or the html page) into a pdf file and inserts the file into mysql table with a specified name originating from the form itself (ie: within the html form, there is a field called clientid, on insert into db, it is uses this field value to reference the new record.

Not sure if this is doable; however, I appreciate any thoughts on this.
Mossa

Edited by mbarandao: n/a

3
Contributors
9
Replies
18
Views
6 Years
Discussion Span
Last Post by chrishea
0

Converting to PDF isn't too difficult:

http://html2pdf.fr/

You will need to save your output into a variable and then pass it to HTML2PDF to convert it. Saving to MySQL is up to you. Saving to a file is probably a bit simpler. If you need to save it to a database then you have the choice of saving the report output in HTML and converting to PDF when you need to, or, saving it as a PDF directly.

0

Chris, thanks for the reply. I see that the link is in french--tu parle francais? took french is school many years ago, can speak it but can't write it that well. Anyway thanks for the post, I'll explore the site.

Edited by mbarandao: n/a

0

If you look for the British flag on the upper right of their home page it takes you to the english version.

0

Yes, I was able locate the english version --my comment concerning french was a slight deviation.

I'm finding it difficult to understand the conversion's implementation. Essentially, I want to be able have a button on the page that calls a script to perform the conversion and the mysql insertion. I have searched on the site for more instruction, but have been unable find anything. Are you familiar the process --and can expound a little more?

Edited by mbarandao: n/a

1

It's actually pretty easy. Based on the first example they provide with the package, here is the code with a few extra comments

<?PHP
        // first get the html that is to be converted
        // they have them all as separate files but it could be a variable that you
        // built within this program 	
        ob_start();
 	include(dirname(__FILE__).'/res/exemple00.php');
	$content = ob_get_clean();
	
	// conversion HTML => PDF
        // you need to include the class module and then give it a few commands 
	require_once(dirname(__FILE__).'/../html2pdf.class.php');
	try
	{
		$html2pdf = new HTML2PDF();     // you can use the default parms
		$html2pdf->setDefaultFont('Arial');
		$html2pdf->writeHTML($content);
		$html2pdf->Output('example00.pdf');
	}
	catch(HTML2PDF_exception $e) { echo $e; }
?>

I think that Arial is the default font so you probably don't even need that. The key to getting it converted is to give it valid HTML. That means that it needs opening and closing tags for html statements. It does a pretty good job but it doesn't handle everything. I've done some of my own examples to understand the features better. I suggest that you do a little experimenting as a way of learning it better. If you have a specific problem I may be able to help.

With respect to mysql: if that's where you want to save it, then I think it would be simpler to save the HTML (probably in a blob field). I think that the html will probably take less space and you can easily re-create the PDF when you need it. This facility is made to produce an output file. If you really want to capture the PDF as a variable and then save that to MySQL you'll have to experiment and maybe make some changes. I don't think it's worth it to do that.

0

Thanks Chris for providing further explanation --it makes more sense.

More specifically for my need: can the desired html page to be converted have dynamic urls? Here what I mean:

I have an html editable invoice -located on line, which serves as a receipt for clients. Basically, I want to store a copy of the generated receipt as a digital record. So essentially, once the receipt has been physically printed, I want to click save and have this conversion process take place. Thus, to my earlier question concerning dynamic html page address, could I pass the url of a particular receipt to the converter?

I'll play around with it to see. But the above description is my intent.

Again, thanks for your time!
Mossa

0

Hi, i want to know from the code below, how to add a simple print PDF? sorry i managed to create this page but now the client wants to save it in PDF to email thier clients.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

	<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
	
	<title>Invoice</title>
	
	<link rel='stylesheet' type='text/css' href='css/style.css' />
	<link rel='stylesheet' type='text/css' href='css/print.css' media="print" />
	<script type='text/javascript' src='js/jquery-1.3.2.min.js'></script>
	<script type='text/javascript' src='js/example.js'></script>

</head>

<body>

	<div id="page-wrap">

		<textarea id="header"></textarea>
		
		<div id="identity">
		
            <textarea id="address">Senders address</textarea>

            <div id="logo">

              <div id="logoctr">
                <a href="javascript:;" id="change-logo" title="Change logo">Change Logo</a>
                <a href="javascript:;" id="save-logo" title="Save changes">Save</a>
                |
                <a href="javascript:;" id="delete-logo" title="Delete logo">Delete Logo</a>
                <a href="javascript:;" id="cancel-logo" title="Cancel changes">Cancel</a>
              </div>

              <div id="logohelp">
                <input id="imageloc" type="text" size="50" value="" /><br />
                (max width: 540px, max height: 100px)
              </div>
              <img id="image" src="images/logo.png" alt="logo" />
            </div>
		
		</div>
		
		<div style="clear:both"></div>
		
		<div id="customer">

            <textarea id="customer-title">Client details
go here</textarea>

            <table id="meta">
                <tr>
                    <td class="meta-head">Invoice #</td>
                    <td><textarea>000123</textarea></td>
                </tr>
                <tr>

                    <td class="meta-head">Date</td>
                    <td><textarea id="date">December 15, 2009</textarea></td>
                </tr>
                <tr>
                    <td class="meta-head">Amount Due</td>
                    <td><div class="due">£875.00</div></td>
                </tr>

            </table>
		
		</div>
		
		<table id="items">
		
		  <tr>
		      <th>Item</th>
		      <th>Description</th>
		      <th>Unit Cost</th>
		      <th>Quantity</th>
		      <th>Price</th>
		  </tr>
		  
		  <tr class="item-row">
		      <td class="item-name"><div class="delete-wpr"><textarea>Pickup</textarea><a class="delete" href="javascript:;" title="Remove row">X</a></div></td>
		      <td class="description"><textarea>Type here</textarea></td>
		      <td><textarea class="cost">£650.00</textarea></td>
		      <td><textarea class="qty">1</textarea></td>
		      <td><span class="price">£650.00</span></td>
		  </tr>
		  
		  <tr class="item-row">
		      <td class="item-name"><div class="delete-wpr"><textarea>Destination</textarea><a class="delete" href="javascript:;" title="Remove row">X</a></div></td>

		      <td class="description"><textarea>Type Here</textarea></td>
		      <td><textarea class="cost">£75.00</textarea></td>
		      <td><textarea class="qty">1</textarea></td>
		      <td><span class="price">£225.00</span></td>
		  </tr>

		  <tr class="item-row">
		      <td class="item-name"><div class="delete-wpr"><textarea>Waiting Time</textarea><a class="delete" href="javascript:;" title="Remove row">X</a></div></td>

		      <td class="description"><textarea>Type Here</textarea></td>
		      <td><textarea class="cost">£75.00</textarea></td>
		      <td><textarea class="qty">1</textarea></td>
		      <td><span class="price">£225.00</span></td>
		  </tr>
		  
		  <tr id="hiderow">
		    <td colspan="5"><a id="addrow" href="javascript:;" title="Add a row">Add a row</a></td>
		  </tr>
		  
		  <tr>
		      <td colspan="2" class="blank"> </td>
		      <td colspan="2" class="total-line">Subtotal</td>
		      <td class="total-value"><div id="subtotal">£875.00</div></td>
		  </tr>
		  <tr>

		      <td colspan="2" class="blank"> </td>
		      <td colspan="2" class="total-line">Total</td>
		      <td class="total-value"><div id="total">£875.00</div></td>
		  </tr>
		  <tr>
		      <td colspan="2" class="blank"> </td>
		      <td colspan="2" class="total-line">Amount Paid</td>

		      <td class="total-value"><textarea id="paid">£0.00</textarea></td>
		  </tr>
		  <tr>
		      <td colspan="2" class="blank"> </td>
		      <td colspan="2" class="total-line balance">Balance Due</td>
		      <td class="total-value balance"><div class="due">£875.00</div></td>
		  </tr>
		
		</table>
		
		<div id="terms">
		  <h5>Terms</h5>
		  <textarea>NET 30 Days. Finance Charge of 1.5% will be made on unpaid balances after 30 days.</textarea>
		</div>
	
	</div>


</body>

</html>

any help will be great, i created this long time ago but i had notes at that time but not anymore.

thanks

sh4bbz

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.