0% found this document useful (0 votes)
6 views3 pages

WBP22202A0023PR07

Uploaded by

guyn9074
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

WBP22202A0023PR07

Uploaded by

guyn9074
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

IF6IA WBP

DEPARTMENT OF INFORMATION TECHNOLOGY

Subject: Web based Application Development Subject Code: 22619


using PHP
Semester: 6th Course: IF6IA
Laboratory No: L001 Name of Teacher: Chetashri Bhusari
Name of Student: Prajwal Patekar Roll ID: 2220A0023

Experiment No: 7
Title of Experiment Write a simple PHP program to create PDF document buy using graphics
concepts

☆ Practical Related Questions


1. Write use of various graphics functions.
Ans:
imagecreatetruecolor() Creates a blank image with true color.
imagecolorallocate() Allocates a color for an image.
imageline() Draws a line between two points.
imageellipse() Draws an ellipse (circle).
imagerectangle() Draws a rectangle.
imagefilledrectangle() Draws a filled rectangle.
imagepng() Outputs the image in PNG format.
imagejpeg() Outputs the image in JPEG format.
imagedestroy() Frees memory after image creation.

Example:
<?php
// Create an image (300x200 pixels)
$image = imagecreatetruecolor(300, 200);
// Allocate colors
$white = imagecolorallocate($image, 255, 255, 255);
$red = imagecolorallocate($image, 255, 0, 0);
$blue = imagecolorallocate($image, 0, 0, 255);

// Fill background with white


22202A0023 Prajwal Patekar
IF6IA WBP

imagefill($image, 0, 0, $white);
// Draw a red rectangle
imagerectangle($image, 50, 50, 250, 150, $red);
// Draw a blue ellipse (circle)
imageellipse($image, 150, 100, 100, 100, $blue);
// Set content type and output the image
header("Content-Type: image/png");
imagepng($image);
// Free memory
imagedestroy($image);
?>
Output:

22202A0023 Prajwal Patekar


IF6IA WBP

☆ Exercise

1. Write a program to create pdf file using PHP.

Ans:
<?php
require('fpdf.php'); // Include the FPDF library
// Create a new PDF instance
$pdf = new FPDF();
$pdf->AddPage(); // Add a page
// Set font (Arial, Bold, Size 16)
$pdf->SetFont('Arial', 'B', 16);
// Add title
$pdf->Cell(190, 10, 'Hello, This is a PDF File!', 1, 1, 'C');
// Set font for body
$pdf->SetFont('Arial', '', 12);
$pdf->Ln(10); // Line break
$pdf->Cell(190, 10, 'This PDF is generated using PHP and FPDF.', 0, 1, 'C');
// Output the PDF to browser
$pdf->Output('example.pdf', 'I'); // 'I' to display in browser, 'D' to download
?>

22202A0023 Prajwal Patekar

You might also like