Regarding inline php script

543 views
Skip to first unread message

Lakshman

unread,
Jul 26, 2011, 2:05:59 AM7/26/11
to dompdf
Hi,

I am trying to add php in line scrit.But i am not able to get
the result.plz help me. My code is like this.

File name :hello.php
--------------
<?php
require_once("../dompdf_config.inc.php");
$html =
'<html><body>'.
'<p>Hello World!</p>'.
'<script type="text/php"> echo "test123456"; </script>'.
'</body></html>';

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

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

?>


And also in dompdf_config.inc.php "DOMPDF_ENABLE_PHP" is enabled like
this.

def("DOMPDF_ENABLE_PHP", true);


So please help me where i am doing wrong..

Thanks
Lakshman

BrianS

unread,
Jul 26, 2011, 10:31:31 AM7/26/11
to dom...@googlegroups.com
On Tuesday, July 26, 2011 2:05:59 AM UTC-4, Lakshman wrote:
        I am trying to add php in line scrit.But i am not able to get
the result.plz help me. My code is like this.

File name :hello.php
                --------------
<?php
require_once("../dompdf_config.inc.php");
$html =
    '<html><body>'.
    '<p>Hello World!</p>'.
    '<script type="text/php"> echo "test123456"; </script>'.
    '</body></html>';

You can not use inline script to print some text into your PDF. The echo command will send the text to stdout, which in the case of a web page goes to the web browser. Inline script is mainly used to access the PDF library internals (e.g. to lay out text manually, add a password, etc.). See the FAQ for some inline script examples. For most layout options you can now use HTML+CSS only (in the 0.6.0 release).

Regarding the example code you posted, modifying it to read as follows would be more appropriate:

<?php
require_once("../dompdf_config.inc.php");
$html =
    '<html><body>'.
    '<p>Hello World!</p>'.
   "test123456".

    '</body></html>';

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

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

Considering the above, you can disable inline script, which we would definitely recommend if you don't need it. If your reason for wanting to use inline script is more complex you'll have to provide more details.
Reply all
Reply to author
Forward
0 new messages