Monday, October 19, 2009

Create pdf file uisng php

CREATE AN PDF

$pdf = pdf_new();

OPRN FILE

pdf_open_file($pdf);

SET THE INFORMATION
pdf_set_info($pdf, "Author","SIMON");

SET THE TITLE

pdf_set_info($pdf, "Title","TITLE GOES HERE");

BEGIN THE PAGE

pdf_begin_page($pdf, 300, 300);

SAVE PDF

pdf_save($pdf);

MOVE THE ORGIN

pdf_translate($pdf, 100, 100);

ROTATE BY 45 DEGREES

pdf_rotate($pdf, 45);

DRAW A SMALL RECTANGLE
pdf_rect($pdf, 0, 0, 20, 20);

KEEP THE STROKE
pdf_stroke($pdf);

SET THE PREVIOUS STAGE
pdf_restore($pdf);

SAVE THE PDF

END THE PDF PAGE
pdf_end_page($pdf);

pdf_close($pdf);

$data = pdf_get_buffer($pdf);

header('Content-type: application/pdf');

header('Content-disposition: inline; filename=simon.pdf');

header('Content-length: ' . strlen($data));

echo $data;
?>