Jump to content

Recommended Posts

as far i compare, mpdf is quite amazing, simple and easy. others conversion library is tcpdf, fpdf, dompdf, wkhtml2pdf..

so far, only fpdf and mpdf can convert the php to pdf. 

 

i try to convert a php form to pdf.

for example when we want to book a flight ticket. after the booking process, we will get the booking details in pdf form.

any idea how to implement the pdf in php form? 

??

I think you are saying you want to create a pdf out the html on your screen.  (There is NO php on your client screen, only HTML).

 

Using fpdf you create the pdf from your data in a php script without using html.  Fpdf has several functions that you use to output your data according to how you want the pdf to appear when done.  Then you output the new pdf file to a separate screen (target) or else be sure you do not send any other output to the current window.

Edited by ginerjm

I picked up fpdf and figured it out.  It's not that hard - reminds of the days when I used to program Cobol and had to lay out reports by hand and then program to fit the layout. 

yea, not that hard. just quite hard to adjust table content.

 

I don't see what that has to do with it, wkhtml2pdf is a command line program but anyway...

 

Composer has a manual. https://getcomposer.org/doc/00-intro.md

ok.. that wkhtml2pdf is some sort of software that convert the html page to pdf? yes, its simple. but its not what i want. because the user need to install wkhtml2pdf on the pc. else, cant print out pdf report

Don't understand what you mean about adjusting table content.  With fpdf you design the output the way you want it.  If you want to do a table it's not much different than an html table.  Just set up the widths of the columns to be on your pdf report and use them for each of the cells in each row of the pdf table.  No different than the <col> tags of an html table

No. You install wkhtml2pdf on the server. It's all done server side.

 

oh i see. good tips.. tyvm... well, i almost finish my industrial attachment and had to present it next week. the only problems now is this pdf matter.. try see the attachment i put below. 

i did try wkhtml2pdf.. it works awesome. easily generate.. 

 

Don't understand what you mean about adjusting table content.  With fpdf you design the output the way you want it.  If you want to do a table it's not much different than an html table.  Just set up the widths of the columns to be on your pdf report and use them for each of the cells in each row of the pdf table.  No different than the <col> tags of an html table

fpdf had to design the table. else, it bcme awful. lol... so, my last resolution is using html2pdf after many tries using mPDF, fpdf, dompdf and TCPDF.  as you see in my file attachment below, i'm adjusting the font and the alignment of the pdf..  not yet put sql command as i want to make it look nice then i will put sql command. 

post-167866-0-68282400-1395128047_thumb.jpg

Hi kova,

 

try this and hope it will help you.

 

pdf_lib.php

<?php	
	function phptopdf_url($source_url,$save_directory,$save_filename)
	{		
		$API_KEY = 'egtyuhes66r8rb3v5';
                $url = 'http://phptopdf.com/urltopdf.php?key='.$API_KEY.'&url='.urlencode($source_url);
		$resultsXml = file_get_contents(($url)); 		
		file_put_contents($save_directory.$save_filename,$resultsXml);
	}
	function phptopdf_html($html,$save_directory,$save_filename)
	{		
		$API_KEY = 'egtyuhes66r8rb3v5';
                $postdata = http_build_query(
			array(
				'html' => $html,
				'key' => $API_KEY
			)
		);
		
		$opts = array('http' =>
			array(
				'method'  => 'POST',
				'header'  => 'Content-type: application/x-www-form-urlencoded',				
				'content' => $postdata
			)
		);
		
		$context  = stream_context_create($opts);
		
		
		$resultsXml = file_get_contents('http://phptopdf.com/htmltopdf.php', false, $context);
		file_put_contents($save_directory.$save_filename,$resultsXml);
	}
?>

index.php

<?php
 include_once('pdf_lib.php') ;

$html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<body> 
<p>page page page page</p>
</body>
</html>';

phptopdf_html($html,'my_pdf_filename.pdf');
echo "<a href='filename.pdf'>Download PDF</a>";
?> 


phptopdf_html($html,'pdf/', 'my_pdf_filename.pdf');
echo "<a href='pdf/my_pdf_filename.pdf'>Download PDF</a>";

 

Hi kova,

 

try this and hope it will help you.

 

pdf_lib.php

<?php	
	function phptopdf_url($source_url,$save_directory,$save_filename)
	{		
		$API_KEY = 'egtyuhes66r8rb3v5';
                $url = 'http://phptopdf.com/urltopdf.php?key='.$API_KEY.'&url='.urlencode($source_url);
		$resultsXml = file_get_contents(($url)); 		
		file_put_contents($save_directory.$save_filename,$resultsXml);
	}
	function phptopdf_html($html,$save_directory,$save_filename)
	{		
		$API_KEY = 'egtyuhes66r8rb3v5';
                $postdata = http_build_query(
			array(
				'html' => $html,
				'key' => $API_KEY
			)
		);
		
		$opts = array('http' =>
			array(
				'method'  => 'POST',
				'header'  => 'Content-type: application/x-www-form-urlencoded',				
				'content' => $postdata
			)
		);
		
		$context  = stream_context_create($opts);
		
		
		$resultsXml = file_get_contents('http://phptopdf.com/htmltopdf.php', false, $context);
		file_put_contents($save_directory.$save_filename,$resultsXml);
	}
?>

index.php

<?php
 include_once('pdf_lib.php') ;

$html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<body> 
<p>page page page page</p>
</body>
</html>';

phptopdf_html($html,'my_pdf_filename.pdf');
echo "<a href='filename.pdf'>Download PDF</a>";
?> 


phptopdf_html($html,'pdf/', 'my_pdf_filename.pdf');
echo "<a href='pdf/my_pdf_filename.pdf'>Download PDF</a>";

thanks.. but no output shown :

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.