note 90534 added to function.pdf-show-boxed
| From: | han__hui at hotmail dot com | Date: | Mon, 27 Apr 2009 07:46:43 +0000 |
| Subject: | note 90534 added to function.pdf-show-boxed | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153803@lists.php.net to get a copy of this message | ||
an example to illustrate the use of pdf_show_boxed(...).
$pdf = pdf_new();
pdf_set_parameter($pdf,"license","xxxxxxx-xxxxxx-xxxxxx-xxxxxx"); //to remove
the stamp/wartermark of the generated pdf file.
pdf_set_info($pdf, "Creator", "pdf.php");
pdf_set_info($pdf, "Author", "hui");
pdf_open_file($pdf,""); //without a file name, it will open the pdf file in the browser
directly.
pdf_begin_page($pdf,595,842); //A4 page
$font = pdf_findfont($pdf, "Helvetica", "host", 0);
$lineHeight = 10;
$y = 800;
pdf_setfont($pdf, $font, $lineHeight);
$text = "Hi, I am Hui.\n\rI am working in IT Dept.\nI am good at linux administration and
programming in Java, PHP, Javascript, C and C++.";
$ret = pdf_show_boxed($pdf,$text,30,$y,350,$lineHeight,"left","");
$lineSpace = 5;
while($ret>0) //write the whole text into the pdf line by line including the new line character
{
$y = $y - $lineHeight-$lineSpace;
$left = substr($text,-$ret);
if($left[0] == "\n" or $left[0] == "\r") $left = substr($left,1); //this line
decrements the $ret by 1.
$ret = pdf_show_boxed($pdf,$left,30,$y,350,$lineHeight,"left","");
}
pdf_end_page($pdf);
pdf_close($pdf);
$buf = pdf_get_buffer($pdf);
$len = strlen($buf);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=whatever.pdf");
print $buf;
?>
PS: Without "if" in the while loop, it will be an infinite loop when it encounters
"\n" or "\r" in the text to be written.
----
Server IP: 69.147.83.197
Probable Submitter: 83.91.196.102 (proxied: 127.0.0.1)
----
Manual Page -- http://www.php.net/manual/en/function.pdf-show-boxed.php
Edit -- https://master.php.net/note/edit/90534
Del: integrated -- https://master.php.net/note/delete/90534/integrated
Del: useless -- https://master.php.net/note/delete/90534/useless
Del: bad code -- https://master.php.net/note/delete/90534/bad+code
Del: spam -- https://master.php.net/note/delete/90534/spam
Del: non-english -- https://master.php.net/note/delete/90534/non-english
Del: in docs -- https://master.php.net/note/delete/90534/in+docs
Del: other reasons-- https://master.php.net/note/delete/90534
Reject -- https://master.php.net/note/reject/90534
Search -- https://master.php.net/manage/user-notes.php