Skip to content

Commit

Permalink
Merge pull request #24 from YetiForceCompany/developer
Browse files Browse the repository at this point in the history
test
  • Loading branch information
mariuszkrzaczkowski committed Apr 9, 2021
2 parents 97ee849 + 39e8171 commit 32dd9a8
Show file tree
Hide file tree
Showing 226 changed files with 19,299 additions and 590 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: yetiforcecrm
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.idea/
vendor/
.vscode/
.sonarlint/
.history/
30 changes: 12 additions & 18 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
MIT License
YetiForce Public License v3
Open license based on MIT license
Copyright (c) 2017 YetiForce Sp. z o.o. (Ltd.)

Copyright (c) 2018 YetiForce Sp. z o.o.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The inclusion of abovementioned notices may be in a form of an active link to the license, as stated in Appendix A.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The Software used for more than 14 days must be registered via the built-in form.
If such registration is not possible, further use of the Software requires registration via email (registration@yetiforce.com), as stated in Appendix B.
The registration form is properly submitted if sent (data entry to electronic communication system) and if it contains complete and true data.
Registration is mandatory for any company (registration does not apply to employees of these companies or private individuals) that uses, configures and/or modifies the Software, regardless of whether the entity does it for itself or for other subjects.
199 changes: 193 additions & 6 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,15 +1,202 @@
# YetiForcePDF
[![SymfonyInsight](https://insight.symfony.com/projects/2988ef66-83db-4ed9-9ba8-6fb4474566bd/big.png)](https://insight.symfony.com/projects/2988ef66-83db-4ed9-9ba8-6fb4474566bd)
[![Latest Stable Version](https://poser.pugx.org/yetiforce/yetiforcepdf/v/stable)](https://packagist.org/packages/yetiforce/yetiforcepdf)
[![Build Status](https://travis-ci.org/YetiForceCompany/YetiForcePDF.svg?branch=developer)](https://travis-ci.org/YetiForceCompany/YetiForcePDF)
[![Analytics](https://ga-beacon.appspot.com/UA-81376231-2/welcome-page)](https://github.com/igrigorik/ga-beacon)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/YetiForceCompany/YetiForcePDF/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/YetiForceCompany/YetiForcePDF/?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/b2e8645f5091496089ed203d05a05d61)](https://app.codacy.com/app/mariuszkrzaczkowski/YetiForcePDF?utm_source=github.com&utm_medium=referral&utm_content=YetiForceCompany/YetiForcePDF&utm_campaign=Badge_Grade_Settings)
[![Maintainability](https://api.codeclimate.com/v1/badges/af478ddd07cf7278841a/maintainability)](https://codeclimate.com/github/YetiForceCompany/YetiForcePDF/maintainability)
[![SymfonyInsight](https://insight.symfony.com/projects/d944b009-6a76-4957-8833-db95b010e5a5/big.png)](https://insight.symfony.com/projects/d944b009-6a76-4957-8833-db95b010e5a5)

## PDF generation library for PHP (work in progress)
## PDF generation library for PHP
The best library in the world to generate PDF from HTML

### example
## Basic usage (for more take a look at examples folder)

```PHP
```php
<?php
$loader = require __DIR__ . '/vendor/autoload.php';
$loader = require '../vendor/autoload.php';
$document = (new YetiForcePDF\Document())->init();
$document->loadHtml('<div style="font-family: Times-Roman;font-size:50px;margin-left:100px;margin-bottom:200px;">hello world!</div><div style="font-family: Times-Roman;font-size:50px;margin-left:50px;margin-bottom:100px;">hello world2!</div>'');
$document->loadHtml('<div style="text-align:center;">your html goes here</div>');
$pdfFile = $document->render();
file_put_contents('YourPDFD.pdf', $pdfFile);
```

### Supported css rules

- [x] font-family
- [x] font-size
- [x] font-weight
- [x] font-style
- [x] margin [px, em, cm, mm, pt, in]
- [x] margin-left [px, em, cm, mm, pt, in]
- [x] margin-top [px, em, cm, mm, pt, in]
- [x] margin-right [px, em, cm, mm, pt, in]
- [x] margin-bottom [px, em, cm, mm, pt, in]
- [x] padding [px, em, cm, mm, pt, in]
- [x] padding-left [px, em, cm, mm, pt, in]
- [x] padding-top [px, em, cm, mm, pt, in]
- [x] padding-right [px, em, cm, mm, pt, in]
- [x] padding-bottom [px, em, cm, mm, pt, in]
- [x] border [px, em, cm, mm, pt, in]
- [x] border-left
- [x] border-top
- [x] border-right
- [x] border-bottom
- [x] border-left-width [px, em, cm, mm, pt, in]
- [x] border-top-width [px, em, cm, mm, pt, in]
- [x] border-right-width [px, em, cm, mm, pt, in]
- [x] border-bottom-width [px, em, cm, mm, pt, in]
- [x] border-color [hex, rgb]
- [x] border-left-color [hex, rgb]
- [x] border-top-color [hex, rgb]
- [x] border-right-color [hex, rgb]
- [x] border-bottom-color [hex, rgb]
- [ ] border-style
- [ ] border-left-style
- [ ] border-top-style
- [ ] border-right-style
- [ ] border-bottom-style
- [ ] box-sizing
- [x] display [block, inline, inline-block, none]
- [x] width [%, px, em, cm, mm, pt, in]
- [x] height [%, px, em, cm, mm, pt, in]
- [ ] overflow
- [x] vertical-align [baseline, top, bottom, middle]
- [x] line-height [px, em, cm, mm, pt, in]
- [x] background-color [hex, rgb]
- [x] color [hex, rgb, rgba, named]
- [x] word-wrap [normal]
- [ ] max-width
- [ ] min-width
- [x] white-space [normal]
- [ ] word-wrap
- [ ] float
- [ ] clear
- [x] table displays
- [x] background-image
- [x] 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.

```php
<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:

```php
\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

```php
<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.

```php
<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`.

```php
<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.

```php
<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

```php
<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
YetiForce Public License v3
=======
file_put_contents('test.pdf', $pdfFile);
```
22 changes: 17 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@
"html",
"html to pdf"
],
"homepage": "http://yetiforce.com",
"license": "MIT",
"homepage": "https://github.com/YetiForceCompany/YetiForcePDF",
"authors": [
{
"name": "Rafal Pospiech",
"email": "r.pospiech@yetiforce.com"
"name": "YetiForceCompany",
"email": "info@yetiforce.com",
"homepage": "https://yetiforce.com/"
}
],
"require": {
"php": ">=7.2"
"php": ">=7.3",
"ext-mbstring": "*",
"ext-dom": "*",
"ext-libxml": "*",
"ext-bcmath": "*",
"ext-zlib": "*",
"ext-gd": "*",
"ext-filter": "*",
"phenx/php-font-lib": "^0.5.1",
"guzzlehttp/guzzle": "^7.0",
"composer/ca-bundle": "^1.1",
"milon/barcode": "^8.0.0",
"sabberworm/php-css-parser": "^8.3"
},
"autoload": {
"psr-4": {
Expand Down
19 changes: 0 additions & 19 deletions composer.lock

This file was deleted.

10 changes: 10 additions & 0 deletions examples/All.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

$loader = require '../vendor/autoload.php';
$files = ['simpleinline', 'Pages'];
foreach ($files as $file) {
$document = (new YetiForcePDF\Document())->init();
$document->loadHtml(file_get_contents($file . '.html'));
$pdfFile = $document->render();
file_put_contents($file . '.pdf', $pdfFile);
}
4 changes: 4 additions & 0 deletions examples/Barcode.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div style="border:1px solid red;">
Barcode:
<div data-barcode="EAN13" data-size="1" data-height="16" data-code="9780691147727"></div>
</div>
10 changes: 10 additions & 0 deletions examples/Barcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

$loader = require '../vendor/autoload.php';
$files = ['Barcode'];
foreach ($files as $file) {
$document = (new YetiForcePDF\Document())->init();
$document->loadHtml(file_get_contents($file . '.html'));
$pdfFile = $document->parse()->render();
file_put_contents($file . '.pdf', $pdfFile);
}

0 comments on commit 32dd9a8

Please sign in to comment.