PDF Generator: Is there something like this available?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
Woudloper

PDF Generator: Is there something like this available?

Post by Woudloper »

Is there a module or add-on available which can generate PDF documents from the current page that you have selected in 'CMS Made Simple'? Something the same like the 'print' link that is available?

I would like to have three options per page: print, pdf and e-mail if that is possible...

Hope to hear about this as I would like to see something like this working on one of my website I am currently developing.
Last edited by Woudloper on Fri Sep 09, 2005 3:56 pm, edited 1 time in total.
trick

Re: PDF Generator: Is there something like this available?

Post by trick »

sounds like a fairly simple idea if you ask me. you can use this: http://www.php.net/pdf to create the pdfs. I might do it myself, but I'm pretty busy and I don't have much use on this for my site.
Woudloper

Re: PDF Generator: Is there something like this available?

Post by Woudloper »

Thanx for that link. I did some further investigation about generating PDF documents based upon the information that is available on the page.

I have found the following two links which are actually quit usefull:
  • FPDF Library;
    FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library.
  • HTML2PDF Library;
    This library class has been created as the FPDF did not fully supported HTML rendering very well.
As I am not an expert in creating modules/add-ons for "CMS Made Simple" I will try to look at the skeleton module in order to see if I can manage getting this working. If someone else volunteers I will be quit happy as it will take me a long time (since my experience with PHP is only that I can read the code).

If I may say so we can best use the HTML2PDF Library as many of the documents contain HTML with tables, p, div and many other elements and those are supported by HTML2PDF. If possible I would like to be able to add a tag to the template so that when rendering a page you can click  e.g. a small PDF icon and render the PDF from the current page that is being displayed.

See post down below about another module. Which is better?
Last edited by Woudloper on Fri Sep 09, 2005 3:58 pm, edited 1 time in total.
megabob3
Power Poster
Power Poster
Posts: 498
Joined: Sat Jan 08, 2005 11:11 pm
Location: ITALY

Re: PDF Generator: Is there something like this available?

Post by megabob3 »

Very NICE!!!
Woudloper

Re: PDF Generator: Is there something like this available?

Post by Woudloper »

I assume you mean 'very nice' because I am trying to create a module for this specific functionallity?

Currently I am rewriting the Skeleton module into a PDFGenerator module and I have included the HTML2FPDF class and other stuff. Now I would like to create the function so that I will retreive the HTML content of the specific selected page and generate an PDF document.

First of all when the module is called I need to create a link to a page that will render the actual PDF file. The can be done by using the 'default' section within the 'DoAction' function. But how do I need to go further from this? Do I need to create an addional action and call that one within the above mentioned link?

Within the actual PDF generation I need to retrieve the HTML source of the current document. What is the best way to do this inside a module? Do I need to do this like followed:

Code: Select all

$query = "SELECT content FROM ".cms_db_prefix()."content_props WHERE content_id = ".$this->cms->variables['page']." AND prop_name=\"content_en\"";
or do I need to use the smarty functionality and use the caching of the page? If so could someone tell me or point me out (to some documentation) how to do this.

Note 1: See attached my first try. This is still a non working module and the call for creating the PDF is in the wrong action for 'DoAction'

Note 2: The module can be downloaded (right click, save link as) and remove the .txt at the end of the so the .zip file can be opened.

[attachment deleted by admin]
Last edited by Woudloper on Fri Sep 09, 2005 8:31 pm, edited 1 time in total.
Woudloper

Re: PDF Generator: Is there something like this available?

Post by Woudloper »

Above questions still stands, but I found another PDF Generator class for PHP, see:
What do you think. Which one is better? The above mentioned HTMLTOFPDF of the new found class HTML_ToPDF? Hope to hear from you.
User avatar
sjg
Power Poster
Power Poster
Posts: 310
Joined: Thu Jan 27, 2005 5:11 pm
Location: Los Angeles, CA

Re: PDF Generator: Is there something like this available?

Post by sjg »

Here are my thoughts on this...

If you're just grabbing Content from pages and converting it into pdf, it should be fairly straightforward -- except for cases where the content is dynamic (say, generated by a module). This, however, would still only contain the page content, and would omit the template, any html blobs, etc.

If you want to generate an exact replica of a page, I'd recommend doing something sneaky like fetching the page into a variable, and then rendering that to PDF. I haven't used any of the PDF libraries, so I don't know how difficult that would be.

To fetch the page into a variable, do something like:

Code: Select all

$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while (!feof($handle)) {
  $contents .= fread($handle, 8192);
}
fclose($handle);
Or, if you can guarantee a PHP version of 4.3 or later, you can just use:

Code: Select all

$contents = file_get_contents('http://www.example.com/');
You'll still have to worry about importing any linked images, style sheets, etc.

Good luck!
Many modules available from the http://dev.cmsmadesimple.org
The CMS Made Simple Developer Cookbook is now available from Packt Publishers!
Woudloper

Re: PDF Generator: Is there something like this available?

Post by Woudloper »

sjg wrote: If you want to generate an exact replica of a page, I'd recommend doing something sneaky like fetching the page into a variable, and then rendering that to PDF. I haven't used any of the PDF libraries, so I don't know how difficult that would be.
Yes, that is what I want. When working with the 'content' information in the database I am not using the dynamically rendered content. I was totally forgetten this...
To fetch the page into a variable, do something like:

Code: Select all

$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while (!feof($handle)) {
  $contents .= fread($handle, 8192);
}
fclose($handle);
Or, if you can guarantee a PHP version of 4.3 or later, you can just use:

Code: Select all

$contents = file_get_contents('http://www.example.com/');
You'll still have to worry about importing any linked images, style sheets, etc.
This should be possible. So you mean that I need to modify the 'GeneratePDF.php' (which is in the above .zip file) so it will fetch the correct page based upon the input parameter...

Regarding the images, the second shown PDF Library (HTML_ToPDF) can handle images, but don't know how flexible that is, see the below quote:
The ability to convert images in the webpage to images embedded in the PDF. The script tries to convert relative image paths in to absolute ones as well.
alby

Re: PDF Generator: Is there something like this available?

Post by alby »

rustyparts.com | HTML_ToPDF: create PDF's on the fly
Rusty is better but you see README for requirements: html2ps, ps2pdf, java  etc.. :-(

With:
FPDF Library;
FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library.
HTML2PDF Library;
This library class has been created as the FPDF did not fully supported HTML rendering very well.
With FPDF Library and the similar project (live on FPDF Library) HTML2PDF Library I have a trouble with images (gif and a few png) and unicode (Do you see http://www.acko.net/node/56?).

Good job :-)
Last edited by alby on Mon Sep 12, 2005 4:33 pm, edited 1 time in total.
Locked

Return to “Modules/Add-Ons”