Trying to reduce top-margin PDF invoice
-
Great plugin!
Trying to create my own template but I’m not able to reduce the top-margin of the PDF document. Tried setting margin-top in the stylesheet on html, body and @page selector, but none of this works.Can you tell me if it’s possible setting a different top-margin to the PDF invoice with the CSS stylesheet? If so, can you give me a (CSS) code example?
-
Check line 71 in bewpi-document.php where you can change the params.
For a documentation for the MPDF instance params check here. You need to change
$margin-top
.Thank you for your support and swift reply. I’ve managed to adjust the top-margin, the settings are now: $mpdf = new mPDF(”, ‘A4’, 0, ‘opensans’, 17, 17, 17, 150, 5, 0, ”);
But the next update my settings will be gone…
If you allow me to do a suggestion: for people who want to create their own templates it would be great if the default MPDF-margins are set to zero, and are adjustable in the custom stylesheet.
Do you think that’s a possibility?Second, it would be great if you could select your custom in the template setting page, I now have to ‘hack’ bewpi-template-settings.php (see topic “Create my own template”), also gone after the next update…
If it’s possible to set the default MPDF-margins to zero and make a custom template selectable in the settings page, people are really free to create their own custom templates.
That would be a great improvement I think.I’ve updated the plugin. See changelog.
I’ve added a filter for the mpdf options. You can use
add_filter
to change them for your custom template. Unfortunately I can’t set the mpdf margins to zero, because mpdf isn’t very compatible with css only. If you found a solution please let me know and I will try it my self.I’m busy with a bigger release where I am refactoring the code of the complete plugin. In the next update I will add a filter to add your own template.
Again many thanks you for your support and swift action.
I’ve tested the filter functionality for the mpdf-options and it works like a charm, I will rate your plugin.
A last request concerning your remark about adding a filter to add your own template. It would be great to use the filter technique to give a developer the possibility of returning a custom filepath for the template directory. I suppose it must be possible to give the $template_folder variable in bewpi-invoice.php the value this filter returns.
This way a developer can store his or her template files savely in a directory inside the (child)theme (and outside the plugin) where they will not be overwritten or deleted after a plugin update (an important issue).
The developer could use the filter to return a value like: templatepath (or stylesheetpath for childthemes) + custom templatedirectory name.
I think this will be a huge improvement because now you are really free to create and preserve your own custom templates. Lots of clients will be happy with this possibility, you can use it to promote your plugin.
Thanks. You obvious know how to make it work. You could give it a try, fork the plugin and send me a pull request. That would be awesome! Would you like to and/or have some free time for it? ??
I am trying to find the time to add it as quickly as possible.
Hi Bas,
Sorry for the delayed response. Had some vacation past two weeks and now very busy…
Did you find some time to add the filter for a custom template filepath?Almost ready. ?? Will let you know if it’s ready.
See changelog and FAQ. I’ve added the ability to use custom tenplates. ??
Let me know what you think.Hi Bas,
I have tested your new version, I hope I did nothing foolish (!) but I notice the following issue’s.
1) A clean install (I’ve first removed the old plugin and everything related to it and installed the new version) generates a series of warnings:
Warning: scandir(/var/www/vhosts/xxx.nl/httpdocs/brandstof/wordpress/wp-content/uploads/bewpi-templates/invoices/simple/): failed to open dir: No such file or directory in /var/www/vhosts/xxx.nl/httpdocs/brandstof/wordpress/wp-content/plugins/woocommerce-pdf-invoices/includes/admin/settings/class-bewpi-admin-settings-template.php on line 560
Warning: scandir(): (errno 2): No such file or directory in /var/www/vhosts/xxx.nl/httpdocs/brandstof/wordpress/wp-content/plugins/woocommerce-pdf-invoices/includes/admin/settings/class-bewpi-admin-settings-template.php on line 560 Warning: array_merge(): Argument #2 is not an array in /var/www/vhosts/xxx.nl/httpdocs/brandstof/wordpress/wp-content/plugins/woocommerce-pdf-invoices/includes/admin/settings/class-bewpi-admin-settings-template.php on line 561
Warning: Invalid argument supplied for foreach() in /var/www/vhosts/xxx.nl/httpdocs/brandstof/wordpress/wp-content/plugins/woocommerce-pdf-invoices/includes/admin/settings/class-bewpi-admin-settings-template.php on line 563 Notice: Undefined offset: 0 in /var/www/vhosts/xxx.nl/httpdocs/brandstof/wordpress/wp-content/plugins/woocommerce-pdf-invoices/includes/admin/settings/class-bewpi-admin-settings-template.php on line 94
2) If after the installation I try to make an invoice in the CMS with the button ‘aanmaken’ I get an error:
Warning: require_once(header.php): failed to open stream: No such file or directory in /var/www/vhosts/wpoow.nl/httpdocs/brandstof/wordpress/wp-content/plugins/woocommerce-pdf-invoices/includes/abstracts/abstract-bewpi-invoice.php on line 332 Fatal error: require_once(): Failed opening required ‘header.php’ (include_path=’.:’) in /var/www/vhosts/wpoow.nl/httpdocs/brandstof/wordpress/wp-content/plugins/woocommerce-pdf-invoices/includes/abstracts/abstract-bewpi-invoice.php on line 332
No invoice is created.
I tried the following
– if I place the templatedirectory ‘micro’ in the directory ‘uploads/bewpi-templates/invoices/simple’ the error still appears…
– But, if I place my custom templatedirectory ‘brandstof’ in the directory ‘uploads/bewpi-templates/invoices/simple’ then the error disappears (!) and an invoice is created… (conform the custom template)
3) In your instruction how to use a custom template (plugin link ‘view details’ section FAQ ) you state:
“To easily get started, copy the default template files (including folder) called plugins/woocommerce-pdf-invoices/includes/templates/simple/micro to uploads/bewpi-templates/simple and rename the template folder micro to a template name you like.”
However this doesn’t work. If you follow this instruction you will not (!) see your custom template.
But I’ve noticed that directory uploads/bewpi-templates/invoices does contain a directory ‘simple’, and if you place your template files in this directory you will indeed see your custom template, it works.A simple solution of course could be to correct your instruction to something like: copy the default template files (including folder) called … to uploads/bewpi-templates/invoices/simple.
Hi, I customized the template pdf editing the top-margin in the file woocommerce-pdf-invoices/includes/abstracts/abstract-bewpi-document.php
My question is, to keep the changes in the next update, where do I save the edited file?
Regards, Teresa
Hello Teresa,
Unfortunately I didn’t noticed your post. Did you manage to make it work? You can check the FAQ.
Please let me know. ??Hello Bas,
I have done what it says in the FAQ “How to add your custom template?” but the only place to change the margin is in the file wp-content/plugins/WooCommerce-pdf-invoices/includes/abstracts/abstract-bewpi-document.php, and when I upgrade, lose changesRegards, Teresa
For changing the mpdf options I’ve added a filter. Try to add the following code to your themes functions.php.
function custom_bewpi_mpdf_options( $options ) { $options['OPTION_NAME'] = OPTION_VALUE; return $options; } add_filter( 'bewpi_mpdf_options', 'custom_bewpi_mpdf_options' );
Check abstract-bewpi-document.php starting at line 129 for all available options.
Let me know if it works.
Did you get it to work? Please let me know. ??
- The topic ‘Trying to reduce top-margin PDF invoice’ is closed to new replies.