Closed (fixed)
Project:
Entity Print
Version:
7.x-1.x-dev
Component:
User interface
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
10 Sep 2015 at 19:25 UTC
Updated:
6 Nov 2017 at 15:44 UTC
Jump to comment: Most recent
Comments
Comment #2
benjy commentedThis is possible via a little bit of code. I'm open to adding admin settings for the globally available options for wkhtmltopdf, we could even allow per entity type overrides without too much effort.
Here's an example of how you'd implement hook_entity_print_pdf_alter() to adjust the settings.
Comment #3
benjy commentedAlso, all options are documented here: http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
We should probably update the docs with a few examples like this.
Comment #4
benjy commentedSettings to NR, will give this a few more days and then add this to the docs and mark as fixed.
Comment #5
mrpeanut commentedHere is what I have in my custom module:
I ran update.php and cleared cache but am still getting an A4 pdf.
Comment #6
benjy commentedAre you sure it's not working, Letter is only 5mm smaller than the default A4 so it could be hard to notice. See here for the sizes that are used: http://doc.qt.io/qt-4.8/qprinter.html#PaperSize-enum
Give A5 a try, that should be half the size of A4 and obvious for you to see.
Comment #7
mrpeanut commentedA5 is not working for me either. I even tried changing the orientation to landscape and still no change. Is
mymodule_entity_print_pdf_alterthe correct function? Is there a way I can test to see if that's being called? (The module itself is because I have other functions in it.)Comment #8
benjy commentedPut a die in the hook, the PDF won't be generated and execution will halt if the code is firing. Few obvious things to check:
* Make sure you've spelt the module and hook name correctly.
* Make sure the module is enabled
* Make sure you clear the cache.
If all that fails, paste the code here for me to see it.
Comment #9
mrpeanut commentedThe module is spelled correctly and enabled (I'm using other functions in the same module). I cleared cache. I put a die in the hook, and the PDF is still being generated. Here's my code (my module is mrpeanut.module):
Comment #10
benjy commentedCheck entity_print.info, what version do you have?
Comment #11
mrpeanut commentedWow, stupid mistake! I was originally on dev but had downloaded 1.3 when I was testing this. Sorry to waste your time! That works now.
Comment #12
benjy commentedGreat! I've added an example to the docs: https://www.drupal.org/node/2430561#overriding-page-size
Comment #13
nithinkolekar commentedI am trying to change views pdf page size and orientation using hook_entity_print_views_pdf_alter with the following code but pdf is still printing in default a4, portrait .
Also tried placing die() before and inside if statement but pdf is generating instead of exiting.
Comment #14
benjy commentedtwc_pdfprint_print_views_pdf_alter doesn't look right, if your module is twc_pdfprint then it should twc_pdfprint_entity_print_pdf_view_alter($pdf, $view)
I've just tagged 7.x-1.4 to prevent confusion as the hook wasn't in 7.x-1.3.
Comment #15
nithinkolekar commentedI tested by changing the function name (which was typo earlier) with updated 7.x-1.4 but it seems that hook in not called and watchdog message is not logging.
updated code
in your comment above you are mentioning hook_entity_print_pdf_view_alter($pdf, $view) but in api file it is hook_entity_print_views_pdf_alter(WkHtmlToPdf $pdf, $view) which one is correct?
Comment #16
benjy commenteddrupal_alter('entity_print_pdf_view', $pdf, $this->view);entity_print_pdf_view_alter() is correct, i used view instead of views. I'll fix up the api file.
Comment #17
nithinkolekar commentedok got it ... there is a small typo in hook name too.
// Allow other modules to alter the generated PDF object.
drupal_alter('entity_print_pdf_view', $pdf, $this->view);
hook_entity_print_view_pdf_alter
IMO hook_entity_print_views_pdf_alter is good which has the module name(entity_print_views) and we can easily identify it for pdf options.
Comment #18
benjy commentedOK, i've added an additional hook for hook_entity_print_views_pdf_alter().
Comment #21
maxplus commentedHi,
I'm also trying to change some settings for my views output but the view is not changing its output when I change some parameters.
This is my code in my theme template.php, am I doing something wrong?
Thanks!