Jump to content

problems with dompdf link for conversion


garbagedigger

Recommended Posts

I have a ajax/php driven website and I want to setup a link which uses dompdf.  I want to click on the link to convert the current page being viewed to pdf.

 

The current code that came with dompdf has a link feature like this except it looks for the physical webpage on the server and converts it to pdf and not the finished webpage being viewed on your web browser

 

Here is the original code for the link which pulls the physical webpage and inputs it to dompdf for pdf conversion:

 

<?php
$test_files = glob(dirname(__FILE__) . "/test/*.{html,php}", GLOB_BRACE);
$dompdf = dirname(dirname($_SERVER["PHP_SELF"])) . "dompdf.php?base_path=" . rawurlencode("www/test/");
foreach ( $test_files as $file ) {
  $file = basename($file);
  $arrow = "images/arrow_0" . rand(1, 6) . ".gif";  
  echo "<li style=\"list-style-image: url('$arrow');\">\n";
  echo $file;
  echo " [<a class=\"button\" target=\"blank\" href=\"test/$file\">HTML</a>] [<a class=\"button\" href=\"$dompdf&input_file=" . rawurlencode($file) .  "\">PDF</a>]\n";
  echo "</li>\n";
}
?>

 

I took and modified that code to use $_server[“php_self"]

 

<?php
$test_files = glob(dirname($_SERVER["PHP_SELF"]), GLOB_BRACE);
$dompdf = dirname(dirname($_SERVER["PHP_SELF"])) . "dompdf.php?base_path=" . rawurlencode($_SERVER["PHP_SELF"]);
foreach ( $test_files as $file ) {
  $file = basename($file);
  $arrow = "images/arrow_0" . rand(1, 6) . ".gif";  
  echo "<li style=\"list-style-image: url('$arrow');\">\n";
  echo $file;
  echo " [<a class=\"button\" target=\"blank\" href=\"$file\">HTML</a>] [<a class=\"button\" href=\"$dompdf&input_file=" . rawurlencode($file) .  "\">PDF</a>]\n";
  echo "</li>\n";
}
?>

 

After doing that, I get this error message:

 

DOMPDF_Exception: Requested HTML document contains no data

 

If I take rawurlencode on my modified code and tell it to use the url like this:

 

rawurlencode("http://local.example.com");

 

It converts and prints a pdf but it is the site's main page before you are logged in which is useless if you are logged in.

I need to somehow trick it to encode and print the ajax/php driven view my browser is displaying.  Is that even possible?  Iam guessing that I need to replace rawurlencode with something else and still use php_self.

 

Let me know if you need more information or details.

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.