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 bland print page.
It only supports basic html tags (bold, italic, links, div, lists, paragraphs, etc) and will include image attachments in the PDF. So nothing to fancy but seems to work in basic topic testing, YMMV ;)
Print to PDF
LicenseThis Elkarte addon is released under a BSD-3-Clause license.
IntroductionThis addon replaces the print button action to instead create a PDF of the topic for viewing / saving.
DependenciesUtilizes tFPDF by Ian Back, License: LGPL
Requires DomDocument (PHP)
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.
Repohttps://bitbucket.org/spuds_/elk-pdf
Sourcehttps://bitbucket.org/spuds_/elk-pdf/src
Downloadhttps://addons.elkarte.net/enhancement/Print-PDF.html
Coolnessssss! :D
/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)
ob_start('ob_gzhandler');
else
{
ob_start();
header('Content-Encoding: none');
}
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:
http://forum-alternative-antriebe.de/index.php/topic,6580.0.html
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?
Thank you!
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.
This ElkArte addon replaces the default print button with a create PDF. Clicking the PDF button will output a PDF to the browser of the current topic, including images and links. The user can then print or save the PDF.
The package file is large due to the included TTF fonts, so your server will need to support uploads of 4M ... if not use the download from addons site option as outlined below.
Here is what is new in V1.1.0
- This new version only supports ElkArte 1.1+
- Address various issues with PHP 8.1
- Update tfdpf library to pull in the latest tpdf updates (as of 1.84)
- Add support for WEBP attachments
- Fix issue where a topic image could be reused in the wrong post due to naming reuse in the library (a PDF optimization error)
- Fix issue where a normal below post attachment would cover the post text if preceded by a post with an ILA attachment
- Improve line spacing in lists
To get the addon you can do one of two things:
This ElkArte addon replaces the default print button with a create PDF. Clicking the PDF button will output a PDF to the browser of the current topic, including images, attachments, and links. The user can then print or save the PDF.
The package file is large due to the included TTF fonts, so your server will need to support uploads of 5M ... if not use the download from addons site option as outlined below.
Here is what is new in V1.2.1
- Address various issues with PHP 8.2
- Update tfdpf library to the latest (improved PHP 8.2 support)
- Improved processing / formatting of ILA and Gallery images
- Change to use DomDocument instead of the simple dom php library
To get the addon you can do one of two things: