Skip to content

Commit

Permalink
Add lib extension
Browse files Browse the repository at this point in the history
  • Loading branch information
f_cellier committed Jan 10, 2017
1 parent ff40869 commit 9f4d9ec
Show file tree
Hide file tree
Showing 16 changed files with 700 additions and 318 deletions.
287 changes: 287 additions & 0 deletions Lib/Barecode/PDF_Code128.php

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion lib/cellfit/cellfit.php → Lib/Cellfit/FPDF_CellFit.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

class FPDF_CellFit extends \DecoratorPdf {
namespace lib\cellfit;

use lib\DecoratorPdf;

class FPDF_CellFit extends DecoratorPdf {

//Cell with horizontal scaling if text is too wide
function CellFit($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='', $scale=false, $force=true)
Expand Down
12 changes: 12 additions & 0 deletions Lib/DecoratorPdf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace lib;

abstract class DecoratorPdf extends \FPDF {
protected $pdf;

public function __construct (\FPDF $pdf=NULL, $orientation='P', $unit='mm', $size='A4') {
parent::__construct ($orientation='P', $unit='mm', $size='A4');
$this->pdf = $pdf;
}
}
6 changes: 5 additions & 1 deletion lib/draw/draw.php → Lib/Draw/PDF_Draw.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
*
*/

class PDF_Draw extends \DecoratorPdf {
namespace lib\draw;

use lib\DecoratorPdf;

class PDF_Draw extends DecoratorPdf {
// Sets line style
// Parameters:
// - style: Line style. Array with keys among the following:
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Easy Pdf Bundle

Thid bundle allow you to design your pdf easily.

## Documentation

1. [Installation](/Resources/doc/installation.md)
2. [Usage](/Resources/doc/usage.md)
3. [Lib](/Resources/doc/lib.md)
4. [Dev](/Resources/doc/dev.md)

## What is FPDF?

Expand All @@ -26,3 +32,9 @@ _FPDF requires no extension (except zlib to activate compression and GD for GIF
The FPDI class is an extension for FPDF allowing you to import existing PDF pages into FPDF. It extends FPDF_TPL which adds a kind of template feature to FPDF.

FPDI transforms a PDF page into the same structure that is used by FPDF_TPL. The class offers all available methods as you already know from FPDF and extends it with some more methods.

### Todo

- Made a service to inject easily the pdf instance;
- Show an exemple made by dependencies injection;
- Add visual example.
24 changes: 24 additions & 0 deletions Resources/doc/dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Dev


If you want to debug this bundle, just clone it and go on example folder on lib then add a "app.php" file with this snippet in order to do test.

```
<?php
require '../../../vendor/autoload.php';
require 'Controller/AcmeController.php';
require 'Entity/Pdf.php';
require '../../../Lib/DecoratorPdf.php';
require '../../../Lib/Draw/PDF_Draw.php';
require '../../../Lib/Cellfit/FPDF_CellFit.php';
require '../../../Lib/Barecode/PDF_Code128.php';
$ac = new Acme\DemoBundle\Lib\Controller\AcmeController();
$ac->indexAction();
```

Then, you can launch it on your dev tool php project, for example at here:

`http://domain.tld/EasyPdfBundle/Resources/example/Lib/app.php`
196 changes: 196 additions & 0 deletions Resources/doc/lib.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# Lib

## Getting started

Lots of lib are available such as Draw, many CodeBare type which allow you to do many things on pdf. The pdf is decorate through many functions available in this lib.

1. [Draw](#draw)
2. [Cellfit](#cellfit)
3. [Barecode 128](#barecode)

## [Draw](#draw)

This extension allows to draw lines, rectangles, ellipses, polygons and curves with line style.

> Public methods are:
>
> • SetLineStyle($style: array)
>
> Sets line style. Parameters are:
>
> - style: an array with the following possible keys:
>
> . width: width of the line in user units.
> . cap: type of cap to put on the line (butt, round, square). The difference between "square" and "butt" is that "square" projects a flat end past the end of the line.
> . join: miter, round, or bevel.
> . dash: dash pattern. Is 0 (without dash) or array with series of length values, which are the lengths of the on and off dashes.
> . phase: modifier of the dash pattern which is used to shift the point at which the pattern starts.
> . color: draw color. Array with components (red, green, blue).
>
> • Line($x1: float, $y1: float, $x2: float, $y2: float, $style: array)
>
> Draws a line. Overrides the method from FPDF. Parameters are:
>
> - x1, y1: start point.
> - x2, y2: end point.
> - style: line style (array like for SetLineStyle).

> • Rect($x: float, $y: float, $w: float, $h: float, $style: string, $border_style: array, $fill_color: array)
> Draws a rectangle. Overrides the method from FPDF. Parameters are:
> - x, y: top left corner.
> - w, h: width and height.
> - style: style of rectangle (draw and/or fill: D, F, DF, FD).
- border_style: border style of rectangle. Array with index: (all => style) for all borders, or (L => style, T => style, R => style, B => style) for > each border. Style is an array like for SetLineStyle.
> - fill_color: fill color. Array with components (red, green, blue).
> • Curve($x0: float, $y0: float, $x1: float, $y1: float, $x2: float, $y2: float, $x3: float, $y3: float, $style: string, $line_style: array, $fill_> color: array)
> Draws a Bézier curve. Parameters are:
> - x0, y0: start point.
> - x1, y1: control point 1.
> - x2, y2: control point 2.
> - x3, y3: end point.
> - style: style of rectangle (draw and/or fill: D, F, DF, FD).
> - line_style: line style for curve. Array like for SetLineStyle.
> - fill_color: fill color. Array with components (red, green, blue).
>
• Ellipse($x0: float, $y0: float, $rx: float, $ry: float, $angle: float, $astart: float, $afinish: float, $style: string, $line_style: array, $fill_> color: array, $nSeg: integer)
>
> Draws an ellipse. Parameters are:
>
> - x0, y0: center point.
> - rx, ry: horizontal and vertical radius (if ry is 0, this is a circle).
> - angle: orientation angle (anti-clockwise).
> - astart: start angle.
> - afinish: finish angle.
> - style: style of ellipse (draw and/or fill: D, F, DF, FD, C (D + close)).
> - line_style: line style for ellipse. Array like for SetLineStyle.
> - fill_color: fill color. Array with components (red, green, blue).
> - nSeg: ellipse is made up of nSeg Bézier curves.
>
> • Circle($x0: float, $y0: float, $r: float, $astart: float, $afinish: float, $style: string, $line_style: array, $fill_color: array, $nSeg: integer)
> Draws a circle. Parameters are:
> - x0, y0: center point.
> - r: radius.
> - astart: start angle.
> - afinish: finish angle.
> - style: style of circle (draw and/or fill: D, F, DF, FD, C (D + close)).
> - line_style: line style for circle. Array like for SetLineStyle.
> - fill_color: fill color. Array with components (red, green, blue).
> - nSeg: circle is made up of nSeg Bézier curves.
> • Polygon($p: array, $style: string, $line_style: array, $fill_color: array)
> Draws a polygon. Parameters are:
> - p: points. Array with values x0, y0, x1, y1,..., x(np-1), y(np-1).
> - style: style of polygon (draw and/or fill: D, F, DF, FD).
> - line_style: line style. Array with index (all => style) for all borders, or (0..np-1 => style) for each border. Style is an array like for > SetLineStyle.
> - fill_color: fill color. Array with components (red, green, blue)
> • RegularPolygon($x0: float, $y0: float, $r: float, $ns: Integer, $angle: float, $circle: boolean, $style: string, $line_style: array, $fill_color: > array, $circle_style: array, $circle_line_style: array, $circle_fill_color: array)
> Draws a regular polygon. Parameters are:
> - x0, y0: center point.
> - r: radius of circumscribed circle.
> - ns: number of sides.
> - angle: orientation angle (anti-clockwise).
> - circle: draw circumscribed circle or not.
> - style: style of polygon (draw and/or fill: D, F, DF, FD).
> - line_style: line style. Array with index (all => style) for all borders, or (0..ns-1 => style) for each border. Style is an array like for > SetLineStyle.
> - fill_color: fill color. Array with components (red, green, blue).
> - circle_style: style of circumscribed circle (draw and/or fill: D, F, DF, FD).
> - circle_line_style: line style for circumscribed circle. Array like for SetLineStyle.
> - circle_fill_color: fill color for circumscribed circle. Array with components (red, green, blue).
>
• StarPolygon($x0: float, $y0: float, $r: float, $nv: Integer, $ng: Integer, $angle: float, $circle: boolean, $style: string, $line_style: array, > $fill_color: array, $circle_style: array, $circle_line_style: array, $circle_fill_color: array)
>
> Draws a star polygon. Parameters are:
>
> - x0, y0: center point.
> - r: radius of circumscribed circle.
> - nv: number of vertices.
> - ng: number of gaps (ng % nv = 1 => regular polygon).
> - angle: orientation angle (anti-clockwise).
> - circle: draw circumscribed circle or not.
> - style: style of polygon (draw and/or fill) (D, F, DF, FD).
> - line_style: line style. Array with index (all => style) for all borders, or (0..n-1 => style) for each border. Style is an array like for > SetLineStyle.
> - fill_color: fill color. Array with components (red, green, blue).
> - circle_style: style of circumscribed circle (draw and/or fill) (D, F, DF, FD) (if draw).
> - circle_line_style: line style for circumscribed circle. Array like for SetLineStyle (if draw).
> - circle_fill_color: fill color for circumscribed circle. Array with components (red, green, blue).
> • RoundedRect($x: float, $y: float, $w: float, $h: float, $r: float, $round_corner: string, $style: string, $border_style: string, $fill_color: array)
>
> Draws a rounded rectangle. Parameters are:
> - x, y: top left corner.
> - w, h: width and height.
> - r: radius of the rounded corners.
- round_corner: draws rounded corners or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order: > top left, top right, bottom right and bottom left.
> - style: style of rectangle (draw and/or fill: D, F, DF, FD).
> - border_style: border style of rectangle. Array like for SetLineStyle.
> - fill_color: fill color. Array with components (red, green, blue).
## [Cellfit](#cellfit)

This is an extension and the doc says it an extension of Cell() allowing to output text with either character spacing or horizontal scaling.


> CellFit(float w [, float h [, string txt [, mixed border [, int ln [, string align [, boolean fill [, mixed link [, boolean scale [, boolean > force]]]]]]]]])
> The first 8 parameters are the same as Cell(). The additional parameters are:
> scale
> false: character spacing
> true: horizontal scaling
> force
> false: only space/scale if necessary (not when text is short enough to fit)
> true: always space/scale
> The following four methods are also provided for convenience, allowing all combinations of scale/force, and using only the 8 parameters of Cell():
> CellFitScale()
> CellFitScaleForce()
> CellFitSpace()
> CellFitSpaceForce()
## [CodeBar 128](#barecode)


This script handles Code 128 barcodes (A, B and C). All the 128 ASCII characters are available. A, B and C character sets are automatically selected according to the value to print.

**Code 128 barcodes have to be as width as the words number to be easier readable**

> Code128(float x, float y, string code, float w, float h)
>
> x: abscissa
> y: ordinate
> code: barcode value
> w: total width
> h: height
2 changes: 1 addition & 1 deletion Resources/doc/usage.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Usage

To resume, the bundle simply registers the fdpf class and the fpdi class. You just have to invoke them like this and FPDF will be include because FPDI extends FPDF.
To summerize, the bundle simply registers the fdpf class and the fpdi class. You just have to invoke them like this and FPDF will be include because FPDI extends FPDF.

**$pdf = new \FPDI();**
26 changes: 17 additions & 9 deletions ...mple/simple/Controller/AcmeController.php → ...example/Lib/Controller/AcmeController.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<?php

namespace Acme\DemoBundle\Controller;
namespace Acme\DemoBundle\Lib\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Acme\DemoBundle\Entity\Pdf;
use Acme\DemoBundle\Lib\Entity\Pdf;

class AcmeController extends Controller
class AcmeController
{
/**
* Clasic bundle controller
*/
public function indexAction()
{
$this->generationPdf();


return $this->render('AcmeDemoBundle:Acme:index.html.twig');
// Go on your page after generate the pdf !
return $this->render('AcmeDemoBundle:Folder:view.html.twig');
}

/**
* Main function that build and generate the pdf
*/
public function generationPdf()
{
// initiate FPDI
Expand All @@ -23,7 +28,7 @@ public function generationPdf()
// add a page
$pdf->AddPage();

// set the source file
// set the source file (if you have on, FPDI allow that, even, it create a A4 for you ! )
$pdf->setSourceFile($pdf->getWebPath());

// import page 1
Expand All @@ -37,12 +42,15 @@ public function generationPdf()
$pdf->SetTextColor(0, 0, 0);

$pdf->checkboxDemandeDt();
$pdf->checkboxDemandeDict();
$pdf->checkboxDemandeDtDictConjointe();
$pdf->destinataireDenomination("Zone destinataire>denomination");
$pdf->destinataireComplement("Zone destinataire>complement");
$pdf->numeroTelephone('0476898557');

// Use the barecode
$pdf->barecodeTest('I Want To Be A fred Today');

// Pdf is generated here !
$pdf->Output();
}
}

Loading

0 comments on commit 9f4d9ec

Please sign in to comment.