note 90534 modified in function.pdf-show-boxed by danbrown
| From: | danbrown@php.net | Date: | Mon, 27 Apr 2009 14:26:27 +0000 |
| Subject: | note 90534 modified in function.pdf-show-boxed by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153815@lists.php.net to get a copy of this message | ||
an example to illustrate the use of pdf_show_boxed(...).
<?php
$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.
--was--
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.
http://php.net/manual/en/function.pdf-show-boxed.php