We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin for PDF

Development and Programming

_xammax_'s avatar
_xammax_
31 posts
about 16 years ago
_xammax_'s avatar _xammax_

Hello, for my own needs I’ve made a simple plugin to print output in PDF (using TCPDF) on the fly directly from template file.

I mean:

<h1>hello world</h1>
This is for <b>EE 2</b> ...
<img src="http://example.com/image.jpg" alt=""  />
{exp:ee_tcpdf:params  title="This is the document title" author="{screen_name}" 
subject="Hi Man" keywords="Some Words"}
{!-- this tag can be placed every where in template file --}

or

{if segment_2 == 'test'}
  {exp:channel:entries channel="just_for_test"}
    {test_body}
    {exp:ee_tcpdf:params  title="{title_test}"}
  {/exp:channel:entries}
{if:else}
  {exp:channel:entries channel="example"}
    {example_body}
    {exp:ee_tcpdf:params logo="aaa.jpg"}
  {/exp:channel:entries}
{/if}

If someone is interested (for testing, etc) I’m going to post here the direct link to download it …

It’s a (really) “first release” (you can use it at your own risk 😊 but seems to work for my needs.

Max

ps. at this moment the package to download it’s very big because I’ve included the entire TCPDF library, but I’ll change this very soon …

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
about 16 years ago
Mark Bowen's avatar Mark Bowen

Hi Max,

Would definitely be interested in seeing the link posted to this as would like to try this out if that’s okay.

Best wishes,

Mark

       
_xammax_'s avatar
_xammax_
31 posts
about 16 years ago
_xammax_'s avatar _xammax_

Hi Mark,

Hi Max, Would definitely be interested in seeing the link posted to this as would like to try this out if that’s okay.

You can download from here: http://www.age38dev.com/EE_Tcpdf-0.0.1-20100414.zip (it’s a very heavy zip file because it contains the entire tcpdf library that I remove tomorrow)

It requires ExpressionEngine2 and PHP 5. Please read the file README-ENG.txt (I apoligize in advance for my poor english) for installations and tag params.

Thank you very much for your help.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
about 16 years ago
Mark Bowen's avatar Mark Bowen

Hi Max,

Thanks for that. Just tried it now and I’m probably just not understanding everything fully but I placed the example into a template and it did indeed come out as a PDF file which I viewed in the browser without any problems however I then went and deleted the plugin tags from the template and that template still comes out as a PDF. Not too sure why that would happen?

Also I notice that you have to set the font-family and font-size for the template in the plugin itself. Again it’s probably my misunderstanding but I thought that maybe this plugin would allow you to just place in a html document as per normal say using a stylesheet and then the plugin would just convert that into a PDF. Is that not possible?

Thanks again for providing the link, much appreciated. I can definitely see this being a fantastic plugin.

Best wishes,

Mark

       
_xammax_'s avatar
_xammax_
31 posts
about 16 years ago
_xammax_'s avatar _xammax_

Hi Mark,

… however I then went and deleted the plugin tags from the template and that template still comes out as a PDF. Not too sure why that would happen?

Ehm … this sound very strange! Please let me try to reproduce it and double check logic in the code, but for now can you confirm that you force a fresh GET request from browser? Sounds like a cache issue …

… I’m probably just not understanding everything fully …

The “mechanism” is very simple: thanks to the “display_override” hook all page are processed by EE_Tcpdf::output before send the request result to client browser. Using the {exp:ee_tcpdf:params} “comunicate” to EE_Tcpdf::output that “this” request have to print out in pdf format. If you not using the {exp:ee_tcpdf:params} the static var class named $pdf is always FALSE and so the content are simple returned …

Also I notice that you have to set the font-family and font-size for the template in the plugin itself.

Ops … I notice now that I’ve forgot to dynamically change font-family and font-size … I fix it now.

Again it’s probably my misunderstanding but I thought that maybe this plugin would allow you to just place in a html document as per normal say using a stylesheet and then the plugin would just convert that into a PDF. Is that not possible?

Ehm … Sorry but I don’t full understand this (please be patient with my english 😕 … Do you mean a specific stylesheet for pdf print-out that should be parsed by the plugin itself?

Hmmm … At this moment I do not check in deep to TCPDF functionalities (in particular for more format abilities) but let me check what it’s possible to do …

Thanks again for providing the link, much appreciated. I can definitely see this being a fantastic plugin.

Really thanks you for your help.

       
_xammax_'s avatar
_xammax_
31 posts
about 16 years ago
_xammax_'s avatar _xammax_

Mark, talking about format abilities for me this work:



Please note h1 e ul tags … I know this it’s not the best solution, but should be a starting point …

       
_xammax_'s avatar
_xammax_
31 posts
about 16 years ago
_xammax_'s avatar _xammax_
I then went and deleted the plugin tags from the template and that template still comes out as a PDF

Well, I have tried the class code with a php debugger also and seems to works as need. If you remove the {exp:ee_tcpdf:params} print out is not in pdf format … The issue you report seems about cache browser, you can easy check (fix) this adding a random string to force fresh request …

I’ve tried this also when I use conditional statement, example:

request client: /pdf/not_example

{if segment_2 == 'example'}
  <h1>in pdf format</h1>
  {exp:ee_tcpdf:params font-size="18"}
{if:else}
  <h1>just plain html please</h1>
{/if}

This for me works as expect (print out in standard way - not pdf)

Thanks again for your feedback.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
about 16 years ago
Mark Bowen's avatar Mark Bowen

Hi Max,

Regarding the formatting I was more referring to not having to do loads of inline styles on everything. I was hoping that you could just take a normal html template with embedded css etc… and it would just output straight to PDF.

With regards to the template still coming out as PDF I’m really not too sure what is happening there as I’ve deleted all browser caches, restarted the computer and all sorts but it’s still coming out as PDF :-(

Could it be because I’m testing this on a localhost install? I doubt that would be it though, would it?

Best wishes,

Mark

       
_xammax_'s avatar
_xammax_
31 posts
about 16 years ago
_xammax_'s avatar _xammax_

Hi Mark

Hi Max, Regarding the formatting I was more referring to not having to do loads of inline styles on everything. I was hoping that you could just take a normal html template with embedded css etc… and it would just output straight to PDF.

I’ve tried this:

<style>
h1 {color:red}
</style>
<h1>header</h1>

and

<link rel="stylesheet" type="text/css" href="layout.css" />
<h1>header</h1>

Both does not work. Instead like this:



… works. But I put more time in this to find a better solution …

With regards to the template still coming out as PDF I’m really not too sure what is happening there as I’ve deleted all browser caches, restarted the computer and all sorts but it’s still coming out as PDF :-(

Opsss … I’m not able to reproduce this issue in any way. If I remove the {exp:ee_tcpdf:params} tags from template and force a fresh request (I mean, old url with pdf print: /some/pdf … url forcing cache: /some/pdf/abc1234) the same template is print out as normal html page …

Later I publish a new version of this plugin (just small modifications), if you have again time and patience please give a try with the new ones (of course you can immediatly remove the plugin hook to fix this issue).

Could it be because I’m testing this on a localhost install? I doubt that would be it though, would it?

I do not think this is due to localhost install, in my opionion this seems due to a some kind of cache (server side or client side is my doubt) … Anyway, I investigate more for this prob.

Again, really many thank for all your help.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
about 16 years ago
Mark Bowen's avatar Mark Bowen

Hi Max,

Thanks for looking into this. Hopefully some other users will come across this and test it out as I know a lot of people have wanted this kind of functionality in the past. Really not sure why it is caching (if that is indeed what it is doing) as I have definitely gotten rid of all my caches on the computer so a bit confused as to why it’s doing this.

Will wait for your newer version and see if that changes anything.

Thanks again for releasing this for everyone to see though, that’s very kind of you.

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
about 16 years ago
Mark Bowen's avatar Mark Bowen

Hmm just tried again and if I just place a bog standard html template into the template in ExpressionEngine then it shows up as html. As soon as I place in the plugin tags even if they are commented out then it comes up as a PDF in the browser.

Seems that the plugin tags are being processed even if they are commented out (using ExpressionEngine comment method).

Does that happen to you too?

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
about 16 years ago
Mark Bowen's avatar Mark Bowen

Also one other thing I can’t get working is fonts. I tried this :



and I also tried :

{exp:ee_tcpdf:params logo="age38dev.jpg" language="eng" title="This is the title" author="Mark Bowen" subject="Hi Man" keywords="Some Words" font-family="Arial" font-size="22"}

in place of the plugin call in the code above but the page always comes out in Times every single time. Am I misunderstanding something somewhere perhaps?

Best wishes,

Mark

       
_xammax_'s avatar
_xammax_
31 posts
about 16 years ago
_xammax_'s avatar _xammax_
Hmm just tried again and if I just place a bog standard html template into the template in ExpressionEngine then it shows up as html. As soon as I place in the plugin tags even if they are commented out then it comes up as a PDF in the browser. Seems that the plugin tags are being processed even if they are commented out (using ExpressionEngine comment method). Does that happen to you too?

Yes, but just when I do not force the cache browser 😕 Let me publish the new version to be sure that hook process as request …

       
_xammax_'s avatar
_xammax_
31 posts
about 16 years ago
_xammax_'s avatar _xammax_

Hi Mark, font seems to be set per document, in your plugin version using font-family does not have any effect. I’ve yet fixed this for 0.0.2

Just one note:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="keywords, go, here" />
<title>Title</title>
</head>

This can be avoid because you can set this values via plugin tag params …

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
about 16 years ago
Mark Bowen's avatar Mark Bowen

Hi Max,

Thanks for the replies. Eagerly awaiting 0.0.2 for the font-family feature 😉

Thanks again for the hard work on this. All looks great so far.

Best wishes,

Mark

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.