Jump to content

Module: Pages to PDF Module (Alpha)


almonk
 Share

Recommended Posts

Hi guys,

Had a client recently who needed to be able to turn pages from their Processwire driven site into a PDF. I took a look at how this best might be achieved and present here my rough workings of a 'Pages to PDF' module for Processwire.

** Please note** this is in no way a finished module and is tailored to the developers amongst you (not novice users) as it needs modification per project, but it should be a good starting step if anyone else needs to do anything similar.

See the screencast here:

http://f.cl.ly/items/3y2g2E0Q060K3G150h0B/Screeny%20Video%2013%20Sep%202011%2009.58.01.mov

Fork the code here:

https://github.com/almonk/pdfcomposer.module

Dependencies:

FPDF (included).

---

I'd love love love some more contributors to this to help improve it. For example, I'd like to have an ASMselect instead of the page list, but couldn't figure it out in the time I had.

Cheers,

Al

Link to comment
Share on other sites

Hi Alasdair,

I went through multiple PHP PDF generators lately, so let me share my experience and see if it helps;

I started with FPDF, because after testing with my workflow few years back, it was the simplest. I had to program un-utf function, because fpdf simply doesn't offer it, but other than that it was perfect. In these days, I needed to reintroduce PDF generation, so I took FPDF and reused. That UTF-8 unfriendliness was unfortunately showstopper for me, so I also went throgh TFPDF and IPDF I believe, both supposedly UTF-8 friendly forks of FPDF. Sadly, this was a no go, and TFPDF even was not very reliable – somehow, generation of numbers didn't work as expected, because some number were randomly not being generated.

After fghting with FPDF, TFPDF, and UPDF, I almost went back to tcpdf, which I tried years ago, but I found 'dompdf' – http://code.google.com/p/dompdf/ – which rather works. Its main plus is that the PDF's are generated from normal HTML code, are styled with CSS too (although CSS2.1 only). UTF-8 works without problems. The only downside I noticed so far is that PDF files generated by this are rather big – one A4 document can have up to 1.5MB so far. I believe this is due to me not going deep enough with this system – I used pre-compiled UTF fonts (that's nr. 1) and I also don't limit subset used, which I believe is possible and could help great deal. Also, if my suspicion is right, multiple paged PDFs wouldnt be as big, because if majority of that size is in fonts, any page other than the first would me much smaller addition to final size.

Hope this helps,

Adam

Link to comment
Share on other sites

  • 1 year later...

Almonk, this is a great module. Is it possible to get the PDF to render the print version of the page instead of just the items on the page? I poked around and noticed it grabs the body but am wondering how to get it to grab other items—I think I have a pretty good idea about this—along with the markup I've created for it in the template file. Is this possible? Like, PDF the page as I have created it, after PHP renders it? I'm unfamiliar with PDF generation so I'm not sure if this can be done but I thought I'd try asking. Thank you!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...