Support » Plugin: WooCommerce PDF Invoices & Packing Slips » Conflict with rospdf ?

  • Resolved Axel DUCORON



    I’m using “rospdf/pdf-php”: “0.12.52” and “wpackagist-plugin/woocommerce-pdf-invoices-packing-slips”: “2.2.14”.

    When I tried to generate invoice in order, I get the following error :

    Fatal error: Call to protected method Cpdf::getFirstPageId() from context 'Dompdf\Adapter\CPDF'


Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Ewout


    yes, this appears to be a version conflict, see:

    Yes, i saw this post.

    But what can I do now ?

    Plugin Author Ewout


    that depends on what you are using pdf-php for. If the version bundled with dompdf works for you, can you simply remove rospdf.

    I have an entire document writen with rospdf/pdf-php.

    I don’t know how can I use dompdf ? I need to rewrite all my document ?

    No other solution ?

    Plugin Author Ewout


    What I mean is: the Cpdf class bundled in dompdf is just another (older) version of the Cpdf class from rospdf. So the first thing to try before anything else is to turn remove rospdf/pdf-php to see if your code works with the older version that is bundled with dompdf.

    Alternatively you could utilize the mpdf extension for PDF invoices that uses mpdf instead of dompdf. But I would certainly test the above first.

    an alternative (perhaps even better) strategy is to look at where in your own application you call the autoloader that includes rospdf exactly. If you make sure it doesn’t get called in a context in which it’s not used, you will not have any conflicts with dompdf because I do the same thing in this plugin: the dompdf autoloader is only called when a PDF is actually requested (and I’m guessing you’re not creating both PDF files in the same request)

    • This reply was modified 9 months ago by Ewout. Reason: alternative strategy

    Hm yes, actually it’s the same autoloader for both.

    I need to call rospdf/pdf-php only when I need. But I don’t know how to do that.

    Plugin Author Ewout


    No sure what you mean by ‘it’s the same autoloader for both’… At which hook do you initiate yours? Ours is not initiated until the PDF is actually going to be created (which is on a specific admin-ajax action), and on no other occasion.

    Ok perfect.

    I created a new plugin with composer.json and require rospdf only.

    I only require autoloader when I need it and everything works.

    Thanks 🙂

    Other thing : I made a script to import woocommerce order from another site (old) to my site. I use wc_create_order();. Is it possible to manually assign (via code) an invoice number ?

    Plugin Author Ewout


    You can create an invoice programmatically with:

    $invoice = wcpdf_get_invoice( $order, true );

    In this case an invoice number will be assigned automatically and the ‘next invoice number’ will be incremented with a new value.

    If you want to set the invoice number and date manually you can leave out the true parameter for automatic init and use:

    $invoice = wcpdf_get_invoice( $order );
    $invoice->set_number( 987 );
    $invoice->set_date( strtotime( '2014-09-20' ) );

    Note that this should preferably be done on init 20 or later because some elements are not loaded until init 15 to allow other plugins to hook into the process at init 10.


    Thanks for this, it’s working nice.

    It’s posible after order to generate invoice number automatically ? Without click on “generate invoice” or “set invoice number”.

    Note : I don’t want to attach invoice in email. Just have the invoice number.


    Plugin Author Ewout


    Yes, with those exact lines of code from above, hooked into one of the WooCommerce actions. See: Create invoice number when receive order

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Conflict with rospdf ?’ is closed to new replies.