Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Snappy Bundle Laravel Package

dlin/snappy-bundle

View on GitHub
Deep Wiki
Context7

Dlin Symfony Snappy Bundle

Dlin Symfony Snappy Bundle is wrapper bundle for Snapy :

Snappy is a PHP5 library allowing thumbnail, snapshot or PDF generation from a url >or a html page. It uses the excellent webkit-based wkhtmltopdf and wkhtmltoimage >available on OSX, linux, windows.

Dlin Symfony Snappy Bundle provides a configurable service to work with PDF files


Installation

Installation using Composer

NOTE: Unfortunately, Composer does not support repositories in nested dependencies, we have to include dependencies and repositories in the root composer.json.

Add to your composer.json:

json
{
    "require" :  {
        ....
        "dlin/snappy-bundle": "dev-master",
        "google/wkhtmltopdf-amd64": "0.11.0-RC1",
        "google/wkhtmltopdf-i386": "0.11.0-RC1",
    },

    ....

    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "google/wkhtmltopdf-amd64",
                "version": "0.11.0-RC1",
                "dist": {
                    "url": "http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2",
                    "type": "tar"
                }
            }
        },
        {
            "type": "package",
            "package": {
                "name": "google/wkhtmltopdf-i386",
                "version": "0.11.0-RC1",
                "dist": {
                    "url": "http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-i386.tar.bz2",
                    "type": "tar"
                }
            }
        }
    ]
}

Enable the bundle in you AppKernel.php

public function registerBundles()
{
    $bundles = array(
    ...
    new Dlin\Bundle\SnappyBundle\DlinSnappyBundle(),
    ...
}

Configuration

You can specify the installation location of wkhtmltopdf

#app/config/config.yml

dlin_snappy:
    pdf_service:
        wkhtmltopdf: /Applications/wkhtmltopdf.app/Contents/MacOS/wkhtmltopdf

For most OS, this bundle will try to download and install the wkhtmltopdf binary itself. No configuration is required unless you want to use a different wkhtmltopdf binary. For Mac servers, one will have to download the DMG file and install it. The above configuration is required.

Usage

Geting the service in a controller

$pdf =  $this->get('dlin.pdf_service');

Getting the service in a ContainerAwareService

$pdf = $this->container->get('dlin.pdf_service');

Using the method "createPdfFromHtml"

#Pdf will be created (replace if already exist) as file '/tmp/test.pdf'
$pdf->createPdfFromHtml('<html><body><h1>hello</h1></body>', '/tmp/test.pdf');

Using the method "createPdfFromUrl"

#Pdf will be created (replace if already exist) as file '/tmp/test.pdf'
$pdf->createPdfFromUrl('google.com', '/tmp/test.pdf');

Download to browser (HTTP headers will be set and script terminates)

$pdf->sendHtmlAsPdf('<html><body><h1>hello</h1></body>', 'downloadFileName.pdf');
#or
$pdf->sendUrlAsPdf('google.com', 'downloadFileName.pdf');

Show PDF inline in browser (HTTP headers will be set and script terminates)

$pdf->sendHtmlAsPdf('<html><body><h1>hello</h1></body>', 'downloadFileName.pdf', true);
#or
$pdf->sendUrlAsPdf('google.com', 'downloadFileName.pdf', true);

Notes

  • MAMP user couldl have problem using wkhtmltopdf. Please solve the problem here
  • Mac OSX requires its own wkhtmltopdf binnary. You can download it here.
  • On your *nix server, you might need to install a library (sudo apt-get install libxrender1)

License

MIT

Free Software, Yeah!

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed