Skip to content

Unable to find PDF file header error #10

Description

@mennei

Hi,

When I'm calling a controller that excute this method:
public function downloadZip ($did) {
$decs = DB::table ('app_decisions')->select ()->where ('id', '=', $did)->first ();

	$files = DB::table('apps_file')
		->where([
			['app_id', '=', $decs->p5_id],
		])->get();
	Log::debug(count($files));
	$filespath = public_path ('upload');
	$marge_file = 'file.pdf';
	$pdf = new PDFMerger();
	foreach ($files as $key => $file) {
		if( file_exists($filespath . '/' . $file->url) ){
			if (strpos($file->url, 'docx') || strpos($file->url, 'doc') !== false) {
				//header ("Content-type: application/vnd.ms-word");
				//header ("Content-Disposition: attachment;Filename=document_name.doc");
			} else {
				$pdf->addPDF($filespath . '/' . $file->url, 'all');
			}
		} 
		if (file_exists($filespath . '/admin/' . $file->url)) {
			Log::debug('admin:'. $file->url);
			if (strpos($file->url, 'jpg') || strpos($file->url, 'docx') || strpos($file->url, 'doc') !== false) {
				//header ("Content-type: application/vnd.ms-word");
				//header ("Content-Disposition: attachment;Filename=document_name.doc");
			} else {
				$pdf->addPDF($filespath . '/admin/' . $file->url, 'all');
			}
		}
	}
	$pdf->merge('file', storage_path('app/public').'/'.$marge_file);
	return response ()->download (storage_path('app/public').'/'.$marge_file)->deleteFileAfterSend (true);
}

I'm getting this exception:

image

(1/1) PdfParserExceptionUnable to find PDF file header.

in PdfParser.php line 131
at PdfParser->resolveFileHeader()in PdfParser.php line 172
at PdfParser->getPdfVersion()in PdfReader.php line 85
at PdfReader->getPdfVersion()in FpdiTrait.php line 215
at Fpdi->setSourceFile('/var/www/vhosts/betshemesh.automas.co.il/httpdocs/public/upload/5f9e6a074f930_1604217351.jpg')in PDFMerger.php line 67
at PDFMerger->merge('file', '/var/www/vhosts/betshemesh.automas.co.il/httpdocs/storage/app/public/file.pdf')in TendersController.php line 1410
at TendersController->downloadZip('357')

Please, guide me how to use PDFMerger with docx or jpg files.

Thanks,
Menachem.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions