hello and thanks for the new version :)

i just installed the 6.x-1.0 version and the pdf that i had working before doesnt show the page numbers, but the first and last page. in the other releases before they worked. i put the number in the footer and i load it as the first field. i dont have any page break. if you need other information, please tell to me.
an example: http://mientrastanto.org/pdf/483

Comments

hunziker’s picture

Status: Active » Postponed (maintainer needs more info)

Your view is empty. Can you give me the export of your view, the resulting PDF and if existing the template files?

candelas’s picture

Title: header and footer: problem calculating the place and extra pages » page number only works in first and last page
Priority: Major » Normal
StatusFileSize
new89.03 KB

sorry, it was not published in the workflow and, of course, you couldnt see it.
now it is public
http://mientrastanto.org/1-las-agencias-de-rating-han-dejado-de-estar-ba...
i attach the view, and i use the display "pdf 1 articulo" for the pdf presentation.

edit since my clients are trying the site, they removed the article.
i attach a html http://drupal.org/files/issues/las-agencias-de-rating-han-dejado-de-esta... .

candelas’s picture

i upload the bad pdf because i am changing the web.
if i edit with 6.x-1.0-beta5 and save, and then use 6.x-1.0 and dont edit the row style of the pdf fields, it works.
the file was originally made in the beta5... can it have something to do?
but as soon i open and save the row style of the pdf fields, it starts to eat the numbers...
i hope it helps you to debug :)
http://drupal.org/files/issues/483.pdf

candelas’s picture

i found more information about this issue:

when i reported, i was making pdfs of one article, now i have been doing a magazine and i see that when a field has more than 2 pages, the page in the middle doesnt get the number. the same articles produced with 6.x.4 get the number ok. but i cant use it because has problems with the error that you resolved about theme on the new release.

i hope this helps to you to fix it :)

candelas’s picture

Priority: Normal » Major
StatusFileSize
new12.72 KB
new11.59 KB
new6.44 KB

hello

i created a very simple view to check this bug in style 'PDF unformatted'.
this bug it is not present in 6.x-beta4 and starts in beta5 and it is still in version 1.
i think it is related to "Minimal Space" new option on the user interface, but i can be wrong.

to reproduce: i attach the view and you need to create a node with a body of 3 pages or more:

  • the view created in 6.x-1.0 that only has a number field and a body.
  • 2 pdf: how it is seen if view is saved in 6.x-1.0 or in 6.x-beta4.

in a node that has 4 pages, what i found is:

  • if the view is saved with beta4:
    • the numbers and pages are ok in beta4.
    • beta5 and 1 and no extra pages but only first and last page get numbers. because this i think the problem comes from "Minimal Space".
  • if the view is saved with beta5 or 1:
    • the numbers are ok in beta4 and not extra pages.
    • in beta5 and 1, 2 white extra pages are added at the end, only first page has number in place and 6th page gets the number 5 out of place.

i hope this will help to you to find why and make this module even better than it is :)
thanks a lot

i put priority major since a client will not accept a pdf that has not all the numbers... if you think it is not, please change it.

candelas’s picture

more info:

all before was done in the footer.

with one element in the header and field in several pages: no extra pages but it only renderes in 1st and last page. (if it is in the footer it gets the 2 extra pages).

if you put 2 elements in the header/footer, things get crazzy not only with field more than one page.

and now i go to work in other part of the site, i hope this helps you to solve the problem :) thanks

candelas’s picture

Title: page number only works in first and last page » header and footer problem: problem calculating the place and extra pages

i think this tittle is better :)

candelas’s picture

Title: header and footer problem: problem calculating the place and extra pages » header and footer: problem calculating the place and extra pages
candelas’s picture

attach for comment #2

candelas’s picture

Title: page number only works in first and last page » header and footer: problem calculating the place and extra pages
Priority: Normal » Major
Status: Postponed (maintainer needs more info) » Patch (to be ported)

since i gave information, i think i can change the status... if i do wrong, please change it :)

candelas’s picture

Status: Patch (to be ported) » Needs work

my bad english ... :)

candelas’s picture

Title: header and footer: problem calculating the place and extra pages » header and footer: calculating if it has to be printed
Version: 6.x-1.0 » 6.x-1.x-dev

hello

since i finished the site but this problem, i come to see if i can help to detect what is going on :)

i downloaded the last dev version since i saw hunziker has renovated it (thanks).
i searched for the place where it is done and compared with the 6.x-1.x-beta4 where the numbers get ok.
i am tired and i didnt find a solution... but i put what i see, in case it helps.

in views_pdf_plugin_row_fields.inc, function render, line 36, the code changes from (first old version):

<?php 
                    if ($options['position']['object'] == 'header_footer') {
          // Set or update header / footer options
          $this->view->pdf->setHeaderFooter($row, $this->options, $this->view);
        }
?>

to

<?php 
       // Set or update header / footer options per row
        // this ensures that we write the last record for each page
        // in the cache.
        $this->view->pdf->setHeaderFooter($row, $this->options, $this->view);
?>

if i replace it, then the extra page disapears, but i get a number only in the first page.

if i mix both, then i am, without the first extra page and numbers at the begining and at the end. (i put the php tags for better reading)

<?php 
        $this->view->pdf->drawContent($row, $options, $this->view, $id);
               if ($options['position']['object'] == 'header_footer') {
          // Set or update header / footer options
          $this->view->pdf->setHeaderFooter($row, $this->options, $this->view);
        } $this->view->pdf->setHeaderFooter($row, $this->options, $this->view);
?>

mm all this is in a loop, and then you render the number out of it

<?php 
 // Reset the row page number
      $this->view->pdf->resetRowPageNumber();

?>

my problem is that i have fields that are 3 or more pages, so shouldnt the page counter be renewed in other way diferent than the number of items since one field can be in more than two pages?
i am not a programer, so for me this is toooo much :))))

i searched in internet an found a function for getting the page number independent of this loop... o.o
just in case that i am in the right direction, i paste it here:
font http://php.net/manual/en/ref.pdf.php bolyde at gmail dot com 12-Apr-2009 07:27

<?php
public function getNumPagesInPDF(array $arguments = array())
{
@list($PDFPath) = $arguments;
$stream = @fopen($PDFPath, "r");
$PDFContent = @fread ($stream, filesize($PDFPath));
if(!$stream || !$PDFContent)
    return false;
   
$firstValue = 0;
$secondValue = 0;
if(preg_match("/\/N\s+([0-9]+)/", $PDFContent, $matches)) {
    $firstValue = $matches[1];
}
 
if(preg_match_all("/\/Count\s+([0-9]+)/s", $PDFContent, $matches))
{
    $secondValue = max($matches[1]);
}
return (($secondValue != 0) ? $secondValue : max($firstValue, $secondValue));
}
?>

hunziker, any tips or ideas? :)

edit someone, in a different project but problems with long fields, say it used
"Print When Expression" set to "$V{PAGE_NUMBER} == 1" which is working,
http://jasperforge.org/plugins/espforum/view.php?group_id=83&forumid=101...

and i tcpdf: there is a variable (this i write for me, that hunziker sure knows :))))

$page (line 121)

* var: page number
* access: protected

and now to bed... let's see if we can solve tomorrow....

candelas’s picture

Title: header and footer: calculating if it has to be printed » header and footer: calculating if they have to be printed

my bad english... O.O

candelas’s picture

Title: header and footer: calculating if they have to be printed » header and footer: calculating when they have to be printed

my client ask for more changes and i dont find the solution to this bug... :(

candelas’s picture

bad bad... dont touch code when you are tired and the code is done by other person that knows much more than you... :)
dont do what i made because if a rule calls your view and you use views php, you get your functions duplicated... O.O

today that i can investigate for a while, i will look into views_pdf_template.php, since in line 152 i found this:

  /**
   * This method must be overriden, in the other case, some
   * output is printed to the footer.
   */
  function Footer() {
  
  }
  

also i will learn git.
if i dont get any results... i will have to use other module... what i dont want to since i like this one a lot and i have spent a lot of time learning how to use it...
any results, i will tell here :)

by the way, hunziker, thanks for commenting so well the code :)

candelas’s picture

i found a solution using the function Footer() while this bug is fixed
i posted it as a new issue to use for documentation
http://drupal.org/node/1255112

hunziker’s picture

I will try to resolve this issue. It is hard, because it is really deep in the code and the behavior is not always the same. With my test cases it works, so I need to investigate this.

essbee’s picture

I suspect this issue is also displaying itself in my use case.

I had a pdf displaying perfectly, but now in the latest version my headers and footers are all over the shop.
They mainly seem to print after the whole document on their own pages, but I also have a case where my header suddenly prints in the middle of a page.

In a pdf that should only be 3 pages long I have the following behaviour:
First page has page number but no other headers or footer info.
2nd page has page number and additional footer values but no header info.
3rd page has all header and footer information but one of the header fields is printing in the middle of the page not at the top.
4th page (erroneous) has perfect header information, additional footer information but no page number
5th page (erroneous) has all header information but no footer info.

Basically I am having the correct number of headers and footer printers in total (3 headers, 3 footers, 3 page numbers), they just aren't on the right pages :)

essbee’s picture

StatusFileSize
new114.44 KB

Attached is the example of my 7.x view issue. As can be seen the headers and footers are a bit of a mess.

essbee’s picture

Right so I have a view that prints headers and footers correctly.
Now in the latest version if I simply go into PDF Fields | Settings and click Apply then save - making no changes, the footers and headers break and go onto their own page.
Very strange behaviour. I can no loner adjust the settings in anyway as doing so kills my pdf.

digi24’s picture

I am just starting to use this module, but I think that this bug seems solveable. Right now, I have limited the Close function to only handle the first page. All subsequent pages are handled by the Header (OR Footer) function.

This works so far, header is displayed on every page, no empty pages, the remaining problem is now to take care of the margins in the drawContent function. Otherwise the header would overlap with multipage content

edit: More complicated than I thought, it seems that using a PDF template changes the whole behaviour. On the one hand, I am happy that this module works for me, on the other I have no solution for the bug either. Sorry about my optimism.

Makku01’s picture

Uncommenting line 762 in views_pdf_template.php solved the issue for me. Still wondering why it was commented...

    // When a new page is added, we copy the header / footer data from the prvevious page.
    // this ensures that we get always the data, independent on a page break
    // inside a record.
    if (isset($this->headerFooterData[($this->getPage() - 1)])) {
     //$this->headerFooterData[$this->getPage()] = $this->headerFooterData[($this->getPage() - 1)];
    }

EDIT: nope, that doesn't solve anything. Im in desperate need for a solution to print a footer on all (!) pages. Please, for the love of god, can anybody of the mantainers help me?

Makku01’s picture

Priority: Major » Critical
gillarf’s picture

I am having this same problem.

See http://www.travellingsnail.com/journalPDF/288

The footers and headers come and go - i cannot see why.

I have a simple header and footer and would be happy as a short term solution to use a hack (e.g. just to ge page number working!)

Thanks for the module though - its great.

gillarf’s picture

Ok, i can see what's happening in my case.

I am using 'Include Views' to add data into my PDF view from other views.

The footer and header only appear at the start of each new include view. The numbering is correct though.

Is there a way to override this and append a simple page numbering to my view (please somebody :-) )

I am willing to pay for the solution - i need this sorted this week.

gillarf’s picture

Just spotted this from @candelas above.

http://drupal.org/node/1255112

thanks that's useful. But i don;t really understand when those footer and header functions are called.

i still need to get 'title' out of my view to put into a header area, so i'll need to get that information into those functions.

gillarf’s picture

hmmm. that is useful, but it doesn't actually put content into the footer. I have no idea what these footer and header functions do.

However I was trying out different things, and placing:
$this->headerFooterData[$this->getPage()] = 'somehting';

In one of those functions fixed my footer. I have no idea why this should have fixed it. Now all page numbers appear, even those within included views...

candelas’s picture

@gillarf i didnt answer any of your doubts because i didnt use this module again and i didnt found other solution.
thanks for reporting your solution that i would try if i need this module again (probably).

gillarf’s picture

Thanks @candelas

@hunziker - please can you advise how I might hack the module to force the Header and Footers to appear (for example extract content from the view and output it to headers - at any convenient point in the execution)

I must admit, i'm struggling to understand how this module works.

simon georges’s picture

Status: Needs work » Closed (won't fix)

I apologize, the 6.x version is not maintained any more. This issue is close for this reason.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.