KidsLovePC Contact Us
  Home   PHP  Graphics ASP  JavaScript   J2EE  HTML  JAVA   Swing   Webtip  Forums  Lyric  Free sheet music  Ringtones

PHP Create PDF file on fly With ClibPDF

This tutorial demos how to create a PDF file on fly with ClibPDF.

Testing ClibPDF installation

First, you need test if your PHP supports ClibPDF or not. Copy the following code to a file (phpinfo.php) and save it in your web root. Then launch it like : http://your-web-site/phpinfo.php.

<?php
phpinfo();
?>

 

If your PHP supports ClibPDF, you will see an section looks like the following image:

php create dynamic pdf with cpdflib

Get input from Client

We will put client input into our PDF dynamically. Use the following code to get client input.

<html>
<head>
<title>Name Entry Level</title>
</head>
<body>
<table>
<tr>
<td>
<form method="POST" action="cpdfdemo.php">

Enter your text here please =>
<input type="text" name="input" size="20" maxlength="20">

<input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset">

</form>
</td>
</tr>
</table>
</body>
</html>

Create PDF with CPDF

We use the following code to create PDF. Save the following code as cpdfdemo.php.

<?php

if(isset($_POST['submit'])
{
$mytext=$_POST[' input'];
$cpdf = cpdf_open(0);

cpdf_page_init($cpdf, 1, 0, 595, 842, 1.0);

cpdf_add_outline($cpdf, 0, 0, 0, 1, "Page 1");

//write text
cpdf_setrgbcolor ($cpdf,255,0,255);
cpdf_begin_text($cpdf);
cpdf_set_font($cpdf, "Times-Roman", 30, "WinAnsiEncoding");
cpdf_set_text_rendering($cpdf, 2);
cpdf_text($cpdf, $mytext, 50, 340);

cpdf_end_text($cpdf);

//draw a blue line
cpdf_setrgbcolor ($cpdf,0,0,255); //blue line
cpdf_moveto($cpdf, 50, 50);
cpdf_lineto($cpdf, 740, 330);
cpdf_stroke($cpdf);

//draw a red circle
cpdf_setrgbcolor ($cpdf,255,0,0); //color read
cpdf_circle($cpdf,200,200,50);
cpdf_stroke($cpdf);

cpdf_finalize_page($cpdf, 1);
cpdf_finalize($cpdf);

Header("Content-type: application/pdf");
cpdf_output_buffer($cpdf);
cpdf_close($cpdf);
}
?>

$_POST['xxx'] gets parameters from client.

cpdf_open opens a PDF file.

cpdf_page_init set PDF sizes: A4 is 595 x 842, Letter is 612 x 792 and Legal is 612 x 1008.

cpdf_add_outline adds bookmark for current page.

cpdf_setrgbcolor sets color for next drawing action.

The following code are annotated in the code.

 

PHP Calendar
Comprehensive PHP Web Calendar
Configurable PHP Calendar
PHP Calendar
PHP Image Processing
PHP grahic softwares
PHP create real-time dynamic chart
create antispam image(image verification)
Add water mark to image
PHP Image processing introduction
Add text on Image
Create thumbnail for image
Create image from text on fly
PHP code sample
PHP create dynamic PDF with FPDF
PHP create dynamic PDF with PDFLib
PHP create dynamic PDF with ClibPDF
Improved PHP configurable hit counter
Install phpMyAdmin,MySql, PHP
PhpMyAdmin export/import data
A simple PHP RSS feed reader
PHP include (SSI)
Working with Forms
PHP formmail Generator
Using phpMyAdmin Create Database
Insert Form Data into Database
Retrieve data from Database
Retrieve multiple records
Batch insert text using phpMyAdmin
Using phpMyAdmin insert binary file
Insert binary file using PHP code
Using form insert binary file into MySQL
Retrieve binary file from MySQL
Image hosting business in minutes
Send HTML mail in PHP
Send bulk emails in PHP
Polling/Rating System in PHP
Polling/Rating System in PHP(radio button)
Check visitor's IP address
Check reciprocal link
PHP tutorial
What is PHP?
Install PHP on Windows XP (part1)
Install PHP on Windows XP (part2)
PHP open and closing tags
PHP types
Variables
Constants
Operators(part1)
Operators(part2)
Logic Structures
Include files
Loops
Set cookie and delete cookie
Most often used MySQL functions

 

 

Printer Inkjet A Z lyricsLearn ChineseHome|PHP|Swing|HTML|JavaScript|ASP|JAVA|Forum|WebTip|Contact Us
Copyright © kidslovepc.com All rights reserved(new). Privacy|Copyright
designed by info@kidslovepc.com

Please help us cover the web site maintenance fee.
barcode scanner Thermal Printer credit card machine bar code printer