Giter VIP home page Giter VIP logo

famelo.pdf's Introduction

Famelo.PDF

Scrutinizer Code Quality

This package provides a quick and simple way to generate a PDF from a Fluid Template through the MPDF library

Example:

$document = new \Famelo\PDF\Document('My.Package:SomeDocument');
$document->assign('someVariable', 'foobar');

// Trigger a Download and exit
$document->download('SomeDocument ' . date('d.m.Y') . '.pdf');

// Show the document inline and exit
$document->send();

// Save the document to a local file
$document->save('/Some/Path/SomeDocument ' . date('d.m.Y') . '.pdf');

This example will render a template located at 'resource://My.Package/Private/Documents/SomeDocument.html and convert it to PDF.

Page Format and orientation

By default pages will be rendered as a A4 Portrait. You can choose another format/orientation like this:

// set format to A5 Portrait
$document = new \Famelo\PDF\Document('My.Package:SomeDocument', 'A5');

// set format to an A4 Landscape
$document->setFormat('A4-L');

// set format to 100mm x 200mm
$document->setFormat(array(100, 200));

The MPDF library supports different page sizes with these keywords or an array containing 2 values for width + height:

  • A0 - A10
  • B0 - B10
  • C0 - C10
  • 4A0
  • 2A0
  • RA0 - RA4
  • SRA0 - SRA4
  • Letter
  • Legal
  • Executive
  • Folio
  • Demy
  • Royal
  • Ledger
  • Tabloid*

All of the above values can be suffixed with "-L" to force a Landscape page orientation document e.g. "A4-L". If format is defined as a string, the final orientation parameter will be ignored.

*Ledger and Tabloid are standard formats with the same page size but different orientation (Ledger is landscape, and Tabloid is portrait). mPDF treats these identically; if you wish to use Ledger, you should specify "Ledger-L" for landscape.

Page numbering in Fluid

If you want to use mPDFs page numbering variables like {PAGENO} or {nbpg} you have to wrap them in a CDATA section, to keep Fluid from interpreting them as variables.

PDF Generator Implementation

By default this Library uses the MPDF library to generate the PDFs. But you can change the defaultGenerator through the Settings.yaml like this:

Famelo:
  PDF:
    # Generator using wkhtmltopdf through knplabs/knp-snappy
    DefaultGenerator: '\Famelo\PDF\Generator\WebkitGenerator'
    DefaultGeneratorOptions:
      Binary: '/usr/local/bin/wkhtmltopdf'

Feel free to create and use a generator for your favorite PDF Library And send me a Pull-Request if you think others might like to use it :)

famelo.pdf's People

Contributors

albe avatar andyhirsch avatar codelingobot avatar cvette avatar iseries avatar kdambekalns avatar koernchen02 avatar midalmis avatar mkuiphuis avatar mneuhaus avatar philsturgeon avatar scrutinizer-auto-fixer avatar

Stargazers

 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

famelo.pdf's Issues

License

Hello,

I am using your code in a commercial project, can you please tell me what license does it have?

Thank you!

No Rendering in Flow 7.3

Hi,
I can't create pdfs under neos flow 7.3 - neither as download, save or inline.
I always get a blank page in the browser - no error message in the logs. It uses mpdf library for generation.
In previous versions it worked like a charm. What's wrong?

my composer.json

"require": {
        "neos/flow": { "~7.3.0",
        "neos/welcome": "~7.3.0",
        "neos/behat":"~7.3.0",
        "happy/coding":"@dev",
        "famelo/pdf":"^4.2"

Action

/**
   * @return void
   */
    public function pdfAction() {
		$document = new \Famelo\PDF\Document('Happy.Coding:Test');
		$document->assign('someVariable', 'foobar');
		$document->send();
		$document->download('Test' . date('d.m.Y') . '.pdf');
		$document->save('' . date('d.m.Y') . '.pdf');
	}

Template Test.html in /Happy.Coding/Resources/Private/Documents/

{namespace fm=Famelo\PDF\ViewHelpers}
<f:layout name="PDF"/>
<f:section name="Content">
	<p>HELLO WORLD</p>
</f:section>

Errors on Using ViewHelpers

f:layout
f:translate
does not work as expected.

EXAMPLE

Action:
public function pdfAction(\BLEICKER\Shop\Domain\Model\Order $order) {
$document = new \Famelo\PDF\Document('BLEICKER.Shop:Order/ShowResult');
$document->assign('order',$order);
$document->download('SomeDocument ' . date('d.m.Y') . '.pdf');
}

Template:
<f:translate id="myid">Translate this/f:translate

Exception:
#1309269952: Invalid resource URI "resource://Private/Translations/en/Main.xlf": Package "Private" is not available.

Support different Page Sizes and Orientations

It should be possible to create different page sizes and orientations like this:

// A3 landscape
$document = new \Famelo\PDF\Document('My.Package:SomeDocument', 'A3-L');

// A3 portrait
$document = new \Famelo\PDF\Document('My.Package:SomeDocument', 'A3');

// Letter portrait
$document = new \Famelo\PDF\Document('My.Package:SomeDocument', 'Letter');

// 190mm x 236mm
$document = new \Famelo\PDF\Document('My.Package:SomeDocument', array(190, 236));
...

The MPDF library supports different page sizes with these keywords or an array containing 2 values for width + height:

A0 - A10, B0 - B10, C0 - C10
4A0, 2A0, RA0 - RA4, SRA0 - SRA4
Letter, Legal, Executive, Folio
Demy, Royal
A (Type A paperback 111x178mm)
B (Type B paperback 128x198mm)
Ledger, Tabloid*

All of the above values can be suffixed with "-L" to force a Landscape page orientation document e.g. "A4-L". 
If format is defined as a string, the final orientation parameter will be ignored.

*Ledger and Tabloid are standard formats with the same page size but different orientation (Ledger is landscape, and Tabloid is portrait). mPDF treats these identically; if you wish to use Ledger, you should specify "Ledger-L" for landscape.

cc @markyourweb is this something that you're missing? :)

source: http://forum.typo3.org/index.php?t=tree&th=204714&goto=714292&#msg_714292

Exception log entries

First of all thx for this nice package.

The pdf rendering works like a charm and without any exception. But the exception log contains exceptions if the controller action of my package which creates the pdf doesn't have a own template. My workaround is creating an empty template for my controller action.

Can you fix this ... so that no empty template is required?

Best Falk

mPDF version without a bound in composer.json

Hi,

I notice that your composer.json mpdf constraint is missing an upper (or lower) bound. This will cause problems in following weeks when mPDF v 7.0 stable is out - it has a changed namespace, structure and constructor parameters.

This is a heads up, you might want to change your constraint or prepare your code for mPDF 7.0.

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.