PHP extensions PDFLib  Hot PDF Print E-mail
Tag it:
Delicious
Furl it!
Digg
NewsVine
Reddit
YahooMyWeb
Technorati
Articles Reviews PHP
Written by Phil Harrison   
Monday, 09 October 2006
Article Index
PHP extensions PDFLib  Hot
PDF Resume Generator
PDF Resume
{mos_sb_discuss:37}

// Print name.

$font = pdf_findfont($pdf, "Times-Bold", "winansi", 0);

pdf_setfont($pdf, $font, 14.0);

$stringwidth = pdf_stringwidth($pdf, $name, $font, 14.0);

$xpos = (PAGE_WIDTH / 2) - ($stringwidth / 2);

pdf_show_xy($pdf, $name, $xpos, 700);

$xpos = pdf_get_value($pdf, "textx", 0);

$ypos = pdf_get_value($pdf, "texty", 0) - VERT_SPACING;

 

// Print contact information.

$font = pdf_findfont($pdf, "Times-Roman", "winansi", 0);

pdf_setfont($pdf, $font, 12.0);

$headerdata = array($row["Address"],

                   $row["City"] . ", " . $row["State"] . " " . $row["ZipCode"],

       $row["Phone"],

       $row["Email"]);

foreach ($headerdata as $data) {

   $stringwidth = pdf_stringwidth($pdf, $data, $font, 12.0);

   $xpos = (PAGE_WIDTH / 2) - ($stringwidth / 2);

   $ypos = pdf_get_value($pdf, "texty", 0) - VERT_SPACING;

   pdf_show_xy($pdf, $data, $xpos, $ypos);

}

 

// Print categories.

$sql = "SELECT * FROM items WHERE BIOGRAPHY_OID = 0";

 

     $result = mysql_query($sql);

      $prevCategory = "";

      while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

          $curCategory = $row["Category"];

          if (strcmp($prevCategory, $curCategory) != 0) {

            drawHR($pdf);

            pdflib_show($pdf, $row["Category"], CASE_CATEGORY);

          }

         $prevCategory = $row["Category"];

          if (strcmp($row["Category"], "Career Objective") == 0) {

            pdflib_show($pdf, $row["Description"], CASE_OBJECTIVE);

          } else {

            pdflib_show($pdf, $row["Description"], CASE_LIST);

          }

      }

 

      // Wrap up the document and return it to the browser.

     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=resume.pdf");

      print $buf;

 

      // Clean up!

      mysql_close();

      $pdf = 0;

 

      ?>

  This straightforward application generates a simple PDF resume using data drawn from a MySQL  database. Aside from the MySQL connection setup and database queries, the only aspects of this script  that have not already been covered is the use of the biographical data to concatenate information from  the individual's desired position into the document's keywords:

      $keywords = split(" ", $row["DesiredPosition"]);

      $morewords = "";

     foreach($keywords as $keyword) {

          $morewords = $morewords . $keyword . ", ";

      }

     pdf_set_info($pdf, "Keywords", "Resume, " . $morewords . "apache, mysql, php,

      pdf");

 

The resume's header information, containing the individual's name and contact information, was handled  separately from the remainder of the resume's data in order to keep the helper function pdflib_show()'s  implementation as simple as possible.

The body of the resume is generated by a while loop that tracks the  current and previous categories, printing the category name when the value changes; otherwise, it prints the description. All that remains is closing the document, returning it to the browser, and cleaning up.

One final word of advice: If PDF generation will play a significant role in any of your projects, you must  read and understand the documentation distributed with the PDFLib source code.

The normally rich documentation on the PHP website is particularly lacking where the PDFLib wrapper is concerned. While this text should serve as an excellent introduction, there is no better source of information about the full capabilities of the PDFLib library than the PDFlib manual.


User reviews

There are no user reviews for this item.

Add new review




Powered by jReviews



Last Updated ( Friday, 11 January 2008 )
 
< Prev   Next >