How to use php variable inside pdf ->page_script()?

user3840738

How to use PHP variable inside $pdf->page_script(); Here is my code

<?php
<script type="text/php">
$pdf->page_script(\'
    if ($PAGE_NUM >= 2) {$pdf->image($var,"jpg",25,500,0,0);
    }
  \');

</script>

?>

I am getting an error Syntax error in $var.

BrianS

Inline script is run via the eval() function and any variables declared in the global scope are only accessible via the $GLOBALS superglobal ($GLOBALS['var']) or by initializing them with the global keyword (global $var).

I should note that if you're using dompdf 0.6.x you no longer have to specify the image type. You also appear to have the parameters backwards. The method looks for image path, x, y, width, then height.

The following should work:

<?php
<script type="text/php">
  $pdf->page_script('
    if ($PAGE_NUM >= 2) {
      $pdf->image(' . $GLOBALS['var'] . ',0,0,25,500);
    }
  ');
</script>
?>

Minor note: Since you're creating a page script I concatenated the image path variable with the rest of the script string. You can include that variable reference as part of the script rather than concatenate, but then you're performing additional look-ups on the variable every time the script is run. Though I must admin this is a minor performance consideration in the grand scheme of where this is running.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to use the jquery variable in script inside the PHP tag echo?

How to use php variable inside another one

What is $pdf in script and how to use page_text function to add text inside page dompdf?

How to use php variable inside a javascript code in a php code?

PHP Variable inside <Script> with \

In a bash script, how to use a variable inside a command and assign to a new variable?

How to use an external variable inside a class/function/object in php

How to use a php variable inside a form which is a value of innerHTML?

use php inside script

Use PHP Variable inside PHP string

How to use variable inside awk

How to use variable inside for loop

How to use {old,new}name inside a shell script variable?

How to use a javascript variable inside of a link_to tag that is in a script?

Use PHP variable in href inside of html inside of php?

How to use an awk variable inside an awk variable?

How to use jinja variable inside a variable

How to use variable inside variable in angular template?

use php variable inside javascript retuns null

Want to use href inside php variable

How to use $this inside php closure?

How to use php inside of javascript?

How do I insert a php variable inside javascript inside PHP

how to properly use incremental array variable inside str_replace() in PHP

How can I use PHP Class Method inside a function without using global variable?

How can we pass a variable from script inside php and set it to new a variable?(Closed)

How to use user defined variable inside of `IF` expression?

How to use C code variable inside system()

How to use environment variable inside Jenkinsfile