Hello, I want to adapt a wysiwyg html editor to dompdf. How to?

1,409 views
Skip to first unread message

Paulo Lopes

unread,
Nov 29, 2013, 1:25:06 AM11/29/13
to dom...@googlegroups.com
I tried creditor and tynimce in the /dompdf/examples.php and directly direct into the templates /dompdf/www/test/*.html .
The editor loads but messes-up with the pdf results.
could someone to help?

My goal is to have several templates with custom header/footer + data from mysql db and the editor will do final adjustments.
After that I would like to save this file in the db or a diretory in the server to be viewd and attached to a email form.

so, in fact I need several tasks with dompdf.

Many thanks,
Paulo

BrianS

unread,
Dec 5, 2013, 10:51:55 PM12/5/13
to dom...@googlegroups.com
I don't know that you'll get a step-by-step here, but I'll try to give advice as I can. As far as the GUI editor, dompdf should be able to parse that content same as any other HTML. If it's not showing up right you may be missing some parts (e.g. a default stylesheet) or loading the wrong thing. The easiest way to tell if you're passing dompdf all the necessary content is to just echo it out to the web browser and see how it looks.

Beyond that general advice it would help to know exactly how the output is messes up.

Paulo Lopes

unread,
Dec 11, 2013, 5:09:45 PM12/11/13
to dom...@googlegroups.com
Hello Brian, many thanks for the reply. I missed your message and it is why it took so long to answer you back, sorry. At this point I discard the tynimce with mysql dump capabilities and I am trying to the traditional way. I don't know how to retrieve data from mysql into a dompdf template and I have been goggling here and there about this matter. As I said I am a beginner and the information available requires higher level of knowledge. In fact the dompdf template would retrieve data from db and the tynimce would be used to adjust font style and other minor details and save it back into the db. Producing a .pdf file named by $fname_$lname_$datetime.pdf  and save this file in another column in the db is my dream.

If you have in the back of your mind some links to suggest it will be helpful.

Thanks again for the prompt answer.
Paulo Lopes

BrianS

unread,
Dec 17, 2013, 1:20:13 PM12/17/13
to dom...@googlegroups.com
As far as working with dompdf, consider it the last step in the process of creating your HTML document. So your primary task should be to create the HTML as you would if you were sending the HTML to the user. Then what you do with dompdf is instead of sending the HTML to the browser you capture it and feed it into dompdf. So if I were to do this with a simple document (using heredoc syntax):

<?php
$html = <<<EOF
  <html>
  <head>
    <title>Hello World</title>
  </head>
  <body>
    <h1>Hello World</h1>
  </body>
  </html>
EOF;

$dompdf = new DOMPDF( );
$dompdf->load_html( $html );
$dompdf->render( );
$dompdf->stream( );
?>


Of course, building your HTML from a database requires a lot more work. But this should get you started.

Nathan Obral

unread,
Dec 18, 2013, 5:19:42 PM12/18/13
to dom...@googlegroups.com
So far my installation of DOMPDF has gone okay. I did want to reopen this thread as I'm not quite sure just how to extrapolate WYSIWYG code from a respective page onto the dompdf.php file itself, plus it made more sense to bump up a thread than starting a redundant one.

For all the pages on my website that utilitze a print function (some don't, for practicality reasons) the following code is invoked on the top of the specified pages (Dreamweaver templates keep this list in order):

<script language="JavaScript">
var gAutoPrint = true; // Tells whether to automatically call the print function

function printSpecial()
{if (document.getElementById != null)
{var html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml">\n<head>';

if (document.getElementsByTagName != null)
{var headTags = document.getElementsByTagName("head");
if (headTags.length > 0)
html += headTags[0].innerHTML;}

html += '</head>\n<body id="print">';

var printReadyElem = document.getElementById("printReady");

if (printReadyElem != null)
{html += printReadyElem.innerHTML;}
else {alert("Could not find the printReady function"); return;}

html += '</body>\n</html>';

var printWin = window.open("","printSpecial");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint)
printWin.print();}
else { alert("The print ready feature is only available if you are using an browser. Please update your browser.");}}

</script>
<link rel="stylesheet" type="text/css" href="http://www.superior-insulation.com/images/print.css">


The parsed out code is commanded by the following tags, which are manageable within the framework of the website, utilizing the Gumby Framework.

<div class="printReady">

[ ... html for printing ... ]

</div>


Thus, the "Print this Page" button at the bottom of a page like this renders the wysiwyg command as intended.

Would be interested in hearing how this can be done in dompdf, and where the necessary code should be inserted. Thanks!





On Friday, November 29, 2013 1:25:06 AM UTC-5, Paulo Lopes wrote:

BrianS

unread,
Dec 19, 2013, 12:55:39 PM12/19/13
to dom...@googlegroups.com
There are a lot of ways you can achieve the output you want. The easiest method would be to point dompdf to the current page and use print styling to remove the extraneous content (i.e. navigation). If that's not feasible you could write a script that parses a page for the printReady content (e.g. using DOMDocument) and uses a pre-defined stylesheet or grabs the head content to apply the document-defined styles. Or you could utilize your current JS and instead of filling the new window with HTML point it to a script that parses the HTML content from a GET parameter. Or you could create a form on the pop-up window containing a text area, fill the text area with the content of the html variable, then submit the form to dompdf using a POST request. Or you could submit your PDF request via AJAX, capture the results, and create a new window and fill it with the content of the PDF.

It really depends on how you want to go about this.

Nathan Obral

unread,
Dec 20, 2013, 6:29:08 PM12/20/13
to dom...@googlegroups.com
The first option sounds best. I can wrap up the divs not surrounded by the printReady div in a different custom div (i.e., <div class="extra">) and comment that out. I'm still inexperienced somewhat with dompdf.php, so I'm not sure what to comment out.

As of right now, the outputting PDFs look something like this, which is odd because parts of my stylesheets appear to be commanded but other parts aren't.

BrianS

unread,
Dec 23, 2013, 10:34:43 AM12/23/13
to dom...@googlegroups.com
Yes, I'm seeing the same issue. I'll need to take a closer look to see why so much of the styling is ignored.

Nathan Obral

unread,
Dec 29, 2013, 3:19:14 PM12/29/13
to dom...@googlegroups.com
First of all, I apologize for the lateness in this reply. Christmas break can do that sometimes. ;)
 
I do know that, in the composition of the pages on my site, there are multiple stylesheets I have to invoke. The key one... gumby.css ... has to be invoked like so:
<link rel="stylesheet" href="../css/gumby.css" />
in order for the stylesheet to properly work. (I've tried multiple times using <link rel="stylesheet" href="http://www.superior-insulation.com/css/gumby.css" /> on the site in some form, with no luck whatsoever.)
 
As a result, the following stylesheets are included at the top of every page like so:
  <link rel="stylesheet" href="../css/gumby.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/css/style.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/css/bootstrap-fileupload.min.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/css/bootstrap-fileupload.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/css/additional.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/css/bootstrap-dropdown.min.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/css/bootstrap-dropdown.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/images/css/jquery-ui.css" media="all" type="text/css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/images/css/jquery-ui-timepicker-addon.css" media="all" type="text/css" />
 
It should also be noted that, when I do invoke the stylesheet as "<link rel="stylesheet" href="http://www.superior-insulation.com/css/gumby.css" />", I get the following friendly error message:
 
Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given, called in /hsphere/local/home/superior/superior-insulation.com/dompdf/include/table_frame_decorator.cls.php on line 312 and defined in /hsphere/local/home/superior/superior-insulation.com/dompdf/include/frame.cls.php on line 765
Is this because I do not compose the site with any tables? It's a DIV-powered website with a framework that discourages tables as the main source of page composition.
 
 
Minus the username and password, here are the settings on the dompdf_config.custom.inc.php file:
<?php
define("DOMPDF_TEMP_DIR", "/tmp");
define("DOMPDF_CHROOT", DOMPDF_DIR);
define("DOMPDF_FONT_DIR", DOMPDF_DIR."/lib/fonts/");
define("DOMPDF_FONT_CACHE", DOMPDF_DIR."/lib/fonts/");
define("DOMPDF_UNICODE_ENABLED", true);
define("DOMPDF_PDF_BACKEND", "CPDF");
define("DOMPDF_DEFAULT_MEDIA_TYPE", "print");
define("DOMPDF_DEFAULT_PAPER_SIZE", "letter");
define("DOMPDF_DEFAULT_FONT", "Roboto");
//define("DOMPDF_DEFAULT_FONT", "serif");
define("DOMPDF_DPI", 72);
define("DOMPDF_ENABLE_PHP", true);
define("DOMPDF_ENABLE_REMOTE", true);
define("DOMPDF_ENABLE_CSS_FLOAT", true);
define("DOMPDF_ENABLE_JAVASCRIPT", true);
define("DEBUGPNG", false);
define("DEBUGKEEPTEMP", false);
define("DEBUGCSS", false);
define("DEBUG_LAYOUT", false);
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");
define("DOMPDF_ENABLE_HTML5PARSER", true);
define("DOMPDF_ENABLE_FONTSUBSETTING", true);
[...]
As for the custom font not being called, I rewrote the dompdf_config.custom.inc.php file to accept "Roboto" as the default font (which is the site's default font to begin with).
 
 
And then, back to the main point. It actually would be best to utlize the second option you mentioned: "If that's not feasible you could write a script that parses a page for the printReady content (e.g. using DOMDocument) and uses a pre-defined stylesheet or grabs the head content to apply the document-defined styles." Because, there are sections of our website that are secured through a log in process, with all the necessary pages tagged at the top with a redirect to the log in page if the user ID isn't passed through. Like this. But how do I do that, and with what file? Is it just with the dompdf.php file, or do I do this to every single page to export a PDF from? I have little to no experience with DOMDocument, but I am assuming this is what you are referring to?
 
Here is the dompdf.php file in full:
 
<?php
/**
 * Command line utility to use dompdf.
 * Can also be used with HTTP GET parameters
 *
 * @package dompdf
 * @link   
http://dompdf.github.com/
 * @author  Benj Carson <benjc...@digitaljunkies.ca>
 * @license
http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 */
/**
 * Display command line usage
 */
function dompdf_usage() {
  $default_paper_size = DOMPDF_DEFAULT_PAPER_SIZE;
 
  echo <<<EOD
 
Usage: {$_SERVER["argv"][0]} [options] html_file
html_file can be a filename, a url if fopen_wrappers are enabled, or the '-' character to read from standard input.
Options:
 -h             Show this message
 -l             List available paper sizes
 -p size        Paper size; something like 'letter', 'A4', 'legal', etc. 
                  The default is '$default_paper_size'
 -o orientation Either 'portrait' or 'landscape'.  Default is 'portrait'
 -b path        Set the 'document root' of the html_file. 
                  Relative urls (for stylesheets) are resolved using this directory. 
                  Default is the directory of html_file.
 -f file        The output filename.  Default is the input [html_file].pdf
 -v             Verbose: display html parsing warnings and file not found errors.
 -d             Very verbose: display oodles of debugging output: every frame
                  in the tree printed to stdout.
 -t             Comma separated list of debugging types (page-break,reflow,split)
 
EOD;
exit;
}
/**
 * Parses command line options
 *
 * @return array The command line options
 */
function getoptions() {
  $opts = array();
  if ( $_SERVER["argc"] == 1 )
    return $opts;
  $i = 1;
  while ($i < $_SERVER["argc"]) {
    switch ($_SERVER["argv"][$i]) {
    case "--help":
    case "-h":
      $opts["h"] = true;
      $i++;
      break;
    case "-l":
      $opts["l"] = true;
      $i++;
      break;
    case "-p":
      if ( !isset($_SERVER["argv"][$i+1]) )
        die("-p switch requires a size parameter\n");
      $opts["p"] = $_SERVER["argv"][$i+1];
      $i += 2;
      break;
    case "-o":
      if ( !isset($_SERVER["argv"][$i+1]) )
        die("-o switch requires an orientation parameter\n");
      $opts["o"] = $_SERVER["argv"][$i+1];
      $i += 2;
      break;
    case "-b":
      if ( !isset($_SERVER["argv"][$i+1]) )
        die("-b switch requires a path parameter\n");
      $opts["b"] = $_SERVER["argv"][$i+1];
      $i += 2;
      break;
    case "-f":
      if ( !isset($_SERVER["argv"][$i+1]) )
        die("-f switch requires a filename parameter\n");
      $opts["f"] = $_SERVER["argv"][$i+1];
      $i += 2;
      break;
    case "-v":
      $opts["v"] = true;
      $i++;
      break;
    case "-d":
      $opts["d"] = true;
      $i++;
      break;
    case "-t":
      if ( !isset($_SERVER['argv'][$i + 1]) )
        die("-t switch requires a comma separated list of types\n");
      $opts["t"] = $_SERVER['argv'][$i+1];
      $i += 2;
      break;
   default:
      $opts["filename"] = $_SERVER["argv"][$i];
      $i++;
      break;
    }
  }
  return $opts;
}
require_once("dompdf_config.inc.php");
global $_dompdf_show_warnings, $_dompdf_debug, $_DOMPDF_DEBUG_TYPES;
$sapi = php_sapi_name();
$options = array();
switch ( $sapi ) {
 case "cli":
  $opts = getoptions();
  if ( isset($opts["h"]) || (!isset($opts["filename"]) && !isset($opts["l"])) ) {
    dompdf_usage();
    exit;
  }
  if ( isset($opts["l"]) ) {
    echo "\nUnderstood paper sizes:\n";
    foreach (array_keys(CPDF_Adapter::$PAPER_SIZES) as $size)
      echo "  " . mb_strtoupper($size) . "\n";
    exit;
  }
  $file = $opts["filename"];
  if ( isset($opts["p"]) )
    $paper = $opts["p"];
  else
    $paper = DOMPDF_DEFAULT_PAPER_SIZE;
  if ( isset($opts["o"]) )
    $orientation = $opts["o"];
  else
    $orientation = "portrait";
  if ( isset($opts["b"]) )
    $base_path = $opts["b"];
  if ( isset($opts["f"]) )
    $outfile = $opts["f"];
  else {
    if ( $file === "-" )
      $outfile = "dompdf_out.pdf";
    else
      $outfile = str_ireplace(array(".html", ".htm", ".php"), "", $file) . ".pdf";
  }
  if ( isset($opts["v"]) )
    $_dompdf_show_warnings = true;
  if ( isset($opts["d"]) ) {
    $_dompdf_show_warnings = true;
    $_dompdf_debug = true;
  }
  if ( isset($opts['t']) ) {
    $arr = split(',',$opts['t']);
    $types = array();
    foreach ($arr as $type)
      $types[ trim($type) ] = 1;
    $_DOMPDF_DEBUG_TYPES = $types;
  }
 
  $save_file = true;
  break;
 default:
  if ( isset($_GET["input_file"]) )
    $file = rawurldecode($_GET["input_file"]);
  else
    throw new DOMPDF_Exception("An input file is required (i.e. input_file _GET variable).");
 
  if ( isset($_GET["paper"]) )
    $paper = rawurldecode($_GET["paper"]);
  else
    $paper = DOMPDF_DEFAULT_PAPER_SIZE;
 
  if ( isset($_GET["orientation"]) )
    $orientation = rawurldecode($_GET["orientation"]);
  else
    $orientation = "portrait";
 
  if ( isset($_GET["base_path"]) ) {
    $base_path = rawurldecode($_GET["base_path"]);
    $file = $base_path . $file; # Set the input file
  } 
 
  if ( isset($_GET["options"]) ) {
    $options = $_GET["options"];
  }
 
  $file_parts = explode_url($file);
 
  /* Check to see if the input file is local and, if so, that the base path falls within that specified by DOMDPF_CHROOT */
  if(($file_parts['protocol'] == '' || $file_parts['protocol'] === 'file://')) {
    $file = realpath($file);
    if ( strpos($file, DOMPDF_CHROOT) !== 0 ) {
      throw new DOMPDF_Exception("Permission denied on $file. The file could not be found under the directory specified by DOMPDF_CHROOT.");
    }
  }
 
  $outfile = "dompdf_out.pdf"; # Don't allow them to set the output file
  $save_file = false; # Don't save the file
 
  break;
}
$dompdf = new DOMPDF();
if ( $file === "-" ) {
  $str = "";
  while ( !feof(STDIN) )
    $str .= fread(STDIN, 4096);
  $dompdf->load_html($str);
} else
  $dompdf->load_html_file($file);
if ( isset($base_path) ) {
  $dompdf->set_base_path($base_path);
//  $dompdf->set_base_path(realpath(APPLICATION_PATH . '/css/gumby.css')); (I tried this line of code originally, but since removed it after it proved to be of no help at all.)
}
$dompdf->set_paper($paper, $orientation);
$dompdf->render();
if ( $_dompdf_show_warnings ) {
  global $_dompdf_warnings;
  foreach ($_dompdf_warnings as $msg)
    echo $msg . "\n";
  echo $dompdf->get_canvas()->get_cpdf()->messages;
  flush();
}
if ( $save_file ) {
//   if ( !is_writable($outfile) )
//     throw new DOMPDF_Exception("'$outfile' is not writable.");
  if ( strtolower(DOMPDF_PDF_BACKEND) === "gd" )
    $outfile = str_replace(".pdf", ".png", $outfile);
  list($proto, $host, $path, $file) = explode_url($outfile);
  if ( $proto != "" ) // i.e. not file://
    $outfile = $file; // just save it locally, FIXME? could save it like wget: ./host/basepath/file
  $outfile = realpath(dirname($outfile)) . DIRECTORY_SEPARATOR . basename($outfile);
  if ( strpos($outfile, DOMPDF_CHROOT) !== 0 )
    throw new DOMPDF_Exception("Permission denied.");
  file_put_contents($outfile, $dompdf->output( array("compress" => 0) ));
  exit(0);
}
if ( !headers_sent() ) {
  $dompdf->stream($outfile, $options);
}

BrianS

unread,
Dec 30, 2013, 3:42:13 PM12/30/13
to dom...@googlegroups.com
See inline responses ...


On Sunday, December 29, 2013 3:19:14 PM UTC-5, Nathan Obral wrote:
I do know that, in the composition of the pages on my site, there are multiple stylesheets I have to invoke. The key one... gumby.css ... has to be invoked like so:
<link rel="stylesheet" href="../css/gumby.css" />
in order for the stylesheet to properly work. (I've tried multiple times using <link rel="stylesheet" href="http://www.superior-insulation.com/css/gumby.css" /> on the site in some form, with no luck whatsoever.)

I'm not sure why using the relative URL (../css/gumby.css) is not working. The URL parsing may be having issues with it for some reason, but using the full URL does appear to be OK. It just doesn't look to be the case because of the issue you outlined below.

 
As a result, the following stylesheets are included at the top of every page like so:
  <link rel="stylesheet" href="../css/gumby.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/css/style.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/css/bootstrap-fileupload.min.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/css/bootstrap-fileupload.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/css/additional.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/css/bootstrap-dropdown.min.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/css/bootstrap-dropdown.css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/images/css/jquery-ui.css" media="all" type="text/css" />
  <link rel="stylesheet" href="
http://www.superior-insulation.com/images/css/jquery-ui-timepicker-addon.css" media="all" type="text/css" />
 
It should also be noted that, when I do invoke the stylesheet as "<link rel="stylesheet" href="http://www.superior-insulation.com/css/gumby.css" />", I get the following friendly error message:
 
Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given, called in /hsphere/local/home/superior/superior-insulation.com/dompdf/include/table_frame_decorator.cls.php on line 312 and defined in /hsphere/local/home/superior/superior-insulation.com/dompdf/include/frame.cls.php on line 765
Is this because I do not compose the site with any tables? It's a DIV-powered website with a framework that discourages tables as the main source of page composition.

This is because you are using tables ... sort of. Some of the style declarations specify that certain elements should be treated as tables (e.g. .navbar ul { font-family: "Roboto Condensed", Helvetica, Arial, sans-serif; display: table; vertical-align: middle; margin: 0; float: none; }). So even if the framework discourages tables for layout, it's still basically using them for that purpose to some degree which is probably why you're getting the noted errors. You can define tables this way, but unless the full table structure is explicitly defined in the HTML/CSS the rendering client (dompdf) is supposed to fill out the missing pieces using anonymous table objects. Unfortunately dompdf does not yet fully support anonymous table objects.

It may be that this layout is too much for dompdf to handle right now. I'd have to dig deeper into the HTML/CSS to determine if things can be salvaged.

 
And then, back to the main point. It actually would be best to utlize the second option you mentioned: "If that's not feasible you could write a script that parses a page for the printReady content (e.g. using DOMDocument) and uses a pre-defined stylesheet or grabs the head content to apply the document-defined styles." Because, there are sections of our website that are secured through a log in process, with all the necessary pages tagged at the top with a redirect to the log in page if the user ID isn't passed through. Like this. But how do I do that, and with what file? Is it just with the dompdf.php file, or do I do this to every single page to export a PDF from? I have little to no experience with DOMDocument, but I am assuming this is what you are referring to?

Yes, that is the object I was suggesting you could try. But if you're passing it to dompdf.php then it's not really going to work. dompdf.php is basically a drop-in renderer for public content. To render private content you should write your own code using the class. You can include your login redirect on that page so only logged-in users can use it. Writing a page to utilize the dompdf class requires little code.

Nathan Obral

unread,
Dec 30, 2013, 6:26:19 PM12/30/13
to dom...@googlegroups.com
Thanks for the reply. What I did is created a new php file (literally titled "/dompdf/pdf.php") and adapted portions of code suggestions to construct the following experimental code:

<?php
require_once("dompdf_config.inc.php");
//$html = '<html><body>'.
// '<p>Put your html here, or generate it with your favourite '.
// 'templating system.</p>'.
// '</body></html>';

$link = $input;
$tagName = 'div';
$attrName = 'id';
$attrValue = 'printReady';

$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
@$dom->loadHTMLFile($link);

$html = getTags( $dom, $tagName, $attrName, $attrValue );
echo $html;

function getTags( $dom, $tagName, $attrName, $attrValue ){
    $html = '';
    $domxpath = new DOMXPath($dom);
    $newDom = new DOMDocument;
    $newDom->formatOutput = true;

    $filtered = $domxpath->query("//$tagName" . '[@' . $attrName . "='$attrValue']");
    $i = 0;
    while( $myItem = $filtered->item($i++) ){
        $node = $newDom->importNode( $myItem, true );    // import node
        $newDom->appendChild($node);                    // append node
    }
    $html = $newDom->saveHTML();
    return $html;
}

$dompdf = new DOMPDF();

$dompdf->render();
$dompdf->stream("sample.pdf");

?>


As shown here, I did achieve some success in stripping out everything outside of the <div id="printReady"> ... </div> tags. The only three questions I have are:

1) How can this be reinterpreted as a PDF based on this stripped out HTML?

2) Is is possible to create a separate stylesheet devoid of the problematic "display: table" elements and link specifically to that?

3) Is the "Fatal error: Call to a member function build_tree() on a non-object in /hsphere/local/home/superior/superior-insulation.com/dompdf/include/dompdf.cls.php on line 678 " error message due to the fact that this stripped out code has no <html><body> ... </body></html> tags at the beginning and end (and consequently, why it will not interpret it as a PDF)? I got a bit confused in seeing if I could insert replacement code at the beginning and end.

BrianS

unread,
Dec 31, 2013, 10:32:52 AM12/31/13
to dom...@googlegroups.com
1) If you take out the echo $html; statement and add $dompdf->load_html($html); after you instantiate your dompdf object it should work fine.

2) Of course. You can insert a new link element into your $html, try prepending it to the content after you run getTags(), e.g. $html = ' <link rel="stylesheet" type="text/css" href="theme.css">' . $html;

3)  See #1. This is because you haven't yet loaded your HTML content into dompdf.

Nathan Obral

unread,
Feb 12, 2014, 2:52:43 PM2/12/14
to dom...@googlegroups.com
It works perfectly, as suggested on this thread.

Now that other issues with the website have settled down, I did want to ask about WYSIWYG and MYSQL callups (the backend of our website is MYSQL-driven and is dependent on cookies establishing a user is signed in; if they aren't, the page defaults to the standard login page).

I'd like to create another customized php file (let's call it "pdf1.php" for simplicity) based upon what has already been achieved, so that I could pdf pages from that backend area of the website.

Here's a standard example of how the website backend calls up MYSQL content. The actual table names and passwords are removed for security and have been boldened for distinction.

    $Host = "mysql1.server-provider.com";
    $User = "table_name";
    $Password = "password";
    $DBName = "DB_name";
    $Table_name = "user";
    $today_date = date("Y-m-d");
    $today_time = date("G:i:s");
    $link = mysql_connect($Host, $User, $Password) or die ('I cannot connect because ' .
    mysql_error());
    mysql_select_db($DBName);
    $id = $_COOKIE["username"];
    $strSQL = "SELECT * from user WHERE ((id) = '" . $_COOKIE["username"] . "')";
    $Result = mysql_db_query($DBName, $strSQL, $link);
    $Row = mysql_fetch_array($Result);
    $Permission_level = $Row[level];
    $strSQL2 = "SELECT * from another-table-that-lists-specific-projects WHERE ((id) = '$project_id')";
    $Result2 = mysql_db_query($DBName, $strSQL2, $link);
    $Row2 = mysql_fetch_array($Result2);

It's interesting to note that this code is stripped off from the WYSIWYG rendition of a page without an issue (that's to be expected, as the page has already been constructed), but that just can't work in a DOMPDF rendition, mainly because the code would be missing from the stripped out page, and thus, can't recognize the user as being signed in. If that makes sense. So it would have to be called somehow in the customized pdf1.php file... what would be the most practical way to do this?

Note that I know in advance that multiple pages would need to be reconciled due to similar issues with table settings (noted in your prior reply) although I had reformatted much of the existing tables to DIVs.

BrianS

unread,
Feb 14, 2014, 1:41:14 PM2/14/14
to dom...@googlegroups.com
How is the customized version (pdf1.php) created? If the user browses to pdf1.php then it would seem that you would still have access to all the information you need. If not we will need to know the work flow. Perhaps you can record the necessary information as part of the process.
Reply all
Reply to author
Forward
0 new messages