Export PDF header

QuestionsExport PDF header
Gary Brett asked 9 years ago

Hi Abu, I am trying to output the logged in users name in the PDF header but cant seem to find a way to achieve it.. I use throughout the site to out users name, is the below in wrong format?

$opt["export"] = array("format"=>"pdf", "filename"=>"Adviser Monthly Invoice", "heading"=> '<?php echo userValue($_SESSION['uid'], "username"); ?>', "orientation"=>"landscape", "paper"=>"a4");

Thank you

7 Answers
Abu Ghufran answered 9 years ago

I tested this case and works as expected.

$_SESSION["uid"] = "Abu Ghufran";
$grid["export"] = array("format"=>"pdf", "filename"=>"my-file", "heading"=>"Invoice Details: ".$_SESSION["uid"], "orientation"=>"landscape", "paper"=>"a4");

Sample Code: http://pastebin.com/HMDA3FAr

Output PDF: http://easycaptures.com/0115674286

Gary Brett answered 9 years ago

Thanks Abu, that's an odd one, if I output <?php echo userValue($_SESSION['uid'], "username"); ?> in my page it displays Gary Brett, however if I use

$opt["export"] = array("format"=>"pdf", "filename"=>"Adviser Monthly Invoice", "heading"=>"Invoice Details: ".$_SESSION["uid"],"username", "orientation"=>"landscape", "paper"=>"a4");

it ouputs the number 3 which is my id in the users table, seems its ignoring the "username" code..

Gary Brett answered 9 years ago

Forgot to ask, your outputted pdf table looks nice with single table border and blue header, is that all done inside tcpdf?

Abu Ghufran answered 9 years ago

It looks to be the code logic on your end. PDF header is set with whatever you pass in 'heading' option.

The colors can be set using on_render_pdf handler: See the Code link: http://pastebin.com/HMDA3FAr

$pdf->SetHeaderCellsFillColor(30,70,99);
$pdf->SetHeaderCellsFontColor(255,255,255);

To increase pdf header font size, i changed:

$pdf->Cell( 0, 15, $this->options["export"]["heading"], 0, 1 );

with

$pdf->SetFont('helvetica', '', 15);
$pdf->SetHeaderCellsFontStyle('b');
$pdf->Cell( 0, 15, $this->options["export"]["heading"], 0, 1 );

$pdf->SetFont('helvetica', '', 12);

Gary Brett answered 9 years ago

Hi, looking at it a different way, could we include a column from the grid in the 'heading'?

$col["name"] = "adviser" + $col["name"] = "date_paid"

This would then output Invoice Details: Gary Brett 01.05.15

Thank you

Gary Brett answered 9 years ago

Fixed original query if it helps anyone –

$username = userValue($_SESSION['uid'], "username");
$opt["export"] = array("format"=>"pdf", "filename"=>"Adviser Monthly Invoice", "heading"=>"Invoice Details: ". $username, "orientation"=>"landscape", "paper"=>"a4");

Abu Ghufran answered 9 years ago

For your other query, it would not be simple.
Refer faq: How to show searched string as heading in PDF.

Your Answer

16 + 8 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?