This addon replaces the print button functionality (in a topic view) such that it creates a PDF suitable for saving or printing. There are no options, just install the addon and then when your select print it will generate and display a PDF instead of a print page.
I really did this as an experiment to play with FPDF so it only supports html basic tags and also includes image attachments in the PDF. So nothing fancy but seems to work in some basic testing, YMMV ;)
Print to PDF
This Elkarte addon is released under a BSD-3-Clause license.Introduction
This addon replaces the print button action to instead create a PDF of the topic for viewing / saving.Dependencies
Utilizes tFPDF (based on FPDF 1.7) by Ian Back, License: LGPL Features
o One-click creation of topic PDF's
o Includes topic image attachments in the PDF
o Maintains basic text formatting
o No source edits, all done with hooks.Repo
/me likes when Spuds does experiments! ^-^
Supercool idea ideal for my forum. However, when installed, it doesn't work.
On Chrome I get Cannot be displayed:
Error code: ERR_CONTENT_DECODING_FAILED
Searching the net it looks like a compression issue.
I think Spuds should "copy" the attachments download code and add something like that:
if (!empty($modSettings['enableCompressedOutput']) && strlen($out) <= 4194304)
after the ob_end_clean loop the file creation at:
https://bitbucket.org/spuds_/elk-pdf/src/327b68d7031f11dd8629fa3c17b6f5055474084d/sources/PDF.controller.php?at=master#cl-173 (line 173).
Yep - disabling compression fixes the error. Nice.
Cool, thanks for the debug, will make the update :D
/me thinks it is a helpful add on
So, I'm back on forum conversion from SMF after finishing my book.
This plugin is almost great but breaks if any image in the topic is missing or has any kind of error. Instead of a pdf you get lot of code and at the bottom something like:
FPDF error: Unsupported image type
FPDF error: can't find image xxxxx
This includes links to external images outside of the forum's control.
Can't do that to my users, pity as the PDF output is nice when it works.
At least trapping the error and saying "couldn't generate PDF due to missing images" would be essential.
Removed... wrong tab when posting about ILA... :-[
I'll take a look to see what I can do ... If I can trap the error I may just be able to replace it with the link (even if its bad) ... All depends on what FPDF is doing.
Did some updates so it will better handle external images, give it a whirl (download at the OP link)
I installed this addon today. Thanks for it! :)
Is it possible to change the addon so the PDF is opened in a new
tab/window? And maybe it's better if the button says "PDF" instead of "Print"?
Edit: I get an error:
There are some PNG files in the thread.
Could you point me to the image that is causing the problem?
Must be in this thread:
If you try to make a PDF out of it (button is called "PDF"), the error appears.
Strange ... I've copied all the images to my local and I can't duplicate the error. I know where in the code the error would occur, I just can't duplicate it :( What version of PHP and are you using GD or Imagick on your system?
Okay, it's not a browser problem, I have the error with both IE and Chrome. Phew! But maybe it's a problem with the image resize addon, which I installed at the same time? Sadly I don't know if the problem appeared before or after the image resize addon installation (http://www.elkarte.net/community/index.php?topic=1372.msg31176#msg31176).
It is PHP 5.6.29-nmm1 and Imagick 3.4.1. And GD seems to be there too, bundled (2.1.0 compatible).
Was finally able to duplicate the issue ... now on to fix it !
New version to test .. uninstall / delete the old and upload / install this one.
This also changes the button to say PDF, so whatever edit you made to do that should no longer be needed.
Thank you, I will try it tomorrow.
Thank you, it works with the new version! :)
Updated package to support ElkArte 1.1
When clicking as a guest:
Fatal error: Call to undefined function fatal_lang_error() in /www/htdocs/xyz/hp_elkarte/sources/controllers/PDF.controller.php on line 55
Yup ... thats what we call a bug :D
I'll fix that shortly, but I'm also going to "hide" the PDF button for guests since its not supposed to work for them anyway.
I updated the package, it should now be available on the addon site.
Okay, but the button "print" (not PDF!) as a guest is still there. It seems this is the old function? I can't disable "print for guests" because there is no such setting in the groups permissions for guests.
Yeah I noted that the print button was still there (that has nothing to do with the addon). I think to remove that you have to disable the print topic feature which I think is under the topic settings in the ACP.
If I do that, your PDF button is gone too. :D
Yes ... I think the option is simply on or off and its not a permission based feature, kind of strange really.
Update to version 1.0.8
- Updates to latest tfpdf library with better php 7.4 support.
- Adds basic limited support for inline images/attachments.
- Adds basic support for levertine gallery images.
- Fixes several layout issues with below post attachments.
Note, gallery and inline images are only rendered as left aligned images, so what you see and what you get will be different. There are many cases/variations and I did not want deal with them all. PR's are welcome if you want to improve on how images are handled.
See the first post for the link to the addon site
Can you add the ability to disable images all together for PDF Print?
Can you add the ability to see and use this addon based on permissions?
The permission to use the PDF function is, critically, tied to the "send topics to friends". Remove that permission and the PDF function should be disabled for those users.
I could easily add a feature to disable the images in the output, I'll see if I have time this weekend. If you are in a rush you can edit the elk-pdf class and set the validImageTypes variable to an empty array.