Print pdf: Take a field only once

Hi all,
I’m trying to resolve a request about pdf printing: when I select and print multiple records in a custom module, the content of the “my_field” field only needs to be printed once.

Is there a way to get this?
I’m looking at formLetterPdf.php and the other files but I don’t know exactly where to intervene.

Any suggestion is very welcome.
Thanks!

That sounds like grouping which you can do from Reports module… and then export as PDF

Unfortunately t’s pretty complicated. Now I’m using the slightly customized formLetterPdf.php on listview because I need a header and a footer. In this case, the “$pdf-> AddPage ();” row doesn’t run and I have the records printed one after the other.

What I just don’t know is how to intercept a specific field and print it only once.

I’m not sure, this is just from a quick glance at the code, but maybe you could try unsetting the field from $object_array before this line:

$converted = templateParser::parse_template($text, $object_arr);

(although you could simply omit it from the template, and it wouldn’t print!

And then just print the field in the header.

The first tip is more to my case. Thank you. I’ll be back with a feedback.

Hi,
in the end I’m trying another way.

I already have a slightly changed “formLetterPdf.php” at this point:

 if ($bean->module_dir != 'my_module') {
			$pdf->AddPage();
}

This allows me to print my_module records from listview in a table, row by row.
(it is perhaps an incorrect change but it does what I need.)

So, now I’m basically trying to add a page first of all. This page has different content, may have different header and footer, or may not have them at all (this is not critical but it cannot have template header and footer).

Well, I can add “Hello world” in front of everything from code (always just for my_module with an if):

before “foreach ($recordIds as $recordId) {”:

$cnt = "Hello world";

	ob_clean();
	try {
		//$pdf->SetHTMLHeader($header);	
		$pdf->AddPage();
		$pdf->setAutoFont();
		//$pdf->SetHTMLFooter($footer);
		$pdf->writeHTML($cnt);

    } catch (mPDF_exception $e) {
        echo $e;
    }

But it happens that the generation of the pdf prepends the header before the creation of the new page, so my next page (the one generated inside the for each loop) loses the header (which starts from the second page instead.

So, is there a way to create some sort of break section between the first page and the next create with standard “for each” in order to take the header from the first page?

Thank you very much … I hope I have explained a little …

You probably need to investigate this in mPDF documentation/community… how to create separate sections, I’m sure it’s possible.

1 Like

Great tip!
In fact, all you need is in their guide.
Just play with AddPage () where you can set many parameters (even different headers for odd and even pages). Thanks!

Cool

when you’re finished, if you can share your code that might be helpful for others in the future…