Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
I wanted to create a simple pdf table with list of users. I have created a simple view with the users name and added a pdf page with the format pdf table. The users are shown in the table, but the header is missing. I have attached the view and the pdf.
How can I add the label (Name) in the table header?
Comment | File | Size | Author |
---|---|---|---|
#30 | views_pdf_double_header.jpg | 15.6 KB | calmforce |
#21 | views_pdf-print-table-th-2148103-10.patch | 1.63 KB | irishdan |
view.txt | 3.66 KB | Chipie | |
users.pdf | 9.4 KB | Chipie |
Comments
Comment #1
Priti197 CreditAttribution: Priti197 commentedI am facing the same problem. Data is appearing without table headers.
Comment #2
irishdan CreditAttribution: irishdan commentedSame here. Any ideas?
Comment #3
killua99 CreditAttribution: killua99 commentedMaybe the render or something ... I'll try to see it.
Comment #4
Priti197 CreditAttribution: Priti197 commentedI checked the code for rendering table header in views_pdf_template.php. I noticed that renderRow() function has got 8 parameters, and the $printLabels should be passed as TRUE so as to print the labels appropriately. So i made the below changes:
From: $this->renderRow($x, $y, $column->options['label'], $headerOptions);
To: $this->renderRow($x, $y, $column->options['label'], $headerOptions, $view, $id, TRUE);
And this made the table headers to appear properly.
@killua99 please check if the above changes are recommended, thanks.
Comment #5
killua99 CreditAttribution: killua99 commentedI'll take a look.
Comment #6
irishdan CreditAttribution: irishdan commentedchanging the line also printed headers correctly in the pdf, however it introduced a large amount of errors, for example:
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (regel 173 van XXX/includes/entity.inc).
Notice: Trying to get property of non-object in commerce_line_item_title() (regel 769 van XXX/sites/all/modules/commerce/modules/line_item/commerce_line_item.module).
Warning: Invalid argument supplied for foreach() in views_handler_field->advanced_render() (regel 1053 van XXX/sites/all/modules/views/handlers/views_handler_field.inc).
Comment #7
killua99 CreditAttribution: killua99 commentedWow ! these are all the error? basically are only warning and notice, nothing to really worry about it. But need some fix.
Comment #8
Priti197 CreditAttribution: Priti197 commentedHi killua99, have you got any fix for the above issue?
Comment #9
killua99 CreditAttribution: killua99 commentedWell pritihmhjn yesterday I rest a bit, but maybe today I can figure out what happen.
But I can see those warning could be for the reason that the "$view, $id" on of them are empty or NULL.
You know how to test it? did you know how to make patch etc?
Comment #10
irishdan CreditAttribution: irishdan commentedI got it to work for my situation like so:
sometimes $row is an object sometimes its string, when its string $content = $view->field[$key]->theme($row); produces all of those errors
i also added a check on the $content variable as sometimes it was empty leading to another error:
hope this helps other people.
cheers
Comment #11
killua99 CreditAttribution: killua99 commentedWithout a patch this didn't exist.
Awesome work but, without a patch I'm not gonna handle this.
A patch make you code much better and stable. Please try to submit a patch isn't so hard.
http://youtu.be/pFLLDQFC8yo
Comment #12
irishdan CreditAttribution: irishdan commentedYeah. I just needed to get it working for a project deadline and people seem to want a solution quick so i just posted the code. Will roll a patch as quick as i can.
dan
Comment #13
irishdan CreditAttribution: irishdan commentedHere's a patch
Comment #14
BBCJust trying out this module and ran into the same issue. Patch worked for me.
Thanks!
Comment #15
killua99 CreditAttribution: killua99 commentedAwesome, So the patch looks like solve this issue. But I have some issue with the code.
Empty tab need to be removed.
Tabs and spaces ... also why you compare twice this isset($view->field[$key])
tabs need to be removed
empty space, removed
same ... empty tabs removed.
same here
Comment #16
killua99 CreditAttribution: killua99 commentedComment #17
killua99 CreditAttribution: killua99 commentedI follow (and 90% of all the modules in drupal) the Drupal Coding Style. So I want to submit this patch but before fix this issues with the coding styling.
https://drupal.org/coding-standards
This link help you
thanks :D
Comment #18
giuseppe.minnella CreditAttribution: giuseppe.minnella commentedSame issue here. Patch solved. Thank you irishdan.
Comment #19
irishdan CreditAttribution: irishdan commented@killua grand. I'll take a look at the coding style issues and resubmit. Will have to wait until tomorrow though. Cheers
@giuseppe.minnella You're welcome
Comment #20
killua99 CreditAttribution: killua99 commentedExcellent! When you can irishdan!
Comment #21
irishdan CreditAttribution: irishdan commentedrerolled patch
Comment #22
killua99 CreditAttribution: killua99 commentedHuuuge better!.
Now I'm gonna test it and I'll submit this patch.
Thanks!
Comment #23
killua99 CreditAttribution: killua99 commentedThis issue needs review. I did some and I see not problem at all.
If in a week none one report a problem with this patch I'll commit it and close this issue.
Comment #24
swamiman CreditAttribution: swamiman commentedI created a PDF Table page and I got the headers to show using a patch on #21, but the problem is the table spans multiple pages. The headers only print on the first page and I need the headers to show up on all the pages. Any thoughts?
Comment #25
killua99 CreditAttribution: killua99 commentedI need to test it again.
@vegansupreme Just assigned to you if you have time to reviews this one as well (like a ping)
Comment #26
vegansupreme CreditAttribution: vegansupreme commentedPatch works for me.
@swamiman, it would be good to have headers on every page. Maybe this should be a separate issue though as the original problem appears to be solved.
Comment #27
killua99 CreditAttribution: killua99 commentedComment #30
calmforce CreditAttribution: calmforce commentedWith the fix that is in the current dev version the field labels are printed twice in the header, see the screenshot attached. If I disable "Create label" setting for a field then it doesn't show up at all. So I had to modify line 710 in views_pdf_template.php by replacing TRUE to FALSE, and now the header looks right.
Comment #31
calmforce CreditAttribution: calmforce commentedComment #32
calmforce CreditAttribution: calmforce commentedHere is the patch that I described in #30 above, it eliminates doubling a label in the table header
Comment #33
vegansupreme CreditAttribution: vegansupreme commented@calmforce
There's already an issue for table header printed twice.
#2270233: Table header printed 2 times
I quickly tested your suggested fix and it seems to work better than the current patch for that issue.
Would you be able to submit a patch for that issue? If not, please let me know.
Comment #34
vegansupreme CreditAttribution: vegansupreme commented@calmforce you beat me!
Can you please post this patch into #2270233: Table header printed 2 times
instead, and I'll keep this one closed?
Comment #35
calmforce CreditAttribution: calmforce commented@vegansupreme - will do, no problem.
Comment #36
vegansupreme CreditAttribution: vegansupreme commentedthanks calmforce!