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}

PDF Resume Generator

  Consider the following code:

     <?php
     // Specify string constants and positioning variables.

    define("CASE_CATEGORY",   "Category");

     define("CASE_LIST",        "List");

    define("CASE_OBJECTIVE", "Objective");

    define("MARGIN",          50);

    define("PAGE_HEIGHT",     792);

    define("PAGE_WIDTH",      612);

    define("TAB",             25);

    define("VERT_SPACING",    14);
 

     // Define a couple useful functions.

     function drawHR($res) {

        $xpos = MARGIN;

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

       pdf_moveto($res, $xpos, $ypos);

       pdf_lineto($res, PAGE_WIDTH - MARGIN, $ypos);

       pdf_closepath($res);

       pdf_fill($res);

        $ypos = pdf_get_value($res, "texty", 0) - (VERT_SPACING * 2);

     }
 

     function pdflib_show($res, $text, $type) {

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

        $xpos = MARGIN;

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

 

        switch ($type) {

        case CASE_CATEGORY:

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

            $ypos = pdf_get_value($res, "texty", 0) - (VERT_SPACING * 3);

            break;

        case CASE_LIST:

            $xpos = MARGIN + TAB;

            $text = "* " . $text;

            break;

        case CASE_OBJECTIVE:

            $font = pdf_findfont($res, "Times-Italic", "winansi", 0);

            $xpos = MARGIN + TAB;

            $text = "\"" . $text . "\"";

            break;

        }

       pdf_setfont($res, $font, 12.0);

       pdf_show_xy($res, $text, $xpos, $ypos);

        return;

     }

 

     // Create resource.

     $pdf = pdf_new();

     if (!pdf_open_file($pdf, "")) {

   die("Error: Unable to open output file.");

}

 

// Collect header information from the database.

mysql_connect("localhost", "resume_user", "resume_pw");

mysql_select_db("resume");

$sql = "SELECT * FROM biography WHERE OID = 0";

$result = mysql_query($sql);

$row = mysql_fetch_array($result, MYSQL_ASSOC);

$name = $row["NameFirst"] . " " . $row["NameLast"];

 

// Document info.

pdf_set_info($pdf, "Author", $name . " <" . $row["Email"] . ">");

pdf_set_info($pdf, "Title", "Resume - " . $name);

pdf_set_info($pdf, "Subject", "The resume of " . $name . ", " .

$row["DesiredPosition"] . ".");

 

// Do something clever with the keywords.

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

$morewords = "";

foreach($keywords as $keyword) {

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

}

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

pdf");

 

// Begin PDF page. -- Can be placed anywhere after the PDF

// resource has been instantiated.

pdf_begin_page($pdf, PAGE_WIDTH, PAGE_HEIGHT);



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