Announcement

Collapse
No announcement yet.

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

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 ?

  • #2
    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.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      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.

      Comment


      • #4
        Originally posted by rr View Post
        You can only do that with custom coding. But it is tricky to find it out in detail.
        Yes, but it is functional ...

        Code:
        <?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
                
            }
        }
        ?>
        Code:
        // 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 ...
        Best regards: - Reinhard -

        I use ScriptCase 8 Enterprise Edition, Version 8.(latest)

        Comment


        • #5
          I have this code in my page code section in layout pdf.
          PHP Code:
          //$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,''''''false600''falsefalse0);    //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(false0);
          // 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.

          Comment


          • #6
            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.
            Best regards: - Reinhard -

            I use ScriptCase 8 Enterprise Edition, Version 8.(latest)

            Comment


            • #7
              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).

              Comment

              Working...
              X