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:
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:
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).
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).
Type: | Discussion |
---|---|
Status: | New |
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
Thanks so much for posting this. Very helpful.
Is it also possible to change the CSS for the PDF content?
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.
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.
The idea is that I want to fomat the text in the content in not so wide.
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?
How can I change that?