Support » Plugin: PDF Invoices & Packing Slips for WooCommerce » Conflict with rospdf ?
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'
yes, this appears to be a version conflict, see: https://github.com/dompdf/dompdf/pull/1851
Yes, i saw this post.
But what can I do now ?
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 ?
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 3 years, 8 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.
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.
I created a new plugin with composer.json and require rospdf only.
I only require autoloader when I need it and everything works.
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 ?
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' ) ); $invoice->save();
Note that this should preferably be done on
init20 or later because some elements are not loaded until
init15 to allow other plugins to hook into the process at
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.
Yes, with those exact lines of code from above, hooked into one of the WooCommerce actions. See: Create invoice number when receive order
- The topic ‘Conflict with rospdf ?’ is closed to new replies.