Page 1 of 1

TCPDF and GD2 compatibility

Posted: 14 Jun 2013, 12:27
by szablac
Hi,

I developed a component, which stores content in its own tables, not in Joomla's #__content table. I got a request from a client to save the displayed text into pdf.
I decided to use Phoca PDF for this purpose because of its flexibility and configurability. So I created new plugin for Phoca PDF to provide bridge to my component. For the simple cases everything works fine.
What I mean by simple cases:
- html text only
- html text and image files

In some cases I need to display generated images. I mean I use PHP GD2 library to draw images, for example charts. PDF cannot be displayed with these generated images. In IE I get the following error message: "TCPDF ERROR: [Image] Unable to get image."
Have you ever bumped into this problem or something similar?
Do you have experince with TCPDF and GD2 compatibility?
Any other suggestion is welcome. Thanks.

Re: TCPDF and GD2 compatibility

Posted: 17 Jun 2013, 11:34
by szablac
I found the solution to my problem. I share it with you, it may help someone.

When I generate images with GD2 functions, their HTML-code looks like this: (browsers can display them)

Code: Select all

<img src="data:image/png;base64,#some_encrypted_code_here#" />
TCPDF can display GD2-generated images in a PDF-file, if their code looks like this:

Code: Select all

<img src="@#some_encrypted_code_here#" />
So I had to put string-replace function into the code of my plugin:

Code: Select all

		$myHtmlContent = $document->getBuffer();
		$myHtmlContent = str_replace("data:image/png;base64,", "@", $myHtmlContent);
		
		$pdf->writeHTML($myHtmlContent, true);
And it works like a charm.

Re: TCPDF and GD2 compatibility

Posted: 20 Jun 2013, 18:38
by Jan
Hi, thank you very much for the guide.

Jan