Adding elements to the PDF - tutorial

Permalink Browser Info Environment
Hi all

Thought this might be helpful to some. You can add elements to the PDF easily by amending the $htmlToSave variable in /packages/trans_marine_save_area_to_pdf/blocks/save_area_to_pdf/controller.php (I know it's not ideal to edit the controller, but there you go).

Look at around line 62:

$htmlToSave = ob_get_clean();


This grabs the HTML from the Area on your page which will be put into the PDF.

I've added my client's logo and the page title to the top of the PDF, and the URL it was downloaded from to the bottom:

Loader::helper('navigation'); // Necessary to get the page's URL
$addr = NavigationHelper::getLinkToCollection($c, true); // Get the page's URL
$htmlToSave = '<img src="/themes/username/images/headerlogo.png" />'; // Add the logo
$htmlToSave .= '<h1>'.$c->getCollectionName().'</h1>'; // Add page's title
$htmlToSave .= ob_get_clean(); // Add the Area's content (original line)
$htmlToSave .= '<p style="font-size: small; margin-top: 30px">Downloaded from '.$addr.'</p>'; // A line at the bottom with the page's URL


Note the concatenation operator ('.=' - very different from assignation: '=') which adds to the existing variable. If you don't use that, each new addition will replace the last, which isn't what you want in this context.

Attached is a finished example. It's not particularly pretty, but you can tweak the look of it further by adding inline CSS (like the 'style="font-size: small; margin-top: 30px"' above).

1 Attachment

Type: Discussion
Status: New
melat0nin
View Replies:
jstrong replied on at Permalink Reply
jstrong
Hey thanks for providing this, I know a lot of people have asked for a header feature I just haven't had time to update the block. Peace -J
bjalexander replied on at Permalink Reply
bjalexander
Thanks so much for posting this. Very helpful.
wasabili replied on at Permalink Reply
wasabili
Is it also possible to change the CSS for the PDF content?
melat0nin replied on at Permalink Reply
melat0nin
You can see I've added some inline CSS to the paragraph tag in the OP. I don't know exactly what styles PDFs support (especially in terms of altering layout), but font size and basic styles like bold/italic/underline should be fine I imagine (assuming you're using standard fonts). I would just experiment to see what you can come up with.
wasabili replied on at Permalink Reply
wasabili
Thank you I have seen that. But I ment to style within the content Element. Can I work here with an print.css and include that only as media=print? Is that working?
The idea is that I want to fomat the text in the content in not so wide.
wasabili replied on at Permalink Reply
wasabili
I made a test with a print.css but I didn't take it. Also the font is not corect implementet.
How can I change that?

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.