/** * Set the color * * Sets the current color in the PDF document. For valid color formats * see the README file. * * @param mixed $color the color to set * * @access private */ function setcolor($color) { if (!is_array($color)) { PDF_setcolor($this->pdf, "both", "gray", $color, 0, 0, 0); } else { switch (sizeof($color)) { case 1: PDF_setcolor($this->pdf, "both", "gray", $color[0], 0, 0, 0); break; case 3: PDF_setcolor($this->pdf, "both", "rgb", $color[0], $color[1], $color[2], 0); break; case 4: PDF_setcolor($this->pdf, "both", "cmyk", $color[0], $color[1], $color[2], $color[3]); break; } } }
PDF_lineto($p, $RADIUS / 2, 0.0); PDF_lineto($p, -$RADIUS / 10, $RADIUS / 20); PDF_closepath($p); PDF_fill($p); PDF_restore($p); /* draw minute hand */ PDF_save($p); PDF_rotate($p, -($ltime['seconds'] / 60.0 + $ltime['minutes'] - 15.0) * 6.0); PDF_moveto($p, -$RADIUS / 10, -$RADIUS / 20); PDF_lineto($p, $RADIUS * 0.8, 0.0); PDF_lineto($p, -$RADIUS / 10, $RADIUS / 20); PDF_closepath($p); PDF_fill($p); PDF_restore($p); /* draw second hand */ PDF_setcolor($p, "fillstroke", "rgb", 1.0, 0.0, 0.0, 0.0); PDF_setlinewidth($p, 2); PDF_save($p); PDF_rotate($p, -(($ltime['seconds'] - 15.0) * 6.0)); PDF_moveto($p, -$RADIUS / 5, 0.0); PDF_lineto($p, $RADIUS, 0.0); PDF_stroke($p); PDF_restore($p); /* draw little circle at center */ PDF_circle($p, 0, 0, $RADIUS / 30); PDF_fill($p); PDF_restore($p); PDF_end_page($p); /* close page */ PDF_close($p); /* close PDF document */
<?php $p = PDF_new(); PDF_open_file($p); PDF_begin_page($p, 595, 842); PDF_setcolor($p, "fill", "rgb", 1.0, 0.8, 0.1); PDF_moveto($p, 150, 750); PDF_lineto($p, 450, 750); PDF_lineto($p, 100, 800); PDF_curveto($p, 80, 500, 70, 550, 250, 650); PDF_closepath($p); PDF_fill_stroke($p); PDF_end_page($p); PDF_close($p); $buf = PDF_get_buffer($p); $len = strlen($buf); Header("Content-type:application/pdf"); Header("Content-Length:{$len}"); Header("Content-Disposition:inline; filename=gra2.pdf"); echo $buf; PDF_delete($p);
/** * Output the barcode * * Puts the barcode specified via settext() onto the PDF document. * The barcode is scaled to fit into the specified space. * * @param float $xpos The left starting position * @param float $ypos The top starting position * @param float $width The width of the barcode * @param float $height The height of the barcode * * @access public */ function putcode($xpos, $ypos, $width, $height) { switch ($this->type) { default: case '39': // code 39: narrow=4, wide=11, quiet=7 $narrow = 4; $wide = 11; $quiet = 7; $convtable[0] = $narrow; $convtable[1] = $wide; $convtable[2] = $quiet; $text = $this->text; $codes = array(); array_push($codes, $this->char2code39('START')); for ($i = 0; $i < strlen($text); $i++) { array_push($codes, $this->char2code39(substr($text, $i, 1))); } array_push($codes, $this->char2code39('STOP')); $code = implode('2', $codes); // Total width is the sum of: // - Widths of the characters' barcode representation (plus // start/stop characters) // - Widths of the blank spaces between them $fullwidth = (strlen($text) + 2) * (6 * $narrow + 3 * $wide) + (strlen($text) + 1) * $quiet; $basewidth = $width / $fullwidth; break; case '25i': $narrow = 1; $wide = 2; $convtable[0] = $narrow; $convtable[1] = $wide; $text = $this->text; // The length of the text must be even; if not, we // pad it with a leading "0" if (strlen($text) % 2 != 0) { $text = "0" . $text; } $code = $this->char2code25i('START'); for ($i = 0; $i < strlen($text); $i += 2) { $code1 = $this->char2code25i(substr($text, $i, 1)); $code2 = $this->char2code25i(substr($text, $i + 1, 1)); // Interleaved code: Shake 'em up! for ($j = 0; $j < 5; $j++) { $code .= substr($code1, $j, 1); $code .= substr($code2, $j, 1); } } $code .= $this->char2code25i('STOP'); // Total width is the sum of: // - Widths of the start/stop characters (6*narrow+1*wide) // - Widths of the characters' barcode representation $fullwidth = strlen($text) * (3 * $narrow + 2 * $wide) + 6 * $narrow + 1 * $wide; $basewidth = $width / $fullwidth; break; case '128a': case '128b': case '128c': $convtable[1] = 1; $convtable[2] = 2; $convtable[3] = 3; $convtable[4] = 4; $text = $this->text; switch ($this->type) { case '128a': $char2code128index = char2code128aindex; break; case '128b': $char2code128index = char2code128bindex; break; case '128c': $char2code128index = char2code128cindex; // The length of the text must be even; if not, we // pad it with a leading "0" if (strlen($text) % 2 != 0) { $text = "0" . $text; } break; } $checksum = 0; $index = $this->{$char2code128index}('START'); $code = $this->code128table[$index]; $checksum += $index; for ($i = 0; $i < strlen($text); $i++) { if ($this->type == '128c') { // 128c encodes two chars in one go $index = $this->{$char2code128index}(substr($text, $i, 2)); $i++; } else { $index = $this->{$char2code128index}(substr($text, $i, 1)); } $code .= $this->code128table[$index]; $checksum += ($i + 1) * $index; } // Calculate and output the code 128 checksum $checksum %= 103; $code .= $this->code128table[$checksum]; $index = $this->{$char2code128index}('STOP'); $code .= $this->code128table[$index]; // Total width is the sum of: // - Widths of the start character's barcode representation (11) // - Widths of the text characters' barcode representation (11) // - Widths of the checksum character's barcode representation (11) // - Widths of the stop character's barcode representation (13) $fullwidth = (strlen($text) + 2) * 11 + 13; $basewidth = $width / $fullwidth; break; } $black = true; for ($i = 0; $i < strlen($code); $i++) { $barwidth = $convtable[$code[$i]] * $basewidth; if ($black) { PDF_setcolor($this->pdf, "both", "gray", 0, 0, 0, 0); PDF_setlinecap($this->pdf, 0); PDF_setlinewidth($this->pdf, $barwidth); PDF_moveto($this->pdf, $xpos + 0.5 * $barwidth, $ypos); PDF_lineto($this->pdf, $xpos + 0.5 * $barwidth, $ypos - $height); PDF_stroke($this->pdf); } $xpos += $barwidth; $black = !$black; } return 1; }
PDF_begin_page($p, 595, 842); $font = PDF_findfont($p, "Helvetica-Bold", "host", 0); PDF_setfont($p, $font, 38.0); PDF_set_parameter($p, "overline", "true"); PDF_show_xy($p, "Overlined Text", 50, 780); PDF_set_parameter($p, "overline", "false"); PDF_set_parameter($p, "underline", "true"); PDF_continue_text($p, "Underlined Text"); PDF_set_parameter($p, "strikeout", "true"); PDF_continue_text($p, "Underlined strikeout Text"); PDF_set_parameter($p, "underline", "false"); PDF_set_parameter($p, "strikeout", "false"); PDF_setcolor($p, "fill", "rgb", 1.0, 0.1, 0.1); PDF_continue_text($p, "Red Text"); PDF_setcolor($p, "fill", "rgb", 0, 0, 0); PDF_set_value($p, "textrendering", 1); PDF_setcolor($p, "stroke", "rgb", 0, 0.5, 0); PDF_continue_text($p, "Green Outlined Text"); PDF_set_value($p, "textrendering", 2); PDF_setcolor($p, "fill", "rgb", 0, 0.2, 0.8); PDF_setlinewidth($p, 2); PDF_continue_text($p, "Green Outlined Blue Text"); PDF_end_page($p); PDF_close($p); $buf = PDF_get_buffer($p); $len = strlen($buf); Header("Content-type:application/pdf"); Header("Content-Length:{$len}"); Header("Content-Disposition:inline; filename=coords.pdf"); echo $buf; PDF_delete($p);
<?php $p = PDF_new(); PDF_open_file($p); $im = pdf_open_png($p, "fr-flag.png"); $pattern = pdf_begin_pattern($p, 21, 14, 25, 18, 1); pdf_save($p); pdf_place_image($p, $im, 0, 0, 1); pdf_restore($p); pdf_end_pattern($p); pdf_close_image($p, $im); PDF_begin_page($p, 595, 842); PDF_setcolor($p, "fill", "pattern", $pattern); PDF_setcolor($p, "stroke", "pattern", $pattern); pdf_setlinewidth($p, 30.0); PDF_circle($p, 200, 680, 120); PDF_stroke($p); PDF_end_page($p); PDF_close($p); $buf = PDF_get_buffer($p); $len = strlen($buf); Header("Content-type:application/pdf"); Header("Content-Length:{$len}"); Header("Content-Disposition:inline; filename=gra2.pdf"); echo $buf; PDF_delete($p);
function SetBoth($color = '#000000', $transparency = '0') { if (strlen($color) != 7 || $color[0] != '#') { if ($this->depurar) { echo "<b>PDF:</b> Não foi possivel setar a linha. <br>"; } return FALSE; } $r = hexdec(substr($color, 1, 2)) / 255; $g = hexdec(substr($color, 3, 2)) / 255; $b = hexdec(substr($color, 5, 2)) / 255; $a = $transparency; PDF_setcolor($this->pdf, 'both', 'rgb', $r, $g, $b, 0); if ($this->depurar) { echo "<b>PDF:</b> Fundo setado na cor -> {$color}. <br>"; } return TRUE; }
PDF_setcolor($p, "fill", "rgb", 1.0, 0.8, 0.1); PDF_moveto($p, 150, 750); PDF_lineto($p, 450, 750); PDF_lineto($p, 100, 800); PDF_curveto($p, 80, 500, 70, 550, 250, 650); PDF_closepath($p); PDF_fill_stroke($p); // Circle PDF_setcolor($p, "fill", "rgb", 0.8, 0.5, 0.8); PDF_circle($p, 400, 600, 75); PDF_fill_stroke($p); // Funky Arc PDF_setcolor($p, "fill", "rgb", 0.8, 0.5, 0.5); PDF_moveto($p, 200, 600); PDF_arc($p, 300, 600, 50, 0, 120); PDF_closepath($p); PDF_fill_stroke($p); // Dashed rectangle PDF_setcolor($p, "stroke", "rgb", 0.3, 0.8, 0.3); PDF_setdash($p, 4, 6); PDF_rect($p, 50, 500, 500, 300); PDF_stroke($p); PDF_end_page($p); PDF_close($p); $buf = PDF_get_buffer($p); $len = strlen($buf); Header("Content-type:application/pdf"); Header("Content-Length:{$len}"); Header("Content-Disposition:inline; filename=gra3.pdf"); echo $buf; PDF_delete($p);
echo $item; $u[$cnt] = $item; $cnt++; } } $mypdf = PDF_new(); PDF_open_file($mypdf, ""); PDF_set_info($mypdf, "Creator", "Online Bus Service"); PDF_set_info($mypdf, "Author", "Mukesh Kumar"); PDF_set_info($mypdf, "Title", "Speedticket"); PDF_set_info($mypdf, "Subject", "Ticket"); PDF_set_info($mypdf, "Keywords", "Bus Ticket"); PDF_begin_page($mypdf, 595, 842); $myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0); PDF_setfont($mypdf, $myfont, 12); PDF_setcolor($mypdf, "stroke", "rgb", 0.5, 0.5, 0.5, 1); PDF_moveto($mypdf, 50, 810); PDF_lineto($mypdf, 500, 810); PDF_stroke($mypdf); PDF_moveto($mypdf, 50, 100); PDF_lineto($mypdf, 500, 100); PDF_stroke($mypdf); PDF_show_xy($mypdf, "Online Bus Ticket", 200, 800); PDF_show_xy($mypdf, "Your Ticket Details", 70, 700); PDF_continue_text($mypdf, "Bus Details"); PDF_continue_text($mypdf, "Bus ID: " . $b[0] . " Bus Name:" . $b[1] . " From: " . $b[2] . " To: " . $b[3]); PDF_continue_text($mypdf, "Departure: " . $b[4] . " Arrival:" . $b[5] . " Type: " . $b[6] . "Seats:" . $b[7]); PDF_continue_text($mypdf, " Fare: " . $b[8] . " Facilities: " . $b[9] . " Stars: " . $b[10]); PDF_continue_text($mypdf, "==================================================================="); PDF_continue_text($mypdf, "Your Details"); PDF_continue_text($mypdf, "Your Name: " . $u[0] . " Email: " . $u[1] . " Mobile: " . $u[2] . " Address: " . $u[3]);
function setColor($rgb) { if ($rgb != "") { list($r, $g, $b) = sfGetPdfRgb($rgb); PDF_setcolor($this->pdf, "fillstroke", "rgb", $r, $g, $b, 0); } }
<?php $p = PDF_new(); PDF_open_file($p); PDF_set_info($p, "Creator", "hello.php"); PDF_set_info($p, "Author", "Rasmus Lerdorf"); PDF_set_info($p, "Title", "Hello world (PHP)"); PDF_begin_page($p, 595, 842); PDF_set_parameter($p, "FontOutline", "CANDY==/usr/share/fonts/truetype/CANDY.ttf"); $font = PDF_findfont($p, "CANDY", "host", 1); PDF_setfont($p, $font, 78.0); PDF_set_value($p, "textrendering", 2); PDF_setcolor($p, "fill", "rgb", 0.8, 0.8, 0); PDF_setcolor($p, "stroke", "rgb", 0, 0, 0.5); PDF_set_text_pos($p, 20, 780); PDF_continue_text($p, "� � � � � � � � �"); PDF_continue_text($p, "This is a test"); PDF_end_page($p); PDF_close($p); $buf = PDF_get_buffer($p); $len = strlen($buf); Header("Content-type:application/pdf"); Header("Content-Length:{$len}"); Header("Content-Disposition:inline; filename=candy.pdf"); echo $buf; PDF_delete($p);