1 (edited by advocaat.pollet 03/12/2023 07:35:50 pm)

Topic: Add massive Terms and Conditions/import PDF

Hi,

In an older thread (https://frontaccounting.com/punbb/viewtopic.php?id=6629) I found :

"You can have a generic PDF included into the invoice. Alternatively, you can have a link in the Invoice pointing to a PDF file hosted at your site. Use the TCPDF page number variables at will in the report."

But how can I include a PDF into an invoice ?

Thanks !

F.

Re: Add massive Terms and Conditions/import PDF

http://frontaccounting.com/punbb/viewtopic.php?id=4511

Re: Add massive Terms and Conditions/import PDF

Thanks apmuthu !

This is what I have done :

1/ Created my Terms and Conditions (2 pages), saved them in a pdf-file, named 'TermsAndConditions.pdf'.
2/ Placed this file in /reporting/forms.
3/ Made a new function 'TermAndConditions' in /reporting/includes/pdf_report.inc :

function TermsAndConditions()
    {
        if ($this->pageNumber > 1)
        {
        $tmpl_pdf = find_custom_file("/reporting/forms/TermsAndConditions.pdf");
            if ($tmpl_pdf) {
            $this->tmplSize = $this->setSourceFile($tmpl_pdf);
            }
        }

        if ($this->tmplSize)
        {
            for ($i = 1; $i <= $this->tmplSize; $i++) {
                parent::newPage();
                $id = $this->importPage(min($i, $this->tmplSize));
                $this->useTemplate($id);
            }

        }
    }

4/ In the reports where I need my Terms and Conditions (ex. 'rep107.php' (invoices)), before 'if ($email == 1) ...', added :

// START my modification
    $rep->TermsAndConditions();
    // END my modification

This works as expected (the report with Terms and Conditions is created as it must be), but I get a php-warning in Frontaccouting :

Trying to access array offset on value of type bool in file: /.../reporting/includes/fpdi/fpdi_pdf_parser.php op regel 336

What should be done ?

F.

Re: Add massive Terms and Conditions/import PDF

fpdi v1.2.1 is used in FA 2.4.x.

The warning may be safely ignored. The said line is:

if ($res[0] == PDF_TYPE_OBJECT)

It can better be modified as:

if ((gettype($res[0] == 'boolean' || gettype($res[0]) == 'integer' ) && $res[0] == PDF_TYPE_OBJECT)

Which version of PHP are you using?

The said constant is defined in reporting/includes/fpdi/pdf_parser lines 38, 39:

if (!defined ('PDF_TYPE_OBJECT'))
    define ('PDF_TYPE_OBJECT', 9);

It is probably expecting an 'integer' and not a 'boolean'.

Alternatively, the said line can be modified as:

$res[0] = $res[0]+0;
if ($res[0] == PDF_TYPE_OBJECT)

Re: Add massive Terms and Conditions/import PDF

Changed it like this :

function _getPageRotation ($obj) { // $obj = /Page
        $obj = $this->pdf_resolve_object($this->c, $obj);
        if (isset ($obj[1][1]['/Rotate'])) {
            $res = $this->pdf_resolve_object($this->c, $obj[1][1]['/Rotate']);
//DEV:
            if ($res[0] ?? 'default value' == PDF_TYPE_OBJECT)
//:DEV
                return $res[1];
            return $res;
        } else {
            if (!isset ($obj[1][1]['/Parent'])) {
                return false;
            } else {
                $res = $this->_getPageRotation($obj[1][1]['/Parent']);
//DEV:
                if ($res[0] ?? 'default value' == PDF_TYPE_OBJECT)
//:DEV
                    return $res[1];
                return $res;
            }
        }
    }

Solved the warning.

Re: Add massive Terms and Conditions/import PDF

The ?? construct is for later versions of PHP alone and will fail in PHP 5.x.
Verify that $res[0] is set to 9 before the if check.

No code change is required at all for PHP 5.x.
Kindly state your PHP version.

Re: Add massive Terms and Conditions/import PDF

Oh, PHP Version 8.0.23

Re: Add massive Terms and Conditions/import PDF

I guess its little messy way to customize the fpdi.


Its possible with a template header. And it can designed as a php file and put it inside the forms directory.

Before end of the myrow while loop there we need to call the newpage and set the header again. This header should call the file name which you dropped inside forms directory.

It will get you the  terms and conditions in a separate page after each invoice generated. 

Hope this will be less complicated then modifying the fpdi files.

Subscription service based on FA
HRM CRM POS batch Themes

Re: Add massive Terms and Conditions/import PDF

Hi kvvaradha,

I am no PHP-programmer, so please provide the code / instructions (dummy-proof ;-)).

It seems that the fpdi-files need an update for later PHP-versions.

I rewrote the function, and it works very well :

function TermsAndConditions()
    {
        $tmpl_pdf = find_custom_file("/reporting/forms/TermsAndConditions.pdf");
            if ($tmpl_pdf) {
            $this->tmplSize = $this->setSourceFile($tmpl_pdf);
            }
        for ($i = 1; $i <= $this->tmplSize; $i++) {
            $id = $this->importPage($i);
            $this->AddPage();
            $this->useTemplate($id);
        }
    }

Ofcourse one can define and set a separate header too, calling the TermsAndConditions-file. The problem for me was that 'importPage()' only included 1 page, where the TermsAndConditions-file had 2 (or more) pages.

Kind regards,
F.