Code Monkey home page Code Monkey logo

php-pdf-merge's Introduction

PDF Merge for PHP

PDF Merge library for PHP.

Install with composer:

composer require jurosh/pdf-merge

Should add dependency:

"jurosh/pdf-merge": "^2.0"

Highlights

Pdf merging with modes portrait/landscape.

Tested in Laravel4 & Laravel5 framework (but still can be used without any framework as standalone utility).

Usage

// Autoload composer classses...

// and now we can use library
$pdf = new \Jurosh\PDFMerge\PDFMerger;

// add as many pdfs as you want
$pdf->addPDF('path/to/source/file.pdf', 'all', 'vertical')
  ->addPDF('path/to/source/file1.pdf', 'all')
  ->addPDF('path/to/source/file2.pdf', 'all', 'horizontal');

// call merge, output format `file`
$pdf->merge('file', 'path/to/export/dir/file.pdf');

That's it!

Enjoy and leave star if you like it :)

php-pdf-merge's People

Contributors

it-can avatar jurosh avatar morrislaptop avatar sebastian-serfe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-pdf-merge's Issues

itbz/fpdf is abandoned

Composer message:
Package itbz/fpdf is abandoned, you should avoid using it. Use setasign/fpdf instead.

Issue when merge

have this message when i try to merge pdf 👍

This PDF document probably uses a compression technique which is not supported by the free parser shipped with FPDI

Maybe i need to buy a licence ?

xref table error

Hi, How are you?
I have used your php-pdf-merge library on my project but I have some issues.

Type: Exception

Message: Unexpected data in xref table

Filename: /pdfmerge/vendor/itbz/fpdi/src/pdf_parser.php

Line Number: 187

Now this library is running on my localhost (windows) but it is not running on Linux server.
Could you help me now?

Unable to find PDF file header error

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.

Problem with pdf version >=1.4

Hi , sorry fo english , when i try to merge file with 1.4 version i have an exception :

Unknown HTTP status code provided with no message: 267

Declaration of setasign\Fpdi\FpdfTplTrait::setPageFormat($size, $orientation) should be compatible with TCPDF::setPageFormat($format, $orientation = 'P')

I'm getting this error:

Declaration of setasign\Fpdi\FpdfTplTrait::setPageFormat($size, $orientation) should be compatible with TCPDF::setPageFormat($format, $orientation = 'P')

// and now we can use library

$front = '/home/sapama/projects/web/erp/public/media/erp/upload/cards/front-18980.pdf';
$back = '/home/sapama/projects/web/erp/public/media/erp/upload/cards/back-18980.pdf';
$card = '/home/sapama/projects/web/erp/public/media/erp/upload/cards/18980.pdf';

    // and now we can use library
    $pdf = new \Jurosh\PDFMerge\PDFMerger;

    //Add as many pdfs as you want
    $pdf->addPDF($front, 'all','vertical')
            ->addPDF($back, 'all','vertical');


    //Call merge, output format `file`
    $pdf->merge('file', $card);

Fatal error: Uncaught Exception: Could not locate PDF

When trying to merge some PDFs I got the below error.

Fatal error: Uncaught Exception: Could not locate PDF on 2920.pdf ' in /home/vendor/jurosh/pdf-merge/src/Jurosh/PDFMerge/PDFMerger.php:42
Stack trace: #0 /home/public_html/pdf_merge_test.php(48): Jurosh\PDFMerge\PDFMerger->addPDF('...', 'all') #1 {main}
thrown in /home/vendor/jurosh/pdf-merge/src/Jurosh/PDFMerge/PDFMerger.php on line 42

Note: PDF version is 1.4

Merging seems to work fine when not using the mentioned 2920.pdf
The file does open in Adobe Acrobat however.

Any ideas?

Thanks

links broken after merge

Hello,

after merge, all links in the document disappeared. :(
I use ancor tags in my table of content in the pdf document

$pdf = new \Jurosh\PDFMerge\PDFMerger; $pdf->addPDF($reisenummer.'.pdf', 'all') ->addPDF(Anhang.pdf', 'all'); $pdf->merge('file', 'test.pdf');

Wrong docblock

Since PHP8, return types are very important. When I'm trying to merge single PDF's to one file, the docblocks seems to be incorrect. A class was used, which does not exists in your package.

See PDFMerger::merge()

Did you missed something or was the docblock incorrectly formed?

Error when setting the pages to be merged

$pdf->addPDF('path/to/source/file.pdf', '1,2', 'vertical')

Showing following error:
Undefined index: w

I think it is a typo mistake in the PDFMerger.php on line 85:
$fpdi->AddPage($file->getOrientationCode(), array($size['w'], $size['h']));

If you change the $size['w'] => $size['width'] and $size['h'] => $size['height'] the problem will be fixed.

licence

hi

The licence suggests Apache composer suggests MIT

could these by synced to the preferred licence

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.