<?php //create file $fp = fopen('hello.pdf', 'w'); if (!$fp) { echo "Error: could not create the PDF file"; exit; } // start the pdf document $pdf = pdf_open($fp); pdf_set_info($pdf, "Creator", "pdftest.php"); pdf_set_info($pdf, "Author", "Luke Welling and Laura Thomson"); pdf_set_info($pdf, "Title", "Hello World (PHP)"); // US letter is 11" x 8.5" and there are 72 points per inch pdf_begin_page($pdf, 8.5 * 72, 11 * 72); pdf_add_outline($pdf, 'Page 1'); $font = pdf_findfont($pdf, 'Times-Roman', 'host', 0); pdf_setfont($pdf, $font, 24); pdf_set_text_pos($pdf, 50, 700); // write text pdf_show($pdf, 'Hello,world!'); pdf_continue_text($pdf, '(says PHP)'); // end the document pdf_end_page($pdf); pdf_close($pdf); fclose($fp); // display a link to download echo "download the pdf <a href = 'hello.pdf'>here</a>"; ?>
function _link(&$link) { if (empty($link->text)) { $link->text = preg_replace('/:-:(.*?):-:/e', '$this->pres->\\1', $link->href); } if (!empty($link->leader)) { $leader = preg_replace('/:-:(.*?):-:/e', '$this->pres->\\1', $link->leader); } else { $leader = ''; } if (!empty($link->text)) { $this->pdf_cy = pdf_get_value($this->pdf, "texty", null) + 10; pdf_set_font($this->pdf, $this->pdf_font, -12, 'winansi'); $fnt = pdf_findfont($this->pdf, $this->pdf_font, 'winansi', 0); if (strlen($leader)) { $lx = pdf_stringwidth($this->pdf, $leader, $fnt, -12); } else { $lx = 0; } $dx = pdf_stringwidth($this->pdf, $link->text, $fnt, -12); $cw = pdf_stringwidth($this->pdf, 'm', $fnt, -12); // em unit width switch ($link->align) { case 'center': $x = (int) ($this->pdf_x / 2 - $dx / 2 - $lx / 2); break; case 'right': $x = $this->pdf_x - $this->pdf_cx - $dx - $lx - 15; break; case 'left': default: $x = $this->pdf_cx; break; } if ($link->marginleft) { $x += (int) ((double) $link->marginleft * $cw); } pdf_add_weblink($this->pdf, $x + $lx, $this->pdf_y - $this->pdf_cy - 3, $x + $dx + $lx, $this->pdf_y - $this->pdf_cy + 12, $link->text); pdf_show_xy($this->pdf, strip_markups($leader) . strip_markups($link->text), $x, $this->pdf_cy); pdf_continue_text($this->pdf, ""); } }
function message_header($subject, $author, $date, $id, $th) { $y = pdf_get_value($this->pdf, 'texty', 0) - 3; if ($y < 100) { $this->end_page(); $this->begin_page($this->pg_title); $y = $this->ph - $this->hmargin; } pdf_moveto($this->pdf, $this->wmargin, $y); pdf_lineto($this->pdf, $this->pw - $this->wmargin, $y); pdf_moveto($this->pdf, $this->wmargin, $y - 3); pdf_lineto($this->pdf, $this->pw - $this->wmargin, $y - 3); pdf_stroke($this->pdf); pdf_set_text_pos($this->pdf, $this->wmargin, $y - 5); pdf_setfont($this->pdf, $this->fonts['Helvetica'], 14); pdf_continue_text($this->pdf, 'Subject: ' . $subject); pdf_continue_text($this->pdf, 'Posted by ' . $author . ' on ' . gmdate('D, d M Y H:i:s \\G\\M\\T', $date)); pdf_continue_text($this->pdf, 'URL: '); $url = $GLOBALS['WWW_ROOT'] . '?t=rview&th=' . $th . '&goto=' . $id; $this->add_link($url, $url); $this->draw_line(); pdf_set_text_pos($this->pdf, $this->wmargin, $this->y - 3); }
$im = pdf_open_jpeg($pdf, $imagepath); pdf_place_image($pdf, $im, 5, $y - 72, 0.5); pdf_close_image($pdf, $im); pdf_set_value($pdf, 'textrendering', 0); // fill pdf_set_font($pdf, "Helvetica", 12, winansi); pdf_show_xy($pdf, 'Micro Snot & L4m3r5 S.R.L.', 145, $y - 20); pdf_continue_text($pdf, '123 Calle del Dolor'); pdf_continue_text($pdf, 'Tacora, Lima 666'); pdf_set_font($pdf, "Helvetica", 10, winansi); pdf_show_xy($pdf, 'Cliente Sin Salvacion S.A.', 20, $y - 100); pdf_continue_text($pdf, '1 Calle Pequena'); pdf_continue_text($pdf, 'Cuidad Perdida, Puno 123'); pdf_set_font($pdf, "Helvetica", 10, winansi); pdf_show_xy($pdf, 'Terminos: Pago Completo 15 horas', 150, $y - 100); pdf_continue_text($pdf, 'Apt. Postal: 12345'); pdf_set_font($pdf, "Helvetica-Bold", 30, winansi); pdf_show_xy($pdf, "* F A C T U R A *", $x - 250, $y - 112); pdf_setcolor($pdf, 'fill', 'gray', 0.9, 0, 0, 0); pdf_rect($pdf, 20, 80, $x - 40, $y - 212); pdf_fill_stroke($pdf); $offset = 184; $i = 0; while ($y - $offset > 80) { pdf_setcolor($pdf, 'fill', 'gray', $i % 2 ? 0.8 : 1, 0, 0, 0); pdf_setcolor($pdf, 'stroke', 'gray', $i % 2 ? 0.8 : 1, 0, 0, 0); pdf_rect($pdf, 21, $y - $offset, $x - 42, 24); pdf_fill_stroke($pdf); $i++; $offset += 24; }
$im = pdf_open_jpeg($pdf, "php-big.jpg"); pdf_place_image($pdf, $im, 5, $y - 72, 0.5); pdf_close_image($pdf, $im); pdf_set_value($pdf, 'textrendering', 0); // fill pdf_set_font($pdf, "Helvetica", 12, winansi); pdf_show_xy($pdf, 'Generic Evil Company Inc.', 145, $y - 20); pdf_continue_text($pdf, '123 Main Street'); pdf_continue_text($pdf, 'Dark City, CA 98765'); pdf_set_font($pdf, "Helvetica", 10, winansi); pdf_show_xy($pdf, 'Helpless Customer Ltd.', 20, $y - 100); pdf_continue_text($pdf, '2 Small Street'); pdf_continue_text($pdf, 'Little Town, ID 56789'); pdf_set_font($pdf, "Helvetica", 10, winansi); pdf_show_xy($pdf, 'Terms: Net 30', 150, $y - 100); pdf_continue_text($pdf, 'PO #: 12345'); pdf_set_font($pdf, "Helvetica-Bold", 30, winansi); pdf_show_xy($pdf, "* I N V O I C E *", $x - 250, $y - 112); pdf_setcolor($pdf, 'fill', 'gray', 0.9, 0, 0, 0); pdf_rect($pdf, 20, 80, $x - 40, $y - 212); pdf_fill_stroke($pdf); $offset = 184; $i = 0; while ($y - $offset > 80) { pdf_setcolor($pdf, 'fill', 'gray', $i % 2 ? 0.8 : 1, 0, 0, 0); pdf_setcolor($pdf, 'stroke', 'gray', $i % 2 ? 0.8 : 1, 0, 0, 0); pdf_rect($pdf, 21, $y - $offset, $x - 42, 24); pdf_fill_stroke($pdf); $i++; $offset += 24; }