Skip to main content
Topic: [ADDON] PDF Print (Read 15268 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[ADDON] PDF Print

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
Last Edit: January 18, 2024, 01:52:04 pm by Spuds

Re: [ADDON] PDF Print

Reply #1

Coolnessssss! :D

 emanuele likes when Spuds does experiments! ^-^
Bugs creator.
Features destroyer.
Template killer.

Re: [ADDON] PDF Print

Reply #2

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

Re: [ADDON] PDF Print

Reply #3

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).
Bugs creator.
Features destroyer.
Template killer.

Re: [ADDON] PDF Print

Reply #4

Yep - disabling compression fixes the error. Nice.

 

Re: [ADDON] PDF Print

Reply #5

Cool, thanks for the debug, will make the update  :D

Re: [ADDON] PDF Print

Reply #6

 meetdilip thinks it is a helpful add on

Re: [ADDON] PDF Print

Reply #7

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.

Re: [ADDON] PDF Print

Reply #8

Removed... wrong tab when posting about ILA... :-[
Last Edit: February 07, 2015, 11:15:58 am by emanuele
Bugs creator.
Features destroyer.
Template killer.

Re: [ADDON] PDF Print

Reply #9

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.

Re: [ADDON] PDF Print

Reply #10

Did some updates so it will better handle external images, give it a whirl (download at the OP link)

Re: [ADDON] PDF Print

Reply #11

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.

Re: [ADDON] PDF Print

Reply #12

Could you point me to the image that is causing the problem?


Re: [ADDON] PDF Print

Reply #14

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?