FPDI Fatal error: Uncaught exception 'Exception' with message 'Unable to find object (1, 0) - fpdi

I'm trying to import a pdf with php class FPDI with this simple code:
require_once("fpdf/fpdf.php");
require_once("fpdi/fpdi.php");
$pdf = new FPDI();
$pdf->setSourceFile('intermedia.pdf');
$tplidx = $pdf->ImportPage(1);
$pdf->AddPage();
$pdf->useTemplate($tplidx,0,0,210);
$pdf->Output();
but I receive the following error:
Warning: explode() [function.explode]: Empty delimiter. in
/var/catalogo/test_pdf/fpdi/pdf_parser.php on line 369
Fatal error: Uncaught exception 'Exception' with message 'Unable to
find object (1, 0) at expected location.' in
/var/catalogo/test_pdf/fpdi/pdf_parser.php:709 Stack trace: #0
/var/catalogo/test_pdf/fpdi/pdf_parser.php(268):
pdf_parser->resolveObject(Array) #1
/var/catalogo/test_pdf/fpdi/pdf_parser.php(208):
pdf_parser->_readRoot() #2
/var/catalogo/test_pdf/fpdi/fpdi_pdf_parser.php(71):
pdf_parser->__construct('/var/catalogo/t...') #3
/var/catalogo/test_pdf/fpdi/fpdi.php(128):
fpdi_pdf_parser->__construct('/var/catalogo/t...') #4
/var/catalogo/test_pdf/fpdi/fpdi.php(108):
FPDI->_getPdfParser('/var/catalogo/t...') #5
/var/catalogo/test_pdf/index.php(5):
FPDI->setSourceFile('intermedia.pdf') #6 {main} thrown in
/var/catalogo/test_pdf/fpdi/pdf_parser.php on line 709
This is the file that should be imported:
http://catalogo.selectaspa.it/test_pdf/intermedia.pdf

Ok, the cross reference of this file is simply corrupted. I just catched the "Warning" on explode for now but at the end you will have to resave the document with e.g. Acrobat to repair it before passing it to FPDI.
You may change pdf_parser.php around line 362 to:
// get Line-Ending
$found = preg_match_all("/(\r\n|\n|\r)/", substr($data, 0, 100), $m); // check the first 100 bytes for line breaks
if ($found === 0) {
throw new Exception('Xref table seems to be corrupted.');
}
Same fix can be used in the separate FPDI PDF-Parser which will allow you to read this document then, too.

Related

Fatal Error When Set CI_DEBUG to False On Production Mode Codeigniter 4

Why I get this error when set from Config/Boot/production.php CI_DEBUG to false in production mode ? this is the default setting from CI4.
defined('CI_DEBUG') || define('CI_DEBUG', false);
Fatal error: Declaration of CodeIgniter\Log\Logger::emergency($message, array $context = []): bool must be compatible with Psr\Log\LoggerInterface::emergency(Stringable|string $message, array $context = []): void in E:\testing\Source Code\testing_CI_v.4.2.6\system\Log\Logger.php on line 157
Fatal error: Uncaught Error: Class "CodeIgniter\Log\Logger" not found in E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\Services.php:391 Stack trace: #0 E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\BaseService.php(253): CodeIgniter\Config\Services::logger(false) #1 E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\BaseService.php(194): CodeIgniter\Config\BaseService::__callStatic('logger', Array) #2 E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\Services.php(388): CodeIgniter\Config\BaseService::getSharedInstance('logger') #3 E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\BaseService.php(253): CodeIgniter\Config\Services::logger(true) #4 E:\testing\Source Code\testing_CI_v.4.2.6\system\Common.php(799): CodeIgniter\Config\BaseService::__callStatic('logger', Array) #5 E:\testing\Source Code\testing_CI_v.4.2.6\system\Debug\Exceptions.php(114): log_message('critical', '{message}\nin {e...', Array) #6 E:\testing\Source Code\testing_CI_v.4.2.6\system\Debug\Exceptions.php(180): CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException)) #7 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler() #8 {main} thrown in E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\Services.php on line 391
For Development And Testing Mode run without problem. This error just occur when using routes->resource (RESTFUL API).
It is not clear what error is this. I try to replace the system folder with new one. But the error still exists.
It is said "Uncaught Error: Class "CodeIgniter\Log\Logger" not found" I don't know what is the problem with this and why it is not found.
Now my app just run with set CI_DEBUG to true to prevent the error. But the default is set to false for production.
defined('CI_DEBUG') || define('CI_DEBUG', true);
What is missing in here ? It is so strange that setting the CI_ENVIRONMENT to development or testing worked without a problem. But for production not working. So I decide to turn on the error display in production mode and found the error above.
Seriously help need.
I found the problem in the restful api.
The problem is in the config/filter.php
$routes->resource('ApiManageTips', ['controller' =>'App\Controllers\ApiData\ApiManageTips']); // get, put, create, delete
public $filters = [
'basicauth' => ['before' =>
[
'ApiManageTips/*',
'ApiManageTips',
]
]
];
The Above example is working in the version 4.1.2 but is not working in version 4.2.6
Instead change to :
public $filters = [
'basicauth' => ['before' =>
[
'ApiManageTips/*',
]
];
I don't why it is not working in the CI Version 4.2.6.

Laravel: local.ERROR: Trying to get property 'body' of non-object

I can't understand what's wrong in this code. I think the problem is when i am trying to extract de invoice number..
Line 790 - 792 from /crm/app/Http/Controllers/InvoiceController.php
$bodyInfo = str_replace('{invoice_reference_no}', $data['saleInvoiceData']->reference, $smsInfo->body);
$bodyInfo = str_replace('{order_date}', formatDate($data['saleInvoiceData']->order_date), $bodyInfo);
$bodyInfo = str_replace('{company_name}', $preference['company_name'], $bodyInfo);
First 3 lines of log:
[2021-02-17 09:32:18] local.ERROR: Trying to get property 'body' of non-object {"userId":1,"email":"office#etec.ro","exception":"[object] (ErrorException(code: 0): Trying to get property 'body' of non-object at /home/pkdsiteu/public_html/crm/app/Http/Controllers/InvoiceController.php:790)
[stacktrace]
#0 /home/pkdsiteu/public_html/crm/app/Http/Controllers/InvoiceController.php(790): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Trying to get p...', '/home/pkdsiteu/...', 790, Array)
#1 [internal function]: App\Http\Controllers\InvoiceController->view('14')
Thanks.
Trying to get property 'body' of non-object error directly specify error is due to $smsInfo is not object ...either NULL or empty string
$bodyInfo = str_replace('{invoice_reference_no}', $data['saleInvoiceData']->reference, $smsInfo ? $smsInfo->body:'');
To avoid exception error.

FPDF Including an image in fancytable

I'm trying to insert an image in a FPDF fancytable.
I tried to put inside the fancytable function the following :
$this->Cell($w[1],6,$pdf->Image('lettre.jpg',0,0,20,0),'LRB',0,'C',$fill);
but I have (of course) the following error message :
PHP Notice: Undefined variable: pdf in /MyScript.php on line 143
Notice: Undefined variable: pdf in /MyScript.php on line 143
PHP Fatal error: Uncaught Error: Call to a member function Image() on
null in /MyScript.php:143
Stack trace:
0 /MyScript.php(172): PDF->FancyTable(Array, Array)
1 {main} thrown in /MyScript.php on line 143
I understand that I call the pdf function inside the fancytable function (part of the pdf function), so do I have a solution ?
Thanks !
Damn, the answer was in the question : just replaced $pdf by $this and it fixed my problem..
I let the question here just in case somebody have the same error one day ^^

Need some guidance regarding Elasticsearch php

I need some help in understanding the following things,
I am using composer for elasticsearch php integration. I have created a html page to post form data into elasticsearch. I am trying to access the html page from another pc by changing the localhost ip to the system ip where i have hosted the html page. But i'm getting error.
Fatal error: Uncaught Elasticsearch\Common\Exceptions\NoNodesAvailableException: No alive nodes found in your cluster in C:\xampp\htdocs\Client_portal\vendor\elasticsearch\elasticsearch\src\Elasticsearch\ConnectionPool\StaticNoPingConnectionPool.php:50 Stack trace: #0 C:\xampp\htdocs\Client_portal\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Transport.php(77): Elasticsearch\ConnectionPool\StaticNoPingConnectionPool->nextConnection() #1 C:\xampp\htdocs\Client_portal\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Transport.php(94): Elasticsearch\Transport->getConnection() #2 C:\xampp\htdocs\Client_portal\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php(269): Elasticsearch\Transport->performRequest('POST', '/sib_api/_doc', Array, '{"requestid":"#...', Array) #3 C:\xampp\htdocs\Client_portal\vendor\react\promise\src\FulfilledPromise.php(25): Elasticsearch\Connections\Connection->Elasticsearch\Connections{closure}(Array) #4 C:\xampp\htdocs\Client_portal\vendor\guzzlehttp\ringphp\sr in C:\xampp\htdocs\Client_portal\vendor\elasticsearch\elasticsearch\src\Elasticsearch\ConnectionPool\StaticNoPingConnectionPool.php on line 50
To resolve the above issue i tried to call the autoload.php file using the complete path (i.e) http://localhost:8080/client_portal/vendor/autoload.php
But now I am getting another error
Fatal error: Uncaught Error: Class 'Elasticsearch\ClientBuilder' not found in C:\xampp\htdocs\Client_portal\Elastic_api.php:19 Stack trace: #0 {main} thrown in C:\xampp\htdocs\Client_portal\Elastic_api.php on line 19
Could someone help me to resolve this issue... and also guide me how to access my html page from another system without any isssues.
<?php
session_start();
$Engagement = $_SESSION["Engagement"];
$Application = $_SESSION["Application"];
$Priority = $_SESSION["Priority"];
$Requestid = $_SESSION["Requestid"];
$_SESSION["URL"] = $_POST['url'];
$_SESSION["REQ"] = $_POST['request'];
$_SESSION["RES"] = $_POST['response'];
$_SESSION["yn"] = $_POST['YN'];
$_SESSION["START"] = $_POST['start'];
$_SESSION["END"] = $_POST['end'];
if (isset($_POST['Submit2']))
{
require 'http://localhost:8080/client_portal/vendor/autoload.php';
$client = Elasticsearch\ClientBuilder::create()->build();
// the above line is where i'm getting the error...

php, postgresql and phppgadmin: errors after changes made to files

I was getting deprecated constructor error when I tried installing postgres with xampp. Though I was able to resolve those issues but I am unable to solve the one below. Kindly help to solve this.
Fatal error: Uncaught Error: Call to undefined method ADORecordSet_postgres7::ADORecordSet_postgres64() in C:\xampp\phppgadmin\libraries\adodb\drivers\adodb-postgres7.inc.php:220 Stack trace:
#0 C:\xampp\phppgadmin\libraries\adodb\adodb.inc.php(1055): ADORecordSet_postgres7->__construct(Resource id #19, 2)
#1 C:\xampp\phppgadmin\libraries\adodb\adodb.inc.php(1015): ADOConnection->_Execute('select version(...', false)
#2 C:\xampp\phppgadmin\libraries\adodb\adodb.inc.php(1427): ADOConnection->Execute('select version(...', false)
#3 C:\xampp\phppgadmin\libraries\adodb\drivers\adodb-postgres64.inc.php(129): ADOConnection->GetOne('select version(...')
#4 C:\xampp\phppgadmin\libraries\adodb\drivers\adodb-postgres64.inc.php(697): ADODB_postgres64->ServerInfo()
#5 C:\xampp\phppgadmin\libraries\adodb\adodb.inc.php(525): ADODB_postgres64->_connect('host='localhost...', ''postgres'', ''password'', ''template1'')
#6 C:\xampp\phppgadmin\classes\database\Connection.php(42): ADOConnection->Connect('localhost:5432:...', 'postgres', ' in C:\xampp\phppgadmin\libraries\adodb\drivers\adodb-postgres7.inc.php on line 220
You should also change the constructor in adodb-postgres7.inc.php by replacing
function ADODB_postgres7()
with
function __construct()

Resources