Giter Site home page Giter Site logo

laravel-snappy's Introduction

Snappy PDF/Image Wrapper for Laravel

Tests Packagist License Latest Stable Version Total Downloads Fruitcake

This package is a ServiceProvider for Snappy: https://github.com/KnpLabs/snappy.

Wkhtmltopdf Installation

Choose one of the following options to install wkhtmltopdf/wkhtmltoimage.

  1. Download wkhtmltopdf from here;
  2. Or install as a composer dependency. See wkhtmltopdf binary as composer dependencies for more information.

Attention! Please note that some dependencies (libXrender for example) may not be present on your system and may require manual installation.

Testing the wkhtmltopdf installation

After installing you should be able to run wkhtmltopdf from the command line / shell.

If you went for the second option the binaries will be at /vendor/h4cc/wkhtmltoimage-amd64/bin and /vendor/h4cc/wkhtmltopdf-amd64/bin.

Attention vagrant users!

Move the binaries to a path that is not in a synced folder, for example:

cp vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64 /usr/local/bin/
cp vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 /usr/local/bin/

and make it executable:

chmod +x /usr/local/bin/wkhtmltoimage-amd64 
chmod +x /usr/local/bin/wkhtmltopdf-amd64

This will prevent the error 126.

Package Installation

Require this package in your composer.json and update composer.

composer require barryvdh/laravel-snappy

Laravel

Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider/Facade. If you also use laravel-dompdf, watch out for conflicts. It could be better to manually register the Facade.

After updating composer, add the ServiceProvider to the providers array in config/app.php

Barryvdh\Snappy\ServiceProvider::class,

Optionally you can use the Facade for shorter code. Add this to your facades:

'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
'SnappyImage' => Barryvdh\Snappy\Facades\SnappyImage::class,

Finally you can publish the config file:

php artisan vendor:publish --provider="Barryvdh\Snappy\ServiceProvider"

Snappy config file

The main change to this config file (config/snappy.php) will be the path to the binaries.

For example, when loaded with composer, the line should look like:

'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),

If you followed the vagrant steps, the line should look like:

'binary'  => '/usr/local/bin/wkhtmltopdf-amd64',

For windows users you'll have to add double quotes to the bin path for wkhtmltopdf:

'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"'

Lumen

In bootstrap/app.php add:

class_alias('Barryvdh\Snappy\Facades\SnappyPdf', 'PDF');
$app->register(Barryvdh\Snappy\LumenServiceProvider::class);

Optionally, add the facades like so:

class_alias(Barryvdh\Snappy\Facades\SnappyPdf::class, 'PDF');
class_alias(Barryvdh\Snappy\Facades\SnappyImage::class, 'SnappyImage');

To customise the configuration file, copy the file /vendor/barryvdh/laravel-snappy/config/snappy.php to the /config folder.

Usage

You can create a new Snappy PDF/Image instance and load a HTML string, file or view name. You can save it to a file, or inline (show in browser) or download.

Using the App container:

$snappy = App::make('snappy.pdf');
//To file
$html = '<h1>Bill</h1><p>You owe me money, dude.</p>';
$snappy->generateFromHtml($html, '/tmp/bill-123.pdf');
$snappy->generate('http://www.github.com', '/tmp/github.pdf');
//Or output:
return new Response(
    $snappy->getOutputFromHtml($html),
    200,
    array(
        'Content-Type'          => 'application/pdf',
        'Content-Disposition'   => 'attachment; filename="file.pdf"'
    )
);

Using the wrapper:

$pdf = App::make('snappy.pdf.wrapper');
$pdf->loadHTML('<h1>Test</h1>');
return $pdf->inline();

Or use the facade:

$pdf = PDF::loadView('pdf.invoice', $data);
return $pdf->download('invoice.pdf');

You can chain the methods:

return PDF::loadFile('http://www.github.com')->inline('github.pdf');

You can change the orientation and paper size

PDF::loadHTML($html)->setPaper('a4')->setOrientation('landscape')->setOption('margin-bottom', 0)->save('myfile.pdf')

If you need the output as a string, you can get the rendered PDF with the output() function, so you can save/output it yourself.

See the wkhtmltopdf manual for more information/settings.

Testing - PDF fake

As an alternative to mocking, you may use the PDF facade's fake method. When using fakes, assertions are made after the code under test is executed:

<?php

namespace Tests\Feature;

use Tests\TestCase;
use PDF;

class ExampleTest extends TestCase
{
    public function testPrintOrderShipping()
    {
        PDF::fake();
        
        // Perform order shipping...
        
        PDF::assertViewIs('view-pdf-order-shipping');
        PDF::assertSee('Name');
    }
}

Other available assertions:

PDF::assertViewIs($value);
PDF::assertViewHas($key, $value = null);
PDF::assertViewHasAll(array $bindings);
PDF::assertViewMissing($key);
PDF::assertSee($value);
PDF::assertSeeText($value);
PDF::assertDontSee($value);
PDF::assertDontSeeText($value);
PDF::assertFileNameIs($value);

License

This Snappy Wrapper for Laravel is open-sourced software licensed under the MIT license

laravel-snappy's People

Contributors

adamthehutt avatar alexpozzi avatar barryvdh avatar dalabad avatar darkaonline avatar dciancu avatar denissonleal avatar devinfd avatar dissto avatar django23 avatar felixgoldstein avatar gahlawat avatar gauravmak avatar grahammccarthy avatar hkp22 avatar jaybizzle avatar jibelicious avatar jonnywilliamson avatar jpellissari avatar k-leon avatar kblais avatar laravel-shift avatar luketowers avatar maddhatter avatar omranic avatar ryanmortier avatar silverdr avatar sjorsvanleeuwen avatar szabizs avatar wammy21 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  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

laravel-snappy's Issues

Trying to load a view and output the pdf, while setting a file download cookie

I am trying to output a view while setting a cookie for the jquery fileDownload plugin. but i keep getting the error:

UnexpectedValueException in Response.php line 403:
The Response content must be a string or object implementing __toString(), "object" given.

This is my code:

return new \Response(
                \PDF::loadView( $view, $data )->output(),
                200,
                [
                    'Content-Type' => 'application/octet-stream',
                    'Set-Cookie' => 'fileDownload=1; path=/',
                    'Content-Disposition'   => 'attachment; filename=Gender report ' . date( 'd/m/Y' )
                ]
            );

How am i suppose to achieve this?

Multiple pages?

For starters: thanks for the nice package, it integrates really well with Laravel.

I'm looking for a way to add pages to the generated pdf, for example by way of calling the loadView method multiple times on the same PdfWrapper object. So something like addView instead of loadView.

Any thoughts on the feasibility of this for this package?

App not found

Hi,

I am getting

Class 'App\Http\Controllers\App' not found

What could be wrong?

Saving to file error

using.......
https://github.com/barryvdh/laravel-snappy

// this works fine and creates the pdf and prompts for download
$pdf = PDF::loadView('pages.application.app', array('policy' => $policy));
return $pdf->download('zzsnappytest.pdf');


// this does create the file but results in ErrorException:
Object of class Barryvdh\Snappy\PdfWrapper could not be converted to string

$pdf = PDF::loadView('pages.application.app', array('policy' => $policy));
return $pdf->save('zzsnappytest.pdf'); 

There isn't a way to password lock a downloaded file is there? I'm trying to write the file so i can use PDFtk to password protect it.

The exit status code '126' says something went wrong

Hi barry,
when I hit my end point I get this exception:

The exit status code '126' says something went wrong: stderr: "sh: /Users/xroot/dev_projects/meetings/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64: cannot execute binary file " stdout: "" command: /Users/xroot/dev_projects/meetings/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 --lowquality '/var/folders/ml/gzjp_czs0l9gcvwl4t297gn80000gp/T/knp_snappy555e07f59eaa96.81797228.html' '/var/folders/ml/gzjp_czs0l9gcvwl4t297gn80000gp/T/knp_snappy555e07f59ebe31.72659281.pdf'.

My config file:

<?php

return array(


    'pdf' => array(
        'enabled' => true,
        'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),
        'timeout' => false,
        'options' => array(),
    ),
    'image' => array(
        'enabled' => true,
        'binary' => base_path('/vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64'),
        'timeout' => false,
        'options' => array(),
    ),


);

My route end point:

Route::get('pdf',function(){

    $pdf = PDF::loadView('meetings.print');
    return $pdf->download('invoice.pdf');

});

Laravel 5 Support

I posted this on DOMPDF and i apologize for the redundancy. Is it possible to use a pdf to html converted in laravel 5?

The exit status code '1' says something went wrong: stderr: "The system cannot find the path specified. "

I m using this code in controller but i m facing this error

public function getPDF()
{
    $pdf = PDF::loadView('ab');
    return $pdf->download('invoice.pdf');
}

error

The exit status code '1' says something went wrong: stderr: "The system cannot find the path specified. " stdout: "" command: /usr/local/bin/wkhtmltopdf --lowquality "C:\Users\Admin\AppData\Local\Temp\knp_snappy552137b1a973a8.95135225.html" "C:\Users\Admin\AppData\Local\Temp\knp_snappy552137b1aa4969.49985920.pdf".

capture

Problem with header/footer and encoding

Hello,

i have problem with header and footer with encode:

return PDF::loadView('pdf.my_pdf', $data)
->setOption('encoding', 'utf-8')
->setPaper('a4')
->setOption('footer-center', 'Cabeçalho')
->setOption('footer-font-size', '8')
->stream('my_pdf.pdf');

But always footer output is: Cabealho.

My view have:
meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
Thanks

exceeded the timeout of 60 seconds ?

Hi, I'm having a hard time making this work and don't know what to check.

Symfony \ Component \ Process \ Exception \ ProcessTimedOutException The process "/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf --lowquality '/tmp/knp_snappy539a1b5171a923.27143750.html' '/tmp/knp_snappy539a1b5171b010.24930374.pdf'" exceeded the timeout of 60 seconds.

Thats been thrown.

Any ideas?
I already check that the bin is working

Thanks for any help =)

--replace function implementation?

It isn't possible to use the --replace * <name> <value> function (from the wkhtmltopdf-docs: Replace [name] with value in header and footer (repeatable)).

0.2 should support Laravel 4.* as well

It looks like version 0.2 only supports Laravel 5.0.* while it should support 4.* as well.
There is a bug in 0.1.* on Laravel 4.* (Response not found) so I guess the best option would be to support Laravel 4.* in version 0.2.

Here is the error I got when I tried to update to version 0.2:
screen shot 2015-02-03 at 16 43 02

Not working with ajax calls

I would like to generate a page to a pdf with a few ajax requests in it.
But for some reason this is not working, the ajax content is not displaying in the pdf.

To find out the core problem I tried to generate a pdf with the command line outside Laravel on a plain html file with ajax and via snappy. This is working fine. So I think it has something to do with this plugin or Laravel?

Maybe because of Laravel is caching the view files?

So, when I add this line to the javascript, the word "test" is not added to the class .box.

$.ajax({
    url: 'http://domain.nl/energyusage.json',
    dataType: 'json',
    success: function (data) {
        $('.box').append('test');
    }
});

Cannot load library icui18n

I'm getting this issue

/var/www/systemo.ro/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 --lowquality --print-media-type --header-right '[page]/[toPage]' '/tmp/knp_snappy544e5ffa54d496.58211283.html' '/tmp/knp_snappy544e5ffa54d496.58211283.pdf'
Unable to load library icui18n "Cannot load library icui18n: (icui18n: cannot open shared object file: No such file or directory)"
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
Exit with code 1 due to network error: ProtocolInvalidOperationError

Image size

Hi
thanks for this wrapper.
I want to export a link to base64. so I did something like :
$image_data = Image::setOption('width', 100)->getOutput('http://google.com');
base64_encode($image_data);

but I got an error:
Call to a member function getOutput() on a non-object.
how I can use getOutput and set option? I don't want to use config file because I want to generate image with dynamic size.
It will be good if I can use somthing like this:
Image::setOption('width', 100)->setOption('height', 100)->getOutput('http://google.com')
or something like that.
thanks again :-)

could not install in fresh install of laravel 4.2

Tried to install snappy with this command:

composer require "barryvdh/laravel-snappy": "0.1.x" 

but getting this error:

[InvalidArgumentException]
Could not find package 0.1.x at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability 

composer.json:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "laravel/framework": "4.2.*"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "stable"
}

Also tried with :

"minimm-stability":"dev"

what am i missing here?

Save function missing 'overwrite' argument

Hi,
First, thanks for making this wrapper, it has been of great help to me.
However, I have a small problem with the save function. I need it to be able to overwrite the file if it already exists on the filesystem and this is possible with Snappy by passing the $overwrite = True option to the 'generate' function. Unfortunately, this option is not included in your save function and so it throws an error if the file already exists.
I have fixed it on my own system by amending your function to the following:

public function save($filename, $overwrite = false)
{

    if ($this->html)
    {
        $this->snappy->generateFromHtml($this->html, $filename, $this->options, $overwrite);
    }
    elseif ($this->file)
    {
        $this->snappy->generate($this->file, $filename, $this->options, $overwrite);
    }

    return $this;
}

I hope you will consider patching this for your next release as I think it is a handy function to have.
Sorry if this was not the correct way to submit this, but Im not all that familiar with github and patching.

Error "Class snappy.pdf does not exist"

I followed all info in readme, added it as service and as facade.
I set correct path to binary.

No matter how i do i get the following error:
Class snappy.pdf does not exist (or Class.spanny.pdf.wrapper) does not exist.

What is it that i am missing?

My composer json is like this:

"require": {
"laravel/framework": "5.0.",
"barryvdh/laravel-snappy": "0.2.
",
"h4cc/wkhtmltopdf-amd64": "0.12.2.1",
"h4cc/wkhtmltopdf-i386": "0.12.2.1",
"illuminate/html": "~5.0",
"knplabs/knp-snappy": "0.3.*"
},

my controller code for testing is:
return PDF::loadFile('http://www.github.com')->stream('github.pdf');

Installation of laravel-snappy

I have already update my composer after requiring these files
"h4cc/wkhtmltopdf-amd64": "0.12.x",
"h4cc/wkhtmltoimage-amd64": "0.12.x"

But when I execute this command php artisan config:publish barryvdh/laravel-snappy in my composer I'm getting thie error:

imagen 1
Can you help me please? I'm new to laravel packagist system

Problem with big images

Hey guys, has anyone had trouble when including images in your PDF files? For some reason I get a broken PDF file every time I try to include my images, but it turns out OK if I exclude them.

Here are the kind of images I'm talking about:
h_20150529_162718

It also works fine if I save my HTML to a file and use wkhtmltopdf from the command line. Any ideas?

Win7 64 bits - wkhtmltopdf 0.12.2.2

Libxrender

Libxrender

I spent a few hours trying to get this working today, I found my problem... Turns out I didn't have libxrender installed on my server.

I just wanted to submit this somewhere incase others are getting errors but followed steps seemingly correctly.

Solution

Ran the following command and accepted/updated the package.

sudo apt-get install libxrender1 

Laravel 5.1 compatibility

How can we assure swift compatibility with 5.1 when it comes out? I haven't seen breaking changes for packages, so it might be as simple as changing the version number in composer.json.

I'm happy to help out where if necessary, but I simply don't know what to do.

what file?

what is the file to add this: 'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'), And its route, thank you

The exit status code '1' says something went wrong: stderr: "" stdout: "" command: ...

Hey,

I'm now trying for hours to get wkhtmltopdf to run properly. Locally everything's fine, but on the test server with Windows 2008 R2, IIS 7 it just won't work. This is the error I get:

The exit status code '1' says something went wrong: stderr: "" stdout: "" 
command: "C:\path\to\wkhtmltopdf.exe" --lowquality "http://www.google.com" "c:\test.pdf". 

There is no error besides this general error code "1". The command works fine from command line and even if I just put the command directly in an exec-function. But it does not work with proc_open, which Symfony seems to use. Does anyone have an idea what the problem is or why there is no error?

The process has been signaled with signal "11"

OS: CentOS Linux 7.0.1406
Laravel 5.1

Hi,

I have installed wkhtmltopdf directly and it runs fine from the command line.

However, when using this package I get the following error (truncated to the first few lines):

RuntimeException in Process.php line 367:
The process has been signaled with signal "11".

1. in Process.php line 367
2. at Process->wait() in Process.php line 210
3. at Process->run() in AbstractGenerator.php line 475
4. at AbstractGenerator->executeCommand('/usr/local/bin/wkhtmltopdf --lowquality '/tmp/knp_snappy559fd7e4d812d7.68804302.html' '/tmp/knp_snappy559fd7e4d827b6.83747916.pdf'')  in AbstractGenerator.php line 147
5. at AbstractGenerator->generate(array('/tmp/knp_snappy559fd7e4d812d7.68804302.html'), '/tmp/knp_snappy559fd7e4d827b6.83747916.pdf', array(), false) in Pdf.php line 57
6. at Pdf->generate(array('/tmp/knp_snappy559fd7e4d812d7.68804302.html'), '/tmp/knp_snappy559fd7e4d827b6.83747916.pdf', array()) in AbstractGenerator.php line 177
7. at AbstractGenerator->getOutput(array('/tmp/knp_snappy559fd7e4d812d7.68804302.html'), array()) in AbstractGenerator.php line 198
...

These files are never written to the /tmp/ directory - it has drwxrwxrwt permissions, and I can write to this directory from the command line with wkhtmltopdf.

The controller function is set up very simply, and the correct variables are being passed according to the error logs:

public function pdf($vars)
    {
        $pdf = PDF::loadView('pdf', compact('vars'));
        return $pdf->download('example.pdf');
    }

The snappy.php config file is pointing correctly to usr/local/bin/wkhtmltopdf.

Any help or guidance would be greatly appreciated!

header-html and footer-html options

Can you clarify how to use the options header-html and footer-html? Is this a blade template, actual HTML text, or a path to a html file somewhere.

External links cause timeout...

I've noticed that after a recent update, when I try to convert any render with external links css or images, the script timesout. However removing any links has it behaving like normal again. Any ideas? It's probably related to how Symfony is being called. Anyone have any ideas?

Error help

Hey,

trying to export as pdf. Created a normal laravel route. Even put all needed css into the .blade.php. Works all fine in the browser. No external content loaded (css or js or something else)

When I try to access that blade.php:

$pdf = PDF::loadView('invoice_de');
return $pdf->download('invoice.pdf');

I get the following error message:

RuntimeException thrown with message "The exit status code '1' says something went wrong:
stderr: "Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
[============================>                               ] 47%
[============================>                               ] 48%
[============================================================] 100%
Counting pages (2/6)                                               
[============================================================] Object 1 of 1
Warning: Received createRequest signal on a disposed ResourceObject's NetworkAccessManager. This might be an indication of an iframe taking too long to load.
Resolving links (4/6)
[============================================================] Object 1 of 1
Loading headers and footers (5/6)                                           
Printing pages (6/6)
[>                                                           ] Preparing
[============================================================] Page 1 of 1
Done                                                                      
Exit with code 1 due to network error: ContentNotFoundError
"
stdout: ""
command: /usr/local/bin/wkhtmltopdf --lowquality '/var/folders/13/hpjf_mbs2_x8grtlf7142f_r0000gp/T/knp_snappy54d0f153bef0e6.73569359.html' '/var/folders/13/hpjf_mbs2_x8grtlf7142f_r0000gp/T/knp_snappy54d0f153bf2960.49974221.pdf'."

What might be the error?

exceeded the timeout of 60 seconds

Hi,

I'm try to use this package, but I am getting the following error:

The process "C:"Program Files"\wkhtmltopdf\bin\wkhtmltopdf --lowquality "C:\Users\MIGUEL1\AppData\Local\Temp\knp_snappy54052f4d61f0d1.70329205.html" "C:\Users\MIGUEL1\AppData\Local\Temp\knp_snappy54052f4d6234f1.36255900.pdf"" exceeded the timeout of 60 seconds.

If I run the cmd in console works.

My code:

    public function test()
    {
        $budget = Budget::with(['creator', 'client', 'items'])->findOrFail(1);
        $this->theme->asset()->usePath()->add('styles', 'css/styles.min.css');
        set_time_limit(60*5);

        $html = '<!DOCTYPE html>
        <html>
            <head>
                <meta charset="utf-8">
                <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
                <title>' . Theme::get('title')  . '</title>
                <meta name="viewport" content="width=device-width">' .
                $this->theme->asset()->styles() . '
            </head>
            <body id="invoice-page">' . View::make('budgets.theme1', compact('budget'))->render() . '
            <body>
        </html>';
        $pdf = PDF::loadHTML($html);
        // return $html;
        return $pdf->download('invoice.pdf');
        return $pdf->save('D:\\o.pdf');
        return $pdf->stream();
    }

class 'Barryvdh\Snappy\IlluminateSnappyImage' does not have a method 'make'

I followed the installation process and I did a test...
$pdf = App::make('snappy.pdf.wrapper');
$pdf->loadHTML('Test');
return $pdf->stream();

And error shows that says:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Barryvdh\Snappy\IlluminateSnappyImage' does not have a method 'make'

How can i resolve this?

Background image

Hello!

I cannot for the life of me figure out how to set a background image on all pages. Is it possible? Can it be done via CSS? What should the path to the image look like?

Having trouble getting a pdf out when running on vagrant/homestead server.

I followed the install instructions and I verified that wkhtmltopdf command works on my server.
When I try something very simple to just see what I can get like:

$pdf = App::make('snappy.pdf.wrapper');
$pdf->loadHTML('<h1>Test</h1>');
dd($pdf);

I get the following object which seem to be correct:

PdfWrapper {#299 ▼
  #snappy: IlluminateSnappyPdf {#297 ▶}
  #options: []
  +"html": "<h1>Test</h1>"
  +"file": null
}

But when I try to download some kind of pdf I just get a blank page back. No errors or anything.

I tried

return $pdf->stream('test.pdf');

and the other examples in the repository and I get nothing.

Not recognized as an internal or external command

Hi,

I followed the instructions on https://github.com/KnpLabs/snappy#wkhtmltopdf-binary-as-composer-dependencies and I changed the binary of pdf and image in my config file like this:

    'pdf' => array(
        'enabled' => true,
        'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),
        'timeout' => false,
        'options' => array(),
    ),
    'image' => array(
        'enabled' => true,
        'binary' => base_path('vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64'),
        'timeout' => false,
        'options' => array(),
    ),

But I keep getting:


I don't know what I am doing wrong.

Thanks,

The exit status code '126'

Hi,

I have some strange exception related with wkhtmltopdf driver premissions.

The exit status code '126' says something went wrong: stderr: "sh: 1: /vendor/project_name/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64: Permission denied " stdout: "" command: /opt/project_name/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 --lowquality '/tmp/knp_snappy53bc0f6b50a847.44217361.html' '/opt/project_name/app/storage/tmp/bill-123.pdf'.

Example code I'm using:

$snappy = \App::make('snappy.pdf');


$snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', storage_path().'/tmp/bill-123.pdf');

Thank you for any guidance.

Unable to modify font-size css property

I'm using your library to generate PDF's and it's awesome, but I need to reduce the font-size of the document and I can't.

I tried to declare the propety in a <style> tag inside html code and declaring style='' inside the body html tag, but it didn't work.Any suggestion? Thanks for your time and your code!

Can not save PDF (path)

Hi, I am using Laravel 5 and following code:

PDF::loadFile($url)
    ->callSettings()
    ->save('/home/vagrant/somecompany/src/public/pdf/offer/Somename_'. $offer->code .'.pdf');

I am getting following error

RuntimeException in AbstractGenerator.php line 305:
The file ... was not created ...

My creating of PDF works fine though. I think it should be path related issue?

style media print

I possible (like your dompdf) force to use media="print" style to generate the pdf?

Including CSS file not working on Homestead

@barryvdh -- firstly, thank you very much for writing this wrapper, much appreciated.

When I have a (blade) view pdfs.example like:

<!DOCTYPE html>
<html>
<head>
    <title>Scantron Form</title>
    {{ HTML::style('css/style.min.css') }}
</head>
<body>
    <p>My code here</p>
</body>

and an associated route which maps to a controller function that contains:

        $pdf  = PDF::loadView('pdfs.example');
        return $pdf->stream();

I get 'failed to load pdf document' when I try to view the pdf in-browser. I am using a laravel homestead environment and accessing it with a url like http://mysite.dev:8000/pdf/example.

I've found that if I replace the HTML::style() line with <style type="text/css"> and paste in my minified css file, everything works as expected.

laravel.log shows [2015-01-05 12:03:24] local.ERROR: exception 'RuntimeException' with message 'The exit status code '1' says something went wrong:

Let me know if there's anything else I can provide to help explain the issue. I'm not sure whether this is an error with snappy itself or the wrapper, or if I'm just doing something wrong?

Thanks for any insight you can provide.

Update: I linked to this issue in my related thread over on laracasts

Error while opening shared libraries: libjpeg.so.8

OS: CentOS 6.5 x64

I have verified that libjpeg is installed, but the version I have is libjpeg-turbo-1.2.1-3.el6_5.x86_64

I installed the package laravel-dompdf and it seemed to work fine, but for some reason I can't get this one to work.

Any thoughts on this? Thanks!

Using --viewport-size on Snappy

Hi,
I'm using a admin panel with Twitter Bootstrap 3, and my pdfs are getting the responsible styles. I was looking for this option (--viewport-size) on the wkhtmltopdf docs, but there aren't any examples.

Is it possible to use this option with Snappy? Or there is other way to fix the Bootstrap display styles?

Thanks

variables don't work?

Hi Barry,

Maybe I'm doing something wrong but with this code:

$servicecase = Servicecase::find($id);
$pdf = App::make('snappy.pdf.wrapper');
$pdf = PDF::loadView('backend.servicecases.receipt', $servicecase);
return $pdf->setOption('margin-top', 5)->stream();

I can't pull data off the variable: Undefined variable: servicecase

Am i missing something? And can i perhaps use multiple vars?

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.