Unable to display background image in pdf - Suitecrm8

Hello there,

I am using Suitecrm 8.

It’s now more than a week that I have been trying to insert an image as background in a pdf template
with no success (I use the tinymce html editor).

At the beginning I found out that the url(’…) was truncated after saving. So looking for a solution
reading several topic about the same issue I found out a workaround commenting in the file /data/SugarBean.php the following two lines:

//$this->$key = SugarCleaner::cleanHtml($this->$key, true);
//$this->$key = SugarCleaner::cleanHtml($this->$key, true);

I did it and now the background url (’…) is no more truncated and I can see the image after saving the template.
Look the attached image showing the partial invoice pdf template after saving. It shows the earth image behind the table header.

Once I convert the template (invoice) to pdf the image does not show. It shows just the background
color If I set it.

The same image displays ok in the pdf if I insert it as simple image (src=…).

So as an alternative workaround I tried styling the image adding “position:absolute” and “z-index:-1”.
While editing everything is ok, but after saving the template, the two added style disappear.

Does anybody has a solution to display an image as background in pdf?

Thanks in advance
Mario

It seems nobody has a solution on this.

I know this is an old post, but hopefully this will help someone.

Haven’t been here in ages and this just came up in my use case, which is a very specific one where I only need one BG image for all my templates…so far. Also, the company I am working for is using 7.14.2. If the engine is still TCPDF, the solution I used was to alter the TCPDFEngine.php located at /lib/PDF/TCPDF/.

I created a new function:

public function addBackgroundImage($imgFile) {
	
$pageWidth = $this->pdf->getPageWidth();
$pageHeight = $this->pdf->getPageHeight();

    // Add the background image to each page
 $this->pdf->Image($imgFile, 0, 0, $pageWidth, $pageHeight, '', '', '', false, 300, '', false, false, 0);
}

The writeBlankPage() function is already there. Add this line:

 $this->addBackgroundImage('http://localhost/path/to/image');

Full Function:

public function writeBlankPage(): void
    {
        $this->pdf->AddPage();
		$this->addBackgroundImage('http://localhost/path/to/image');  
    }

I’m working on a better solution and will post if I find one :slight_smile:

Edit: Sorry for the bad formatting on the post @pgr

1 Like