Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jcnventura’s picture

Status: Active » Postponed

I'll try to see if I can find some time for that. If you feel brave and write a patch, it would help a lot :)

Aleksey Zubko’s picture

We need some alter-implementation in function print_pdf_mpdf_print_pdf_generate . And we will can alter $mpdf before $mpdf->WriteHTML($html);
For example $mpdf->SetHTMLFooter('my footer');

ChristianAdamski’s picture

I would need that for a customer as well. Specifically

Header: 1 image + date and specific message
Footer: a bunch of icons + page number

So this would require a possibility to inject/modify header/footer on a per-document basis.
As this is probably not specific for mpdf, generic hooks to write header and footer would be required in the abstract print_pdf hooks already?
Libraries not allowing or implementing this could fall back to simply prepending/append this?

I would like to help & code, but I do not feel qualified to decide on the best approach on this.
If somebody advises me on the desired structure of interfaces, I could work out the actual insertion/printing.

ChristianAdamski’s picture

I just saw, this is currently done by a bunch of per-library functions?
Is this the way to go?

jcnventura’s picture

Yes. I think the problem started with the fact that the header/footers in TCPDF is so specific, that no generic function would apply there. And when the other PDF libraries came along, the possibility of having a generic header/footer never crossed my mind.. Feel free to suggest something different if you have the time.

zorax’s picture

Issue summary: View changes

Hi,
the function to override is in print_pdf_mpdf.pages.inc called print_pdf_mpdf_print_pdf_generate.
Just need to put :
$mpdf = new mPDF('UTF-8', $format);
$mpdf->SetHTMLFooter('my footer');

Can you just tell me how I can override this function ?
Regards,

zealfire’s picture

Status: Postponed » Needs review
FileSize
671 bytes

This patch inserts page number within the footer but needs testing.Hope it helps.
@zorax you are going right but for this to work you need to initialize a variable like margin_footer and then pass it within the function where you are creating an instance of class.

zealfire’s picture

FileSize
763 bytes

Attaching a new patch as previous included wrong details.

dianaalbert’s picture

Hi,
I need to add a header and footer on my project too, as well as change the default margins.
I've tried to add the:
$mpdf->SetHTMLFooter('my footer');
And modify the $format with the margins I need (on the new mPDF)
In print_pdf_mpdf.pages.inc
And also tried on the hook print_pdf_mpdf_alter on my template.php

But nothing seems to work.. The margins are still the default ones and no footer is appearing. Any ideas why?

zorax’s picture

Here is my code modified in the print_pdf_mpdf.page.inc file.
It adds a footer and header :

line 38
// Try to use local file access for image files
  $html = _print_access_images_via_file($html, $images_via_file);

  // set document information
 
  $mpdf = new mPDF('UTF-8', $format);
  $mpdf->setAutoTopMargin = 'stretch';
  $mpdf->setAutoBottomMargin = 'stretch';
  $mpdf->SetHTMLHeader('<div><img src="http://....../bandeau_pdf.jpg" width="800px" ></div>');
  $mpdf->SetHTMLFooter('<div class="pdf_date" style="color:black; text-align:left;" >{DATE j-m-Y}</div><div class="pdf_pagination" style="color:black; text-align:right;" >{PAGENO}</div>');
mandclu’s picture

Rather than hardcoding in a value which will likely only meet the needs of a single user, could the code be written to look for a tpl file and use the contents of that, if found?

virtuid’s picture

You can use varius method for defining header and footer (and much more) using special HTML tags in node.tpl.php just check http://mpdf1.com/manual/index.php?tid=253

bisonbleu’s picture

The link in #12 no longer works. Try this instead: https://mpdf.github.io/

Ada Hernandez’s picture

FileSize
1.27 KB

Hello everyone, I've needed a footer with its page number and I'm using mpdf library and print_pdf_mpdf so I needed to do some changes for give that. print module support a section for footer in admin/config/user-interface/print/common so if I checked User-specified and set Page {PAGENO} of {nb}, so footer was printed after of content not in footer page, so I've created a patch for modifying and fix this issue,

Ada Hernandez’s picture

this is not a different patch I just changed the path to print,

alex.87’s picture

You can also add it in template directly:

<htmlpagefooter name="myFooter" style="display:none;">
  // Here goes your custom code, field...
</htmlpagefooter>
<sethtmlpagefooter name="myFooter" value="on" />
shevgeny’s picture

Footer #15 ok.
Header?

jcnventura’s picture

  • jcnventura committed e952e99 on 7.x-2.x authored by Adita
    Issue #1619766 by zealfire, Adita, jcnventura: mPDF footers and headers
    
jcnventura’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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