Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Generate pdf from custom post type with custom meta fields? WordPress

  • SOLVED

I use a custom post type (ansatte - meaning employees) to register/show the employees of a company (or actually, several daughter-companies of one company), and the single-ansatte.php shows the CV, contact-info and so on, for each individual employee.

I think I have tried all the different plugins available, but some doesn't seem to work, and the ones I have found that otherwise works, doesn't include the meta fields. Using some outside service to generate the pdf is not an option. Then I'll rather make the pdf's by hand and use a meta field for the link. Except from outside services and branded pdf's, almost any solution is acceptable.

As you see, I also have an option to download a vcard with the mail/phone++ of the employee, [[LINK href="http://www.wpquestions.com/question/show/id/2575"]]solved very nice, simple & elegant by John Cotton here[[/LINK]]. The ideal solution would be something similar to johns solution, where I can include the meta fields I want to and I can use some html and css to get a nice layout on the pdf.

I will need an example of working code since my php-skills really suck :)
Here is the code for the single-ansatte.php and the custom post type including the meta fields.

Please ask if there is any other info you need. If I get a good solution quickly, I'll also add a bonus.

single-ansatte.php

<?php
/**
* Mal for ansattes CV.
*
* @package WordPress
*/


// er det vcard som skal lastes ned?
if( isset( $_GET['vcard'] ) ) {

global $post;



$custom = get_post_custom($post->ID);



header('Content-type: text/x-vcard; charset=utf-8');

header('Content-Disposition: attachment; filename="vcard.vcf"');



echo 'BEGIN:VCARD'. "\n";

echo 'VERSION:3.0'. "\n";

echo 'N:'.$custom["etternavn"][0] .';'.$custom["fornavn"][0]. "\n";

echo 'FN:'.$custom["fornavn"][0] .' '.$custom["etternavn"][0]. "\n";

echo 'ORG:Industrifinans'. "\n";

echo 'TITLE:' .$custom["stilling"][0]. "\n";

echo 'TEL;type=CELL;type=pref:'.$custom["tlf"][0]. "\n";

echo 'EMAIL;PREF;INTERNET:'.$custom["mail"][0]. "\n";

echo 'X-ABShowAs:COMPANY'. "\n";


/// etc for each field

echo 'END:VCARD';

exit();

}

// vcard slutt


get_header(); ?>

<div id="container">
<div id="content" role="main">
<div id="firmaliste">
</div>
<div id="ansattliste">
</div>

<?php $custom = get_post_custom($post->ID);
$etternavn = $custom["etternavn"][0];
$fodselsar = $custom["fodselsar"][0];
$tlf = $custom["tlf"][0];
$mail = $custom["mail"][0];
$about = $custom["about"][0];
$fornavn = $custom["fornavn"][0];?>

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

<div id="cvpage" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?> (<?php echo $fodselsar; ?>)</h1>
<div class="entry-content cv">
<p><?php echo $about; ?></p>
<?php the_content(); ?>
</div><!-- .entry-content -->

<div class="entry-utility">
<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-utility -->
</div><!-- #post-## -->
<div id="ansattinfo">
<?php
$thumb = get_the_post_thumbnail($post->ID);
$pattern= "/(?<=src=['|\"])[^'|\"]*?(?=['|\"])/i";
preg_match($pattern, $thumb, $thePath);
$theSrc = $thePath[0]; ?>

<?php
if ( has_post_thumbnail() ) {
// the current post has a thumbnail
the_post_thumbnail('thumbnail');
echo '<p><a href="'."$theSrc".'">Last ned høyoppløst bilde</a></p>';

} else {
// the current post lacks a thumbnail
}
?>
<div id="ansattinfo-tekst">
<p><strong>Tlf:</strong> <?php echo $tlf; ?></p>
<p><?php if ( function_exists( 'joliprint_show_the_button' ) ) echo joliprint_show_the_button(); ?></p>
<p><strong>Epost:</strong> <a href="mailto:<?php echo $mail; ?>"><?php echo $mail; ?></a></p>
<p><strong><a href="<?php the_permalink(); ?>?vcard=1">Lagre som kontakt (vcard)</a></strong></p>
</div>
</div>
<?php endwhile; // end of the loop. ?>

</div><!-- #content -->
</div><!-- #container -->

<?php get_footer(); ?>


The code for the custom post type and the meta fields:

add_action('init', 'ansatte_register');

function ansatte_register() {

$labels = array(
'name' => _x('Ansatte', 'post type general name'),
'singular_name' => _x('Ansatte', 'post type singular name'),
'add_new' => _x('Legg til', 'ansatt'),
'add_new_item' => __('Legg til ny ansatt'),
'edit_item' => __('Rediger ansatt.'),
'new_item' => __('Ny ansatt.'),
'view_item' => __('Vis ansatt'),
'search_items' => __('Søk i ansatte'),
'not_found' => __('Ingenting funnet'),
'not_found_in_trash' => __('Ingenting funnet i søppel'),
'parent_item_colon' => ''
);

$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('thumbnail','title','editor')
);

register_post_type( 'ansatte' , $args );
}

function ansatte_meta() {
global $post;
$custom = get_post_custom($post->ID);
$fornavn = $custom["fornavn"][0];
$etternavn = $custom["etternavn"][0];
$fodselsar = $custom["fodselsar"][0];
$about = $custom["about"][0];
$stilling = $custom["stilling"][0];
$mail = $custom["mail"][0];
$tlf = $custom["tlf"][0];
$cvlink = $custom["cvlink"][0]; ?>
<p><label>Fornavn:</label><br />
<input type="text" name="fornavn" value="<?php echo $fornavn; ?>"></input></p>
<p><label>Etternavn:</label><br />
<input type="text" cols="50" rows="1" name="etternavn" value="<?php echo $etternavn; ?>"></input></p>
<p><label>Fødselsår:</label><br />
<input type="text" cols="50" rows="1" name="fodselsar" value="<?php echo $fodselsar; ?>"></input></p>
<p><label>Kort tekst om ansatt:</label><br />
<textarea cols="50" rows="5" name="about"><?php echo $about; ?></textarea></p>
<p><label>Stillingstittel:</label><br />
<input type="text" name="stilling" value="<?php echo $stilling; ?>"></input></p>
<p><label>Telefonnr:</label><br />
<input type="text" cols="50" rows="1" name="tlf" value="<?php echo $tlf; ?>"></input></p>
<p><label>E-postadresse:</label><br />
<input type="text" cols="50" rows="1" name="mail" value="<?php echo $mail; ?>"></input></p>
<p><label>Link til CV:</label><br />
<input type="text" cols="50" rows="1" name="cvlink" value="<?php echo $cvlink; ?>"></input></p>
<?php
}

register_taxonomy("firma", array("ansatte"), array("hierarchical" => true, "label" => "Firma", "singular_label" => "Firma", "rewrite" => true));

Answers (2)

2011-07-10

Alex Sancho answers:

How about using [[LINK href="https://code.google.com/p/dompdf/"]]dompdf[[/LINK]] to convert your html to pdf? It has some caveats and it's a bit overhelming with large files, but i think it's perfect for the task you're asking


Torstein Opperud comments:

That might be a good solution, but then I'll need some code for the implementation :)


Alex Sancho comments:

Sure, i can do the job. If you're interested we can contact by mail or IM :)


Torstein Opperud comments:

well, getting the neccessary code was kinda what this question was about...


Alex Sancho comments:

The code isn't tested, but it's a start point http://pastie.textmate.org/private/y1fwm5rwe9uztomxm69lw


Alex Sancho comments:

Did you tried the code linked on the previous comment?


Torstein Opperud comments:

Hi Alex, I have tried it, but its not really easy to say if its working properly before I have dompdf working properly, which was not the simplest thing to set up I have encountered (seems rather poorly documented, at least for us who are used to the wordpress codex).


Alex Sancho comments:

Certainly, the [[LINK href="https://code.google.com/p/dompdf/wiki/Usage"]]documentation[[/LINK]] isn't the best one, but isn't that complicated. DomPDF [[LINK href="https://code.google.com/p/dompdf/wiki/Installation"]]installation[[/LINK]] is really easy, you only need to upload the files to the server and include it on the template using the full path to avoid extra complications.


Torstein Opperud comments:

Ok,
getting a bit further here now. Just a totally silly misunderstanding because of the extra "www"-folder that came with dompdf that confused me.

However, I'm getting this error from acrobat:

<blockquote>Acrobat could not open 'sample-5.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).

To create an Adobe PDF document, go to the source application. Then print the document to Adobe PDF.</blockquote>

Can it be something with my config-files?

<?php
//define("DOMPDF_TEMP_DIR", "/tmp");
//define("DOMPDF_CHROOT", DOMPDF_DIR);
//define("DOMPDF_UNICODE_ENABLED", false);
//define("TTF2AFM", "C:/Program Files (x86)/GnuWin32/bin/ttf2pt1.exe");
//define("DOMPDF_PDF_BACKEND", "PDFLib");
define("DOMPDF_DEFAULT_MEDIA_TYPE", "print");
define("DOMPDF_DEFAULT_PAPER_SIZE", "a4");
//define("DOMPDF_DEFAULT_FONT", "helvetica");
//define("DOMPDF_DPI", 72);
//define("DOMPDF_ENABLE_PHP", true);
//define("DOMPDF_ENABLE_REMOTE", true);
//define("DOMPDF_ENABLE_CSS_FLOAT", true);
//define("DOMPDF_ENABLE_JAVASCRIPT", false);
//define("DEBUGPNG", true);
//define("DEBUGKEEPTEMP", true);
//define("DEBUGCSS", true);
//define("DEBUG_LAYOUT", true);
//define("DEBUG_LAYOUT_LINES", false);
//define("DEBUG_LAYOUT_BLOCKS", false);
//define("DEBUG_LAYOUT_INLINE", false);
//define("DOMPDF_FONT_HEIGHT_RATIO", 1.0);
//define("DEBUG_LAYOUT_PADDINGBOX", false);
//define("DOMPDF_LOG_OUTPUT_FILE", DOMPDF_FONT_DIR."log.htm");


and
<?php
/**
* DOMPDF - PHP5 HTML to PDF renderer
*
* File: $RCSfile: dompdf_config.inc.php,v $
* Created on: 2004-08-04
*
* Copyright (c) 2004 - Benj Carson <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library in the file LICENSE.LGPL; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*
* Alternatively, you may distribute this software under the terms of the
* PHP License, version 3.0 or later. A copy of this license should have
* been distributed with this file in the file LICENSE.PHP . If this is not
* the case, you can obtain a copy at http://www.php.net/license/3_0.txt.
*
* The latest version of DOMPDF might be available at:
* http://www.dompdf.com/
*
* @link http://www.dompdf.com/
* @copyright 2004 Benj Carson
* @author Benj Carson <[email protected]>
* @contributor Helmut Tischer <[email protected]>
* @package dompdf
*
* Changes
* @contributor Helmut Tischer <[email protected]>
* @version 0.5.1.htischer.20090507
* - Allow overriding of configuration settings by calling php script.
* This allows replacing of dompdf by a new version in an application
* without any modification,
* - Optionally separate font cache folder from font folder.
* This allows write protecting the entire installation
* - Add settings to enable/disable additional debug output categories
* - Change some defaults to more practical values
* - Add comments about configuration parameter implications
*/

/* $Id: dompdf_config.inc.php 363 2011-02-17 21:18:25Z fabien.menager $ */

//error_reporting(E_STRICT | E_ALL | E_DEPRECATED);
//ini_set("display_errors", 1);

/**
* The root of your DOMPDF installation
*/
define("DOMPDF_DIR", str_replace(DIRECTORY_SEPARATOR, '/', realpath(dirname(__FILE__))));

/**
* The location of the DOMPDF include directory
*/
define("DOMPDF_INC_DIR", DOMPDF_DIR . "/include");

/**
* The location of the DOMPDF lib directory
*/
define("DOMPDF_LIB_DIR", DOMPDF_DIR . "/lib");

/**
* Some installations don't have $_SERVER['DOCUMENT_ROOT']
* http://fyneworks.blogspot.com/2007/08/php-documentroot-in-iis-windows-servers.html
*/
if( !isset($_SERVER['DOCUMENT_ROOT']) ) {
$path = "";

if ( isset($_SERVER['SCRIPT_FILENAME']) )
$path = $_SERVER['SCRIPT_FILENAME'];
elseif ( isset($_SERVER['PATH_TRANSLATED']) )
$path = str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']);

$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr($path, 0, 0-strlen($_SERVER['PHP_SELF'])));
}

/** Include the custom config file if it exists */
if ( file_exists(DOMPDF_DIR . "/dompdf_config.custom.inc.php") ){
require_once(DOMPDF_DIR . "/dompdf_config.custom.inc.php");
}

//FIXME: Some function definitions rely on the constants defined by DOMPDF. However, might this location prove problematic?
require_once(DOMPDF_INC_DIR . "/functions.inc.php");

/**
* The location of the DOMPDF font directory
*
* If DOMPDF_FONT_DIR identical to DOMPDF_FONT_CACHE or user executing DOMPDF from the CLI,
* this directory must be writable by the webserver process ().
* *Please note the trailing slash.*
*
* Notes regarding fonts:
* Additional .afm font metrics can be added by executing load_font.php from command line.
* Converting ttf fonts to afm requires the external tool referenced by TTF2AFM
*
* Only the original "Base 14 fonts" are present on all pdf viewers. Additional fonts must
* be embedded in the pdf file or the PDF may not display correctly. This can significantly
* increase file size and could violate copyright provisions of a font. Font embedding is
* not currently supported (? via HT).
*
* Any font specification in the source HTML is translated to the closest font available
* in the font directory.
*
* The pdf standard "Base 14 fonts" are:
* Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique,
* Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique,
* Times-Roman, Times-Bold, Times-BoldItalic, Times-Italic,
* Symbol,
* ZapfDingbats,
*
* *Please note the trailing slash.*
*/
def("DOMPDF_FONT_DIR", DOMPDF_DIR . "/lib/fonts/");

/**
* The location of the DOMPDF font cache directory
*
* Note this directory must be writable by the webserver process
* This folder must already exist!
* It contains the .afm files, on demand parsed, converted to php syntax and cached
* This folder can be the same as DOMPDF_FONT_DIR
*/
def("DOMPDF_FONT_CACHE", DOMPDF_FONT_DIR);

/**
* The location of a temporary directory.
*
* The directory specified must be writeable by the webserver process.
* The temporary directory is required to download remote images and when
* using the PFDLib back end.
*/
def("DOMPDF_TEMP_DIR", sys_get_temp_dir());

/**
* ==== IMPORTANT ====
*
* dompdf's "chroot": Prevents dompdf from accessing system files or other
* files on the webserver. All local files opened by dompdf must be in a
* subdirectory of this directory. DO NOT set it to '/' since this could
* allow an attacker to use dompdf to read any files on the server. This
* should be an absolute path.
* This is only checked on command line call by dompdf.php, but not by
* direct class use like:
* $dompdf = new DOMPDF(); $dompdf->load_html($htmldata); $dompdf->render(); $pdfdata = $dompdf->output();
*/
def("DOMPDF_CHROOT", realpath(DOMPDF_DIR));

/**
* Whether to use Unicode fonts or not.
*
* When set to true the PDF backend must be set to "CPDF" and fonts must be
* loaded via the modified ttf2ufm tool included with dompdf (see below).
* Unicode font metric files (with .ufm extensions) must be created with
* ttf2ufm. load_font.php should do this for you if the TTF2AFM define below
* points to the modified ttf2ufm tool included with dompdf.
*
* When enabled, dompdf can support all Unicode glyphs. Any glyphs used in a
* document must be present in your fonts, however.
*/
def("DOMPDF_UNICODE_ENABLED", true);

/**
* The path to the tt2pt1 utility (used to convert ttf to afm)
*
* Not strictly necessary, but useful if you would like to install
* additional fonts using the {@link load_font.php} utility.
*
* Windows users should use something like this:
* define("TTF2AFM", "C:\\Program Files\\Ttf2Pt1\\bin\\ttf2pt1.exe");
*
* @link http://ttf2pt1.sourceforge.net/
*/
if ( strpos(PHP_OS, "WIN") === false )
def("TTF2AFM", DOMPDF_LIB_DIR ."/ttf2ufm/ttf2ufm-src/ttf2pt1");
else
def("TTF2AFM", "C:\\Program Files\\GnuWin32\\bin\\ttf2pt1.exe");

/**
* The PDF rendering backend to use
*
* Valid settings are 'PDFLib', 'CPDF' (the bundled R&OS PDF class), 'GD' and
* 'auto'. 'auto' will look for PDFLib and use it if found, or if not it will
* fall back on CPDF. 'GD' renders PDFs to graphic files. {@link
* Canvas_Factory} ultimately determines which rendering class to instantiate
* based on this setting.
*
* Both PDFLib & CPDF rendering backends provide sufficient rendering
* capabilities for dompdf, however additional features (e.g. object,
* image and font support, etc.) differ between backends. Please see
* {@link PDFLib_Adapter} for more information on the PDFLib backend
* and {@link CPDF_Adapter} and lib/class.pdf.php for more information
* on CPDF. Also see the documentation for each backend at the links
* below.
*
* The GD rendering backend is a little different than PDFLib and
* CPDF. Several features of CPDF and PDFLib are not supported or do
* not make any sense when creating image files. For example,
* multiple pages are not supported, nor are PDF 'objects'. Have a
* look at {@link GD_Adapter} for more information. GD support is new
* and experimental, so use it at your own risk.
*
* @link http://www.pdflib.com
* @link http://www.ros.co.nz/pdf
* @link http://www.php.net/image
*/
def("DOMPDF_PDF_BACKEND", "CPDF");

/**
* PDFlib license key
*
* If you are using a licensed, commercial version of PDFlib, specify
* your license key here. If you are using PDFlib-Lite or are evaluating
* the commercial version of PDFlib, comment out this setting.
*
* @link http://www.pdflib.com
*
* If pdflib present in web server and auto or selected explicitely above,
* a real license code must exist!
*/
// def("DOMPDF_PDFLIB_LICENSE", "your license key here");

/**
* html target media view which should be rendered into pdf.
* List of types and parsing rules for future extensions:
* http://www.w3.org/TR/REC-html40/types.html
* screen, tty, tv, projection, handheld, print, braille, aural, all
* Note: aural is deprecated in CSS 2.1 because it is replaced by speech in CSS 3.
* Note, even though the generated pdf file is intended for print output,
* the desired content might be different (e.g. screen or projection view of html file).
* Therefore allow specification of content here.
*/
def("DOMPDF_DEFAULT_MEDIA_TYPE", "screen");

/**
* The default paper size.
*
* North America standard is "letter"; other countries generally "a4"
*
* @see CPDF_Adapter::PAPER_SIZES for valid sizes
*/
def("DOMPDF_DEFAULT_PAPER_SIZE", "A4");

/**
* The default font family
*
* Used if no suitable fonts can be found. This must exist in the font folder.
* @var string
*/
def("DOMPDF_DEFAULT_FONT", "serif");

/**
* Image DPI setting
*
* This setting determines the default DPI setting for images and fonts. The
* DPI may be overridden for inline images by explictly setting the
* image's width & height style attributes (i.e. if the image's native
* width is 600 pixels and you specify the image's width as 72 points,
* the image will have a DPI of 600 in the rendered PDF. The DPI of
* background images can not be overridden and is controlled entirely
* via this parameter.
*
* For the purposes of DOMPDF, pixels per inch (PPI) = dots per inch (DPI).
* If a size in html is given as px (or without unit as image size),
* this tells the corresponding size in pt.
* This adjusts the relative sizes to be similar to the rendering of the
* html page in a reference browser.
*
* In pdf, always 1 pt = 1/72 inch
*
* Rendering resolution of various browsers in px per inch:
* Windows Firefox and Internet Explorer:
* SystemControl->Display properties->FontResolution: Default:96, largefonts:120, custom:?
* Linux Firefox:
* about:config *resolution: Default:96
* (xorg screen dimension in mm and Desktop font dpi settings are ignored)
*
* Take care about extra font/image zoom factor of browser.
*
* In images, <img> size in pixel attribute, img css style, are overriding
* the real image dimension in px for rendering.
*
* @var int
*/
def("DOMPDF_DPI", 96);

/**
* Enable inline PHP
*
* If this setting is set to true then DOMPDF will automatically evaluate
* inline PHP contained within <script type="text/php"> ... </script> tags.
*
* Enabling this for documents you do not trust (e.g. arbitrary remote html
* pages) is a security risk. Set this option to false if you wish to process
* untrusted documents.
*
* @var bool
*/
def("DOMPDF_ENABLE_PHP", false);

/**
* Enable inline Javascript
*
* If this setting is set to true then DOMPDF will automatically insert
* JavaScript code contained within <script type="text/javascript"> ... </script> tags.
*
* @var bool
*/
def("DOMPDF_ENABLE_JAVASCRIPT", true);

/**
* Enable remote file access
*
* If this setting is set to true, DOMPDF will access remote sites for
* images and CSS files as required.
* This is required for part of test case www/test/image_variants.html through www/examples.php
*
* Attention!
* This can be a security risk, in particular in combination with DOMPDF_ENABLE_PHP and
* allowing remote access to dompdf.php or on allowing remote html code to be passed to
* $dompdf = new DOMPDF(); $dompdf->load_html(...);
* This allows anonymous users to download legally doubtful internet content which on
* tracing back appears to being downloaded by your server, or allows malicious php code
* in remote html pages to be executed by your server with your account privileges.
*
* @var bool
*/
def("DOMPDF_ENABLE_REMOTE", false);

/**
* The debug output log
* @var string
*/
def("DOMPDF_LOG_OUTPUT_FILE", DOMPDF_FONT_DIR."log.htm");

/**
* A ratio applied to the fonts height to be more like browsers' line height
*/
def("DOMPDF_FONT_HEIGHT_RATIO", 1.1);

/**
* Enable CSS float
*
* Allows people to disabled CSS float support
* @var bool
*/
def("DOMPDF_ENABLE_CSS_FLOAT", false);

/**
* DOMPDF autoload function
*
* If you have an existing autoload function, add a call to this function
* from your existing __autoload() implementation.
*
* @param string $class
*/
function DOMPDF_autoload($class) {
$filename = DOMPDF_INC_DIR . "/" . mb_strtolower($class) . ".cls.php";

if ( is_file($filename) )
require_once($filename);
}

// If SPL autoload functions are available (PHP >= 5.1.2)
if ( function_exists("spl_autoload_register") ) {
$autoload = "DOMPDF_autoload";
$funcs = spl_autoload_functions();

// No functions currently in the stack.
if ( $funcs === false ) {
spl_autoload_register($autoload);
}

// If PHP >= 5.3 the $prepend argument is available
else if ( version_compare(PHP_VERSION, '5.3', '>=') ) {
spl_autoload_register($autoload, true, true);
}

else {
// Unregister existing autoloaders...
$compat = version_compare(PHP_VERSION, '5.1.2', '<=') &&
version_compare(PHP_VERSION, '5.1.0', '>=');

foreach ($funcs as $func) {
if (is_array($func)) {
// :TRICKY: There are some compatibility issues and some
// places where we need to error out
$reflector = new ReflectionMethod($func[0], $func[1]);
if (!$reflector->isStatic()) {
throw new Exception('This function is not compatible with non-static object methods due to PHP Bug #44144.');
}

// Suprisingly, spl_autoload_register supports the
// Class::staticMethod callback format, although call_user_func doesn't
if ($compat) $func = implode('::', $func);
}

spl_autoload_unregister($func);
}

// Register the new one, thus putting it at the front of the stack...
spl_autoload_register($autoload);

// Now, go back and re-register all of our old ones.
foreach ($funcs as $func) {
spl_autoload_register($func);
}

// Be polite and ensure that userland autoload gets retained
if ( function_exists("__autoload") ) {
spl_autoload_register("__autoload");
}
}
}

else if ( !function_exists("__autoload") ) {
/**
* Default __autoload() function
*
* @param string $class
*/
function __autoload($class) {
DOMPDF_autoload($class);
}
}

// ### End of user-configurable options ###


/**
* Ensure that PHP is working with text internally using UTF8 character encoding.
*/
mb_internal_encoding('UTF-8');

/**
* Global array of warnings generated by DomDocument parser and
* stylesheet class
*
* @var array
*/
global $_dompdf_warnings;
$_dompdf_warnings = array();

/**
* If true, $_dompdf_warnings is dumped on script termination when using
* dompdf/dompdf.php or after rendering when using the DOMPDF class.
* When using the class, setting this value to true will prevent you from
* streaming the PDF.
*
* @var bool
*/
global $_dompdf_show_warnings;
$_dompdf_show_warnings = false;

/**
* If true, the entire tree is dumped to stdout in dompdf.cls.php.
* Setting this value to true will prevent you from streaming the PDF.
*
* @var bool
*/
global $_dompdf_debug;
$_dompdf_debug = false;

/**
* Array of enabled debug message types
*
* @var array
*/
global $_DOMPDF_DEBUG_TYPES;
$_DOMPDF_DEBUG_TYPES = array(); //array("page-break" => 1);

/* Optionally enable different classes of debug output before the pdf content.
* Visible if displaying pdf as text,
* E.g. on repeated display of same pdf in browser when pdf is not taken out of
* the browser cache and the premature output prevents setting of the mime type.
*/
def('DEBUGPNG', false);
def('DEBUGKEEPTEMP', false);
def('DEBUGCSS', false);

/* Layout debugging. Will display rectangles around different block levels.
* Visible in the PDF itself.
*/
def('DEBUG_LAYOUT', false);
def('DEBUG_LAYOUT_LINES', true);
def('DEBUG_LAYOUT_BLOCKS', true);
def('DEBUG_LAYOUT_INLINE', true);
def('DEBUG_LAYOUT_PADDINGBOX', true);


Alex Sancho comments:

could you send me the pdf file?


Torstein Opperud comments:

Hm, not sure if it will work to enclose it here, I'll try, but if it doesnt work, send me a mail at [email protected], and I'll send it to you.

PS: I'm starting to realize this may be a little more job than 50$, so we'll work something out, just send me that mail :)



Torstein Opperud comments:

trying one more time... it claims it should work with a zip...


Torstein Opperud comments:

but it does not. Just send me that mail, alright? :)

2011-07-12

Denzel Chia answers:

Hi,

If you still cannot get your pdf library to work.
You may want to try using this FPDF library.
http://www.fpdf.org/

You can download the whole library zip file that includes the demos.
Just put the whole folder within your htdocs and navigate to the examples.
All demos work out of the box.

They got well documented manual online too.

You can follow the demo codes to familiarize with how it works, before applying to your codes.
Library is written in Object Oriented Programming. No additional PHP extension required.

Thanks.
Denzel