yetiforce / yetiforcepdf
Library that generate pdf files from html.
Fund package maintenance!
Open Collective
Requires
- php: >=7.4
- ext-bcmath: *
- ext-dom: *
- ext-filter: *
- ext-gd: *
- ext-libxml: *
- ext-mbstring: *
- ext-zlib: *
- composer/ca-bundle: ^1
- guzzlehttp/guzzle: ^7
- milon/barcode: ^11
- phenx/php-font-lib: ^0.5
- sabberworm/php-css-parser: ^8
- dev-developer
- 0.1.42
- 0.1.41
- 0.1.40
- 0.1.39
- 0.1.38
- 0.1.37
- 0.1.36
- 0.1.35
- 0.1.34
- 0.1.33
- 0.1.32
- 0.1.31
- 0.1.30
- 0.1.29
- 0.1.28
- 0.1.27
- 0.1.26
- 0.1.25
- 0.1.24
- 0.1.23
- 0.1.22
- 0.1.21
- 0.1.20
- 0.1.19
- 0.1.18
- 0.1.17
- 0.1.16
- 0.1.15
- 0.1.14
- 0.1.13
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-master
- dev-renovate/phenx-php-font-lib-1.x
This package is auto-updated.
Last update: 2024-12-09 12:28:10 UTC
README
PDF generation library for PHP
The best library in the world to generate PDF from HTML
Issues & bugs
Report errors related to PDF in https://github.com/YetiForceCompany/YetiForceCRM/issues
Basic usage (for more take a look at examples folder)
<?php $loader = require '../vendor/autoload.php'; $document = (new YetiForcePDF\Document())->init(); $document->loadHtml('<div style="text-align:center;">your html goes here</div>'); $pdfFile = $document->render(); file_put_contents('YourPDF.pdf', $pdfFile);
Supported css rules
- font-family
- font-size
- font-weight
- font-style
- margin [px, em, cm, mm, pt, in]
- margin-left [px, em, cm, mm, pt, in]
- margin-top [px, em, cm, mm, pt, in]
- margin-right [px, em, cm, mm, pt, in]
- margin-bottom [px, em, cm, mm, pt, in]
- padding [px, em, cm, mm, pt, in]
- padding-left [px, em, cm, mm, pt, in]
- padding-top [px, em, cm, mm, pt, in]
- padding-right [px, em, cm, mm, pt, in]
- padding-bottom [px, em, cm, mm, pt, in]
- border [px, em, cm, mm, pt, in]
- border-left
- border-top
- border-right
- border-bottom
- border-left-width [px, em, cm, mm, pt, in]
- border-top-width [px, em, cm, mm, pt, in]
- border-right-width [px, em, cm, mm, pt, in]
- border-bottom-width [px, em, cm, mm, pt, in]
- border-color [hex, rgb]
- border-left-color [hex, rgb]
- border-top-color [hex, rgb]
- border-right-color [hex, rgb]
- border-bottom-color [hex, rgb]
- border-style
- border-left-style
- border-top-style
- border-right-style
- border-bottom-style
- box-sizing
- display [block, inline, inline-block, none]
- width [%, px, em, cm, mm, pt, in]
- height [%, px, em, cm, mm, pt, in]
- overflow
- vertical-align [baseline, top, bottom, middle]
- line-height [px, em, cm, mm, pt, in]
- background-color [hex, rgb]
- color [hex, rgb, rgba, named]
- word-wrap [normal]
- max-width
- min-width
- white-space [normal]
- word-wrap
- float
- clear
- table displays
- background-image
- rgb / rgba color
Available fonts by default
- DejaVu Sans
Custom fonts
Upload your ttf font files to server and add following code at the beginning of your html.
Each font weight and style could be defined if your font supports it.
<div data-font data-family="Your Font Name" data-weight="400" data-style="normal" data-file="/absolute/path/to/font/file/YourFontName-Regular.ttf"></div> <div data-font data-family="Your Font Name" data-weight="400" data-style="italic" data-file="/absolute/path/to/font/file/YourFontName-Italic.ttf"></div> <div data-font data-family="Your Font Name" data-weight="800" data-style="normal" data-file="/absolute/path/to/font/file/YourFontName-Bold.ttf"></div> <div data-font data-family="Your Font Name" data-weight="800" data-style="italic" data-file="/absolute/path/to/font/file/YourFontName-BoldItalic.ttf"></div>
You can also add fonts inside php like:
\YetiForcePDF\Document::addFonts([ [ 'family' => 'Pacifico', 'weight' => '400', 'style' => 'normal', 'file' => '/absolute/path/to/Pacifico/Pacifico-Regular.ttf' ], [ 'family' => 'Lobster Two', 'weight' => '400', 'style' => 'normal', 'file' => '/absolute/path/to/Lobster_Two/LobsterTwo-Regular.ttf' ], [ 'family' => 'Lobster Two', 'weight' => 'bold', 'style' => 'normal', 'file' => '/absolute/path/to/Lobster_Two/LobsterTwo-Bold.ttf' ], ]);
Headers, footers and watermarks
You can define header, footer and watermark to be displayed inside pdf file
<div data-header> <table style="border:1px solid greenyellow;font-size:12px;margin:10px;background-color:yellow;width:100%"> <tr> <td style="width:50%;border:1px solid red;">This is a page header</td> <td style="text-align:right;border:1px solid red;">which could be table</td> </tr> </table> </div> <div data-footer> <div style="border:1px solid greenyellow;font-size:14px;margin:10px;"> <div style="text-align:center">Footer</div> </div> </div> <div data-watermark style="text-align:center;"> <div style="display:inline-block;font-size:20px;opacity:0.25;"> <img src="Image.jpg"> </div> </div>
Page format, orientation and margins
Page format, orientation and margins could be defined from YetiForcePDF instance or inside html code.
If you have multiple page formats and orientations inside one pdf document you can insert multiple data-page-group
s to your html.
<div data-page-group data-format="A4" data-orientation="P" data-margin-left="30" data-margin-right="30" data-margin-top="40" data-margin-bottom="40" data-header-top="10" data-footer-bottom="10" ></div>
Page break
When you want to add new page use data-page-group
or set style on div element page-break-after:always
.
<div style="page-break-after:always;"></div>
Page numbering
When you want to place page number (in header or footer for example) you can do it by placing {p}
or {a}
text inside your html - it will be replaced by {p}
page number or {a}
all pages count.
<div data-footer> <div style="border:1px solid greenyellow;font-size:14px;margin:10px;"> <div style="text-align:center">Page {p} / {a}</div> </div> </div>
Barcodes
<div data-barcode="EAN13" data-size="1" data-height="16" data-code="9780691147727"></div>
TODO (later but important)
- floats
- display: list-item
- basic transformations (rotateXY, scaleXY, translateXY)
- position (absolute, relative)
License
Distributed under the MIT license. See LICENSE for details.
👥 Contributors
This project exists thanks to all the people who contribute.