Hi , is possible to change the background image on a pdf report ?

I try to change the background image based on onRecord event , with an databese image field , is possible to do ?

Not sure if you can do it in a onrecord event. If you have more records on your pdf things for sure will go wrong. But since it’s using tcpdf, you can use the functions directly too so all what’s possible in tcpdf, is possible in scriptcase.

You can only do that with custom coding. But it is tricky to find it out in detail.
If you insist I suggest you make one pdf with an image already properly placed. Then View the generated source code and you will see how scriptcase did it. Then copy the code you need and remove the backgroud again. Add the background code that scriptcase generated and put it in your own code section.
You can use sc_pdf_… functions (see the manual) and you need to study the tcpdf a bit as well.

Yes, but it is functional …


<?php
// Include the main TCPDF library (search for installation path).
include_once($this->Ini->path_third . '/tcpdf/tcpdf.php');

class ZNW_PDF extends TCPDF {

    // Page header
    public function Header() {
        // Quelle: http://www.tcpdf.org/examples/example_051.phps
        // get the current page break margin
        $bMargin = $this->getBreakMargin();
        // get current auto-page-break mode
        $auto_page_break = $this->AutoPageBreak;
        // disable auto-page-break
        $this->SetAutoPageBreak(false, 0);
        // set background image
        $img_file = '../_lib/img/sys__NM__zeitnachweis.png';
        $this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
        // restore auto-page-break status
        $this->SetAutoPageBreak($auto_page_break, $bMargin);
        // set the starting point for the page content
        $this->setPageMark();
    }

    // Page footer
    public function Footer() {
        
        // no special footer
        
    }
}
?>


// Include the main TCPDF library (search for installation path).
include_once($this->Ini->path_third . '/tcpdf/tcpdf.php');

// New PDF doc with class ZNW_PDF (Tools / Libraries / Project / znw_header_footer.php)
// Header with background image (A4)
$pdf = new ZNW_PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('me ...');
$pdf->SetTitle('Zeitnachweis');
$pdf->SetSubject('KIS Zeitnachweis');
$pdf->SetKeywords('KIS Zeitnachweis');

and so on ...

I have this code in my page code section in layout pdf.


//$lang='nl';
//$lang='en';

// create new PDF document
//$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
//$img_path=str_replace("", '/', $str);
// set document information
if ($lang=='nl'){
    sc_pdf_set_creator('TCPDF');
    sc_pdf_set_author('Rijksuniversiteit Groningen');
    sc_pdf_set_title('Betaling');
    $img_file=getcwd().'\..\_lib\img\BCK-NL.jpg';
}    
if ($lang=='en'){
    sc_pdf_set_creator('TCPDF');
    sc_pdf_set_author('University of Groningen');
    sc_pdf_set_title('Payment');
    $img_file=getcwd().'\..\_lib\img\BCK-EN.jpg';
}    



sc_pdf_image($img_file,0,0,21,29.70,'', '', '', false, 600, '', false, false, 0);    //image must be before PageMark

$this->Pdf->setPageMark(); //MultiCell,WriteCell,WriteHTML after this

// get the current page break margin
//$bMargin = $this->Pdf->getBreakMargin();
// get current auto-page-break mode
//$auto_page_break = $pdf->AutoPageBreak;
// disable auto-page-break
sc_pdf_set_auto_page_break(false, 0);
// set bacground image
//$img_file = K_PATH_IMAGES.'image_demo.jpg';
//$pdf->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
// restore auto-page-break status
//$pdf->SetAutoPageBreak($auto_page_break, $bMargin);
// set the starting point for the page content
//$pdf->setPageMark();
sc_pdf_set_xy(0,0,TRUE);


// set auto page breaks
//$pdf->SetAutoPageBreak(FALSE);
//$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
//$pdf->setImageScale(0.3); //PDF_IMAGE_SCALE_RATIO
//$pdf->SetPageMark();
// ---------------------------------------------------------

//Font for this page should be georgia
sc_pdf_set_font('Helvetica','',8);

// add a page
//$pdf->AddPage();

sc_pdf_write(1,'TEST TEST TEST');

//Close and output PDF document not needed it seems scriptcase does this
//$pdf->Output('testmike.pdf', 'I');

I am still fiddling on this code. Be aware that you can not run scriptcase functions in the code section (I reported this, so they may change it). The sc_pdf_* functions do seem to work…

If you want to use other pdf functions that are not available under tc_pdf_* then you can use $this->Pdf->x where is is the function you need.

In my (complete) code i have no sc_pdf_* functions. Only php and TCPDF-functions. But, i’m use for this report no SC report.

I dont understand your last comment. Anyway you can use sc_pdf_ functions AND $this->pdf if you use the pdf stuff from scriptcase or you can use tcpdf and do your own way (follow the awesome examples from the tcpdf lib).

Hello rr1.
Thx for this info.
Can you tell me where I can find the description of the sc_pdf_xxx functions?
I haven’t fond anything in the ScriptCase manual. There is only the list of functions but without the description about their parameters!
Thx a lot.

scriptcase uses sc_tc_pdf but it has made it a bit different then the original tc_pdf.
The functions are here: https://www.scriptcase.net/docs/en_us/v81/report-pdf-applications/report/pdf-layout/code

The tc_pdf funtions are here:
https://tcpdf.org/examples/ and you will find that the tc_pdf and the scriptcase.

Basically those libraries are the same. So if you want to find a function you can make it with tc_pdf functions of with sc_pdf funcions from scriptcase.
Both work fine.
So now about the background, see here:
https://tcpdf.org/examples/example_051/
The complete code for an example is there, made with tc_pdf functions which you can also do with sc_pdf_ functions…

Take into account that the tc_pdf library that scriptcase uses doesnt update so quickly as the original tc_pdf functions.

If you investigate here: https://tcpdf.org/examples/ you will see various examples of using the native tc_pdf functions. As far as I know almost all sc_tc_pdf functions are taken over as sc_tcpdf

https://www.scriptcase.net/docs/en_us/v9/manual/06-applications/12-reportpdf-application/05-pdf-advanced-settings/

Maybe you can use this?
https://tcpdf.org/examples/example_008/

Thx everyone. Very useful.
To add the image in the PDf, I made it with “sc_pdf_image()” within the “Layout PDF/Code” section of the ReportPDF application.
It works well like this: sc_pdf_image(’…/…/…/file/img/’ . $topImgName ,$topImgX,$topImgY,$topImgWidth,$topImgHeight, $fileExt);
And it does not work like this:
$dirPath = ‘…/…/…/file/img/’;
sc_pdf_image($dirPath . $topImgName ,$topImgX,$topImgY,$topImgWidth,$topImgHeight, $fileExt);
But I’d like to remove the hard coded directory part of the full path image name. I tried different ways and it never worked. It is like the forward slashes within a variable cause problems. I tried to escape them, I tried with backslashes … no success.
Any idea.

Using …/…/ etc is a bit tricky, you make yourself dependancies which you cant handle. In such case I would code from the root of your server. So not using …/…/ but just using a path from the root of your server.
I rather avoid these constructions and prefer to have direct paths from the root.

Thx rr1.
I totally agree with you.
But it looks like that SC does not “act” this way.
From within a ReportPDF application, in the “Layout PDF/Code” section, I was not able to reach the image folder other than with a relative path like “…/…/…/file/img/”.
Do you have any idea about the issue related to the path within a variable that is not interpreted correctly by the “sc_pdf-image” function ?
Thanks a lot.