Illegal string offset '/Root' in FPDF FPDI Parser issue - php

I have multiple pdf files of one user. So, I have given an option to our user to see all his document in a single PDF file.
For this, I am using FPDI pdf parser to merge all pdf files in a single file and then show to user. But I am getting below error:
Illegal string offset '/Root' in pdf_parser.php line 90
the function in which this error is thrown is given below:
protected function _readRoot()
{
if ($this->_xref['trailer'][1]['/Root'][0] != self::TYPE_OBJREF) {
throw new \Exception('Wrong Type of Root-Element! Must be an indirect reference');
}
$this->_root = $this->resolveObject($this->_xref['trailer'][1]['/Root']);
}
Can anyone please tell me what kind of issue is this. I have tried a lot as well as googled many things but failed.
Thanks in Advance.

Related

Reading File With PhpSpreadsheet Sheet Out of Bounds Error

Trying to read from a XLSX file with PhpSpreadsheet however getting below error:
PHP Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Exception: Your requested sheet index: -1 is out of bounds. The actual number of sheets is 0. in C:\php\projects\stock\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Spreadsheet.php:678
There is definitely a worksheet and my code below to pull a single cell works fine when I remove the table and just have unformatted data.
$spreadsheet = new PhpOffice\PhpSpreadsheet\Spreadsheet();
$inputFileName = "path/to/temp_file_download.xlsx";
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($inputFileName);
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$spreadsheet = $reader->load($inputFileName);
echo $cellValue = $spreadsheet->getActiveSheet()->getCellByColumnAndRow(2, 2)->getValue();
It seems that saving the file with Excel allows it to work just fine however excel does not complain that it is corrupt etc. I have no control over the actual spreadsheet as generated from an external source.
Just wondering if anyone has had similar issues and have any ideas for working around or what I may be doing wrong?
Tried to use the older PhpExcel also to get this to work however similar issues occur until I save the file again.
Have also tried XLSXReader with similar issues:
PHP Fatal error: Uncaught Exception: File /xl/workbook.xml does not exist in the Excel file in C:\php\projects\stock\vendor\XLSXReader\XLSXReader.php:57
Stack trace:
#0 C:\php\projects\stock\vendor\XLSXReader\XLSXReader.php(70): XLSXReader->getEntryData()
#1 C:\php\projects\stock\vendor\XLSXReader\XLSXReader.php(47): XLSXReader->parse()
#2 C:\php\projects\stock\stock.php(17): XLSXReader->__construct()
#3 {main}
thrown in C:\php\projects\stock\vendor\XLSXReader\XLSXReader.php on line 57
And have seen many issues on web for people having issues reading these files that area created like so however still not sure of a simple workaround.
Adding the workaround mentioned below hack for non standard xlsx seemed to do the trick!
https://github.com/PHPOffice/PHPExcel/issues/1187
Just need to add the class extending the xlsx class to phpspreadsheet then call that class instead and all works!

A non-numeric value encountered php 7 tcpdf

$header_x = (float)$this->original_lMargin + (float)($headerdata['logo_width'] * (float)1.1);
Severity: Warning
Message: A non-numeric value encountered
Filename: tcpdf/tcpdf.php
Line Number: 3422
I worked on this issue many days. In my case, I solved this problem on this way:
When you create a PDF with tcpdf you need to use ob_start(); at the top, then create instance object :
$pdf = new pdf(PDF_PAGE_ ..... BODY.. FOOTER, ETC,
and before output :
$pdf->Output('/media/Linux/Folder/document.pdf', 'F')
You need to end your ob with:
ob_end_clean();
I realised about the problem from create two or more PDFs continuously. You could try this.
I found the answer while visiting this:
TCPDF ERROR: Some data has already been output, can't send PDF file

Apple PNG Image Decompression

I have run into a problem with Apple's unfortunate decision to create a PNG file format that isn't actually a PNG file format. I pulled a PNG image file from an app IPA file and attempted to display it on a web browser and found that web browsers don't know how to display them and give an error. It took me some time to discover that the original, unzipped image was even the problem in the first place.
After researching the issue and doing a lot of poking around, I finally found this script as I don't have the knowledge to create a class to do what I need:
https://gist.github.com/juban/8397183
The author says this is a PHP scripted version that will turn an apple PNG file into a standard PNG file so that it can display properly. For added information, I am running PHP 5.5+.
My process of pulling out the image file goes like this:
if ($zip->open($ipaFile) === TRUE) {
if($zip->locateName($iconFilePath.$iconFile) !== FALSE) {
if ($iconData = $zip->getFromName($iconFilePath.$iconFile)) {
$iOSNormalizer = new iOSPNGNormalizer();
$iconData = $iOSNormalizer->getNormalizedPNG($iconData);
file_put_contents($iconSaveFile.$newIconFile, $iconData);
}
}
}
The iOSNormalizer is a class you can look at by clicking on the link I gave.
When I run it through the class I get hung up with the following errors:
Warning: zlib_decode(): data error in mypage.php on line 524
Notice: Uninitialized string offset: 12840 in mypage.php on line 532
Notice: Uninitialized string offset: 12840 in mypage.php on line 532
...These last two notices are repeated a ton of times for a lot of different lines. What happens is the apple PNG file has its original widths and heights restored, runs into the zlib_decode() error, and then stops working. The outputted file is a blank white image with its original height and width. zlib_decode() is not documented well for PHP and I'm not sure how to fix this problem. I'm hoping someone can look at the class in the link and better understand why this may be happening. Thanks!
EDIT: To ensure it isn't anything to do with how I am pulling out the icon file from the IPA file, I tested the following code on the image attached at at the end of my question and I still have the same problem (again, see the PHP class in my link to see what the function getNormalizedPNG() does):
$iconFile = "/path/AppIcon40x40#2x.png";
$newIconFile = "/path/converted.png";
$iOSNormalizer = new iOSPNGNormalizer();
$iconData = $iOSNormalizer->getNormalizedPNG($iconFile);
file_put_contents($newIconFile, $iconData);
Example PNG

With PHP, how can I check if a PDF file has errors

I have a DB system built in PHP/MySql. I'm fairly new at this. The system allows the user to upload an invoice. Others give permission to pay the invoice. The accounting person uploads the check. After check is uploaded, it generates a PDF as a cover, then uses PDFTK (using Ben Squire's PDFTK-PHP-Library) to combine all of the files together and present the user with a single PDF to download.
Some users upload PDF files which cause PDFTK to hang indefinitely when it tries to combine the PDF with others (but most of the time it works fine). No returned error, just hangs. In order to get back onto the sytem, user must clear cache and re-log in. There are no error messages logged by the server, it just freezes. The only difference I can find in the files that do or do not work in looking at them with Acrobat is that the bad files are legal sized (8.5 x 14) ... but if I create my own legal sized file and try that, it works fine.
Using Putty I've gone to command line and replicated the same problem, PDFTK can't read the file, it hangs on the command line as well. I tried using PDFMerge which uses FPDF to combine the files and get an error with the file as well (The error I get back from this is: FPDF error: Unable to find object (4, 0) at expected location). On the command line I was able to use ImageMagick to convert PDF to JPG, but it gives me an error: "Warning: File has an invalid xref entry: 2. Rebuilding xref table." and then it converts it to a jpg but gives a few other less helpful warnings.
If I could get PHP to check the PDF file to determine if is valid without hanging the system, I could use ImageMagick to convert the file and then convert it back to a PDF, but I don't want to do this to all files. How can I get it to check the validity of the file when uploaded to see if it needs to be converted without causing the system to hang?
Here is a link to a file that is causing problems: http://www.cssc-testing.org/accounting/school_9/20130604-a1atransportation-1.pdf
Thanks in advance for any guidance you can offer!
My Code (which I'm guessing is not very clean, as I'm new):
$pdftk = new pdftk();
if($create_cover) { $pdftk->setInputFile(array("filename" => $cover_page['server'])); }
// Load a list of attachments
$sql = "SELECT * FROM actg_attachments WHERE trans_id = {$trans_id}";
$attachments = Attachment::find_by_sql($sql);
foreach($attachments as $attachment) {
// Check if the file exists from the attachments
$attachment->set_variables();
$file = $attachment->abs_path . DS . $attachment->filename;
if(file_exists($file)){
// Use the pdftk tool to attach the documents to this PDF
$pdftk->setInputFile(array("filename" => $file));
}
}
$pdftk->setOutputFile($save_file);
$pdftk->_renderPdf();
the $pdftk class it is calling is from: https://github.com/bensquire/php-pdtfk-toolkit
You could possibly use Ghostscript using exec() to check the file.
The non-accepted answer here may help:
How can you find a problem with a programmatically generated PDF?
I wont say this is an appropriate/best fix, but it may resolve your problem,
In: pdf_parser.php, comment out the line:
$this->error("Unable to find object ({$obj_spec[1]}, {$obj_spec[2]}) at expected location");
It should be near line 544.
You'll also likely need to replace:
if (!is_array($kids))
$this->error('Cannot find /Kids in current /Page-Dictionary');
with:
if (!is_array($kids)){
// $this->error('Cannot find /Kids in current /Page-Dictionary');
return;
}
in the fpdi_pdf_parser.php file
Hope that helps. It worked for me.

PHPExcel - chart rendering and load excel giving error

require_once('PHPExcel-1.7.7/Classes/PHPExcel.php');
$inputFileName = 'RN Tracker.xlsx';
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
if i try following
$objReader->setIncludeCharts(TRUE);
during load i get following error message:
Warning: PHPExcel_Reader_Excel2007::load(): Node no longer exists in /users/pravkum4/html/tracker/PHPExcel-1.7.7/Classes/PHPExcel/Reader/Excel2007.php on line 1518
Notice: Trying to get property of non-object in /users/pravkum4/html/tracker/PHPExcel-1.7.7/Classes/PHPExcel/Reader/Excel2007.php on line 1519
Fatal error: Call to a member function children() on a non-object in /users/pravkum4/html/tracker/PHPExcel-1.7.7/Classes/PHPExcel/Reader/Excel2007.php on line 1519
What mistake i am doing here?
Should i include some additional class for chart?
Does chart option is included by default in load method of reader? chart count gives 0. :((
Sometimes gives correct chart count but rendering doesn't work.
One more thing, what is this code? not working for me. Sometimes i get jpgraph_pie.php missing.
PHPExcel_Settings::setChartRenderer(
PHPExcel_Settings::CHART_RENDERER_JPGRAPH,
dirname(__FILE__).'/../../libraries/Charts/jpgraph3.5.0b1/src'
);
Please provide a tutorial for chart rendering. Thank you so much in Advance.
I have yet to see this issue raised at the PHPExcel sites on either CodePlex or on Github... and to resolve it you'll need to upload a sample file that demonstrates the problem so that we can identify what node no longer exists in the Excel data
Look at this this may help you...
http://phpexcel.codeplex.com/workitem/16
http://phpexcel.codeplex.com/wikipage?title=Examples

Categories