ElkArte Community

Extending Elk => Addons => Topic started by: Spuds on August 13, 2014, 09:28:53 pm

Title: [ADDON] PDF Print
Post by: Spuds on August 13, 2014, 09:28:53 pm
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


License
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 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.

Repo
https://bitbucket.org/spuds_/elk-pdf
Source
https://bitbucket.org/spuds_/elk-pdf/src
Download
https://addons.elkarte.net/enhancement/Print-PDF.html
Title: Re: [ADDON] PDF Print
Post by: emanuele on August 14, 2014, 03:48:05 am
Coolnessssss! :D

/me likes when Spuds does experiments! ^-^
Title: Re: [ADDON] PDF Print
Post by: overscan on October 02, 2014, 05:37:26 am
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
Title: Re: [ADDON] PDF Print
Post by: emanuele on October 02, 2014, 05:54:57 am
Searching the net it looks like a compression issue.
I think Spuds should "copy" the attachments download code and add something like that:
Code: [Select]
		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).
Title: Re: [ADDON] PDF Print
Post by: overscan on October 02, 2014, 06:47:23 am
Yep - disabling compression fixes the error. Nice.
Title: Re: [ADDON] PDF Print
Post by: Spuds on October 02, 2014, 09:08:04 am
Cool, thanks for the debug, will make the update  :D
Title: Re: [ADDON] PDF Print
Post by: meetdilip on October 02, 2014, 05:38:58 pm
/me thinks it is a helpful add on
Title: Re: [ADDON] PDF Print
Post by: overscan on February 05, 2015, 08:46:24 pm
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.
Title: Re: [ADDON] PDF Print
Post by: emanuele on February 07, 2015, 08:20:45 am
Removed... wrong tab when posting about ILA... :-[
Title: Re: [ADDON] PDF Print
Post by: Spuds on February 07, 2015, 04:54:41 pm
Quote from: overscan – 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.
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.
Title: Re: [ADDON] PDF Print
Post by: Spuds on February 08, 2015, 05:40:00 pm
Did some updates so it will better handle external images, give it a whirl (download at the OP link)
Title: Re: [ADDON] PDF Print
Post by: Jorin on March 10, 2017, 12:42:07 am
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:

QuoteFPDF error: Interlacing not supported: attachments/11377_087368c3070226df31fd8fbcd4a6c00814707a5c.elk

There are some PNG files in the thread.
Title: Re: [ADDON] PDF Print
Post by: Spuds on March 11, 2017, 10:07:43 pm
Could you point me to the image that is causing the problem?
Title: Re: [ADDON] PDF Print
Post by: Jorin on March 13, 2017, 02:00:39 am
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.
Title: Re: [ADDON] PDF Print
Post by: Spuds on March 13, 2017, 09:23:23 am
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?
Title: Re: [ADDON] PDF Print
Post by: Jorin on March 13, 2017, 09:36:41 am
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).
Title: Re: [ADDON] PDF Print
Post by: Spuds on March 13, 2017, 10:06:34 am
Was finally able to duplicate the issue ... now on to fix it !
Title: Re: [ADDON] PDF Print
Post by: Spuds on March 13, 2017, 03:56:03 pm
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.
Title: Re: [ADDON] PDF Print
Post by: Jorin on March 13, 2017, 04:34:13 pm
Thank you, I will try it tomorrow.
Title: Re: [ADDON] PDF Print
Post by: Jorin on March 14, 2017, 01:57:23 am
Thank you, it works with the new version!  :)
Title: Re: [ADDON] PDF Print
Post by: Spuds on November 26, 2017, 05:47:39 pm
Updated package to support ElkArte 1.1
Title: Re: [ADDON] PDF Print
Post by: Jorin on June 07, 2018, 07:44:11 am
When clicking as a guest:

Code: [Select]
Fatal error: Call to undefined function fatal_lang_error() in /www/htdocs/xyz/hp_elkarte/sources/controllers/PDF.controller.php on line 55
Title: Re: [ADDON] PDF Print
Post by: Spuds on June 07, 2018, 04:51:52 pm
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.
Title: Re: [ADDON] PDF Print
Post by: Spuds on June 08, 2018, 02:05:22 pm
I updated the package, it should now be available on the addon site.
Title: Re: [ADDON] PDF Print
Post by: Jorin on June 10, 2018, 01:28:13 am
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.
Title: Re: [ADDON] PDF Print
Post by: Spuds on June 10, 2018, 11:54:40 pm
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.
Title: Re: [ADDON] PDF Print
Post by: Jorin on June 11, 2018, 01:14:39 am
If I do that, your PDF button is gone too.  :D
Title: Re: [ADDON] PDF Print
Post by: Spuds on June 11, 2018, 10:14:15 pm
Yes ... I think the option is simply on or off and its not a permission based feature, kind of strange really.
Title: Re: [ADDON] PDF Print
Post by: Spuds on May 04, 2021, 01:13:22 pm
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
Title: Re: [ADDON] PDF Print
Post by: optimizerdude on July 13, 2021, 11:02:54 pm
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!
Title: Re: [ADDON] PDF Print
Post by: Spuds on July 14, 2021, 09:49:37 am
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.
Title: Re: [ADDON] PDF Print
Post by: Spuds on November 06, 2022, 03:33:11 pm
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


To get the addon you can do one of two things:
Title: Re: [ADDON] PDF Print
Post by: Spuds on January 18, 2024, 01:57:29 pm
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


To get the addon you can do one of two things: