• Hi,

    We have orders printing to a zebra label printer via our woocommerce and a plugin called print orders, we are trying to add pages numbers to the label using dompdf, I have searched the forums and found the code but do not know where to put it, I have tried google cloud plugin header as it is type/php, I have tried functions.php and tried the template file from the plugin but it does not work.

    Any advice this is the code below

    <script type=”text/php”>
    if ( isset($pdf) ) {
    $pdf->page_script(‘
    if ($PAGE_COUNT > 1) {
    $font = Font_Metrics::get_font(“Arial”, “normal”);
    $size = 7;
    $pageText = “Page ” . $PAGE_NUM . ” of ” . $PAGE_COUNT;
    $y = $pdf->get_height() – 80;
    $x = ($pdf->get_width() – Font_Metrics::get_text_width($pageText, $font, $size) ) / 2 ;
    $pdf->text($x, $y, $pageText, $font, $size);
    }
    ‘);
    }
    </script>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    That may work in Google Cloud, but putting PHP inside of script blocks does not work with Apache servers, PHP code needs to be within <?php ?> delimiters.

    Even with correct delimiters the code will not work unless the Font_Metrics class declaration is included in the code in some way. Then I’m seeing several variables and constants with no values assigned, these need to be resolved too.

    Thread Starter Chrisra

    (@chrisra)

    Hi, bcworkz,

    Currently without this code the orders come through from the plugin, what is the minimum PHP code would I need to get this to work as those values may not be needed.

    Moderator bcworkz

    (@bcworkz)

    Well, assuming the $pdf object has been properly initialized and you are able to assign values to all the parameters in the call to $pdf->text(), maybe something like this:

    <?php if ( isset($pdf) ) {
    $pdf->page_script('
    $font = Font_Metrics::get_font("Arial", "normal");
    $pdf->text(50, 500, "text example", $font, 7);
    ');
    } ?>

    But you still need the Font_Metrics class declaration to get the $font object. And since I don’t know what that class or the one for $pdf object actually do, I’d be very surprised if that worked.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘DOMPDF Page numbers’ is closed to new replies.