Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I get the error 'The file does not begin with "%PDF- ..... #9

Closed
HVSoftware opened this issue Oct 21, 2013 · 7 comments
Closed

I get the error 'The file does not begin with "%PDF- ..... #9

HVSoftware opened this issue Oct 21, 2013 · 7 comments

Comments

@HVSoftware
Copy link

Can you tell me if this is due to my installation?

@barryvdh
Copy link
Owner

Not sure, can you be more specific?
What is the code you are using to generate the PDF? What is the full error?

@HVSoftware
Copy link
Author

I only get an dialog within my Chrome with a message about an incorrect PDF. I have include the package inside Composer.json and run "Composer update".

I used the code in the example

use \Barryvdh\DomPDF\PDF;

class ReportController extends \BaseController {

public function getInvoice($id)
{
    $pdf = new PDF;
    $pdf->loadHTML('<h1>Test</h1>');
    return $pdf->stream();
}

}

@HVSoftware
Copy link
Author

Do I need to use something like: php artisan config:publish

I temporary used https://github.com/thujohn/pdf-l4.

@barryvdh
Copy link
Owner

Does download instead of stream work?

@HVSoftware
Copy link
Author

In this case I get the following error: Undefined offset: 2

case 'procset':
$o['info']['procset'] = $options;
break;

case 'mediaBox':
  $o['info']['mediaBox'] = $options;
  // which should be an array of 4 numbers
  // Harry:The application breaks on this line.
  $this->currentPageSize = array('width' => $options[2], 'height' => $options[3]);
  break;

@barryvdh
Copy link
Owner

Okay, it doesn't seem to work very well when creating a new class.
I suggest using the facade or the App container:

$pdf = app('dompdf');
$pdf->loadHTML('<h1>Test</h1>');
return $pdf->stream();

//Or with Facade:
return PDF::loadHTML('<h1>Test</h1>')->stream();

I will see why this doesn't work otherwise.

@barryvdh
Copy link
Owner

Should be fixed with this commit: 55cd8c8
Problem was that the ServiceProvider was deferred, so the config wasn't loaded when using the class directly.
You may need to remove the serviceprovider from app.php, open a route and add it back, so the meta/cache is updated.
But using App::make('dompdf') and the Facade work also fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants