Download the PHP package spraed/pdf-generator-bundle without Composer

On this page you can find all versions of the php package spraed/pdf-generator-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pdf-generator-bundle

SpraedPDFGeneratorBundle

SpraedPDFGeneratorBundle generates HTML documents to PDF. The bundle gives you the chance to add a page header and footer very easily (which can be disabled/switched on the first page).

It works with a little jar library based on the Flying Saucer project. So you need to run Java on your server (Java 6 or later).

Total Downloads Latest Stable Version

Installation using Composer

composer require spraed/pdf-generator-bundle

Usage

There is a service registered in the services.yml to generate pdf files. Just call the PDF generator from the service class and call the generatePDF() method with the XHTML and the url of the PDF:

$html = $this->renderView('AcmeDemoBundle:Default:index.html.twig');
$pdfGenerator = $this->get('spraed.pdf.generator');

Also you are able to set an encoding option (you can leave the second parameter, it defaults to UTF-8):

$pdfGenerator->generatePDF($html, 'UTF-8');

Anything else will be handled by the Response object in the controller, i.e.:

    $html = $this->renderView('ACMEYourBundle:Print:print.html.twig');
    $pdfGenerator = $this->get('spraed.pdf.generator');

    return new Response($pdfGenerator->generatePDF($html),
                    200,
                    array(
                        'Content-Type' => 'application/pdf',
                        'Content-Disposition' => 'inline; filename="out.pdf"'
                    )
    );

If you wish the pdf to be offered as a download, simply change 'inline' in 'Content-Disposition' to 'attachment'.

Make sure that all assets in your HTML are linked with absolute paths, because the HTML is copied into a tmp folder on the server. If you want to add an image to your twig it should look something like this:

    {{ app.request.scheme ~'://' ~ app.request.httpHost ~ asset('images/foo.jpg') }}

You are also capable of printing multiple pdfs in one stack. Saying you generate multiple documents from multiple html files and you want to output those in on huge pdf file, there is the 'generatePDFs' method which takes an array of rendered html Views and sticks those together:

    $twigs[0] = 'SpraedSomethingBundle:Print:print_pdf_one.html.twig'
    $twigs[1] = 'SpraedSomethingBundle:Print:print_pdf_two.html.twig'

    $htmlCollection = array();
    foreach($twigs as $twig){
            $htmlCollection[] = $this->renderView($twig);
    }

    return new Response($pdfGenerator->generatePDFs($htmlCollection, 'UTF-8'),
        200,
        array(
            'Content-Type' => 'application/pdf',
            'Content-Disposition' => 'inline; filename="out.pdf"'
        )
    );

To define proper print css you might want to read into the w3.org's hints on that: w3.org

Configuration

Example configuration options:

    spraed_pdf_generator:
        command:
            env:
                FOO: BAR
        java:
            full_path: /path/to/java

The command environment will add environment variables when running the Java application.


All versions of pdf-generator-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
symfony/framework-bundle Version ^6.0.4
matthiasnoback/symfony-config-test Version ^4.2.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package spraed/pdf-generator-bundle contains the following files

Loading the files please wait ....