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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Priti197’s picture

I am facing the same problem. Data is appearing without table headers.

irishdan’s picture

Same here. Any ideas?

killua99’s picture

Maybe the render or something ... I'll try to see it.

Priti197’s picture

I 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.

killua99’s picture

I'll take a look.

irishdan’s picture

changing 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).

killua99’s picture

Wow ! these are all the error? basically are only warning and notice, nothing to really worry about it. But need some fix.

Priti197’s picture

Hi killua99, have you got any fix for the above issue?

killua99’s picture

Well 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?

irishdan’s picture

I got it to work for my situation like so:


protected function renderRow($x, $y, $row, $options, &$view = NULL, $key = NULL, $printLabels = TRUE) {

   $pageDim = $this->getPageDimensions();

    // Render the content if it is not already:
    if (is_object($view) && $key != NULL && isset($view->field[$key]) && is_object($view->field[$key]) &&    (isset($view->field[$key])) ) {
    	if(!is_string($row)){
	      $content = $view->field[$key]->theme($row);
    	}
    }

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:


 // Write the content of a field to the pdf file:    
    if(isset($content)){
    	$this->MultiCell($w, $h, $prefix . $content, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml, $autopadding, $maxh, $valign, $fitcell);
    } else {
    	$this->MultiCell($w, $h, $prefix, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml, $autopadding, $maxh, $valign, $fitcell);
    }

hope this helps other people.

cheers

killua99’s picture

Without 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

irishdan’s picture

Yeah. 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

irishdan’s picture

Status: Active » Needs review
FileSize
2.96 KB

Here's a patch

BBC’s picture

Just trying out this module and ran into the same issue. Patch worked for me.

Thanks!

killua99’s picture

Awesome, So the patch looks like solve this issue. But I have some issue with the code.

  1. +++ b/views_pdf_template.php
    @@ -396,12 +396,14 @@ class PdfTemplate extends FPDI {
    +	  	¶
    

    Empty tab need to be removed.

  2. +++ b/views_pdf_template.php
    @@ -396,12 +396,14 @@ class PdfTemplate extends FPDI {
    +    	if(!is_string($row)){
    ...
    +    if (is_object($view) && $key != NULL && isset($view->field[$key]) && is_object($view->field[$key]) && (isset($view->field[$key])) ) {
    

    Tabs and spaces ... also why you compare twice this isset($view->field[$key])

  3. +++ b/views_pdf_template.php
    @@ -419,7 +421,7 @@ class PdfTemplate extends FPDI {
    +		
    

    tabs need to be removed

  4. +++ b/views_pdf_template.php
    @@ -505,7 +507,7 @@ class PdfTemplate extends FPDI {
    +    } ¶
    

    empty space, removed

  5. +++ b/views_pdf_template.php
    @@ -522,9 +524,12 @@ class PdfTemplate extends FPDI {
    +    // Write the content of a field to the pdf file:    ¶
    

    same ... empty tabs removed.

  6. +++ b/views_pdf_template.php
    @@ -691,8 +696,9 @@ class PdfTemplate extends FPDI {
    +      ¶
    

    same here

killua99’s picture

Status: Needs review » Needs work
killua99’s picture

I 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

giuseppe.minnella’s picture

Same issue here. Patch solved. Thank you irishdan.

irishdan’s picture

@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

killua99’s picture

Excellent! When you can irishdan!

irishdan’s picture

rerolled patch

killua99’s picture

Huuuge better!.

Now I'm gonna test it and I'll submit this patch.

Thanks!

killua99’s picture

Status: Needs work » Needs review

This 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.

swamiman’s picture

I 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?

killua99’s picture

Assigned: Unassigned » vegansupreme

I need to test it again.

@vegansupreme Just assigned to you if you have time to reviews this one as well (like a ping)

vegansupreme’s picture

Assigned: vegansupreme » killua99
Status: Needs review » Reviewed & tested by the community

Patch 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.

killua99’s picture

Assigned: killua99 » Unassigned
Status: Reviewed & tested by the community » Fixed

  • Commit fd43ac8 on 7.x-1.x authored by irishdan, committed by killua99:
    Issue #2148103 by irishdan, Chipie: Table Header ist not included in the...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

calmforce’s picture

FileSize
15.6 KB

With 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.

calmforce’s picture

Status: Closed (fixed) » Needs work
calmforce’s picture

Status: Needs work » Needs review
FileSize
666 bytes

Here is the patch that I described in #30 above, it eliminates doubling a label in the table header

vegansupreme’s picture

Status: Needs review » Needs work
Related issues: +#2270233: Table header printed 2 times

@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.

vegansupreme’s picture

@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?

calmforce’s picture

@vegansupreme - will do, no problem.

vegansupreme’s picture

Status: Needs work » Closed (fixed)

thanks calmforce!