Skip to content

Commit

Permalink
Initial Version
Browse files Browse the repository at this point in the history
  • Loading branch information
kduma committed Jul 26, 2020
1 parent 4b6e27f commit d71cc11
Show file tree
Hide file tree
Showing 34 changed files with 2,339 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ docs
vendor
coverage
/.idea
/output.pdf
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Very short description of the package
# PDF Imposition Toolkit

[![Latest Version on Packagist](https://img.shields.io/packagist/v/kduma/pdf-imposition.svg?style=flat-square)](https://packagist.org/packages/kduma/pdf-imposition)
[![Build Status](https://img.shields.io/travis/kduma/pdf-imposition/master.svg?style=flat-square)](https://travis-ci.org/kduma/pdf-imposition)
[![Quality Score](https://img.shields.io/scrutinizer/g/kduma/pdf-imposition.svg?style=flat-square)](https://scrutinizer-ci.com/g/kduma/pdf-imposition)
[![Total Downloads](https://img.shields.io/packagist/dt/kduma/pdf-imposition.svg?style=flat-square)](https://packagist.org/packages/kduma/pdf-imposition)

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.
PDF Imposition Toolkit

## Installation

Expand All @@ -17,8 +17,24 @@ composer require kduma/pdf-imposition

## Usage

``` php
// Usage description here
```php
use Kduma\PdfImposition\LayoutGenerators\AutoGridPageLayoutGenerator;
use Kduma\PdfImposition\LayoutGenerators\Markers\PrinterBoxCutMarkings;
use Kduma\PdfImposition\PdfImposer;
use Kduma\PdfImposition\PdfSource;
use Kduma\PdfImposition\DTO\Size;

$cardSize = Size::make(90, 50);

$layoutGenerator = new AutoGridPageLayoutGenerator($cardSize);
$layoutGenerator->center();

$layoutGenerator = new PrinterBoxCutMarkings($layoutGenerator);

$PdfImposer = new PdfImposer($layoutGenerator);

$cards = (new PdfSource)->read('input.pdf');
$PdfImposer->export($cards, 'output.pdf');
```

### Testing
Expand Down Expand Up @@ -50,4 +66,4 @@ The GNU GPLv3. Please see [License File](LICENSE.md) for more information.

## PHP Package Boilerplate

This package was generated using the [PHP Package Boilerplate](https://laravelpackageboilerplate.com).
This package was generated using the [PHP Package Boilerplate](https://laravelpackageboilerplate.com).
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
}
],
"require": {
"php": "^7.1"
"php": "^7.4",
"mpdf/mpdf": "^8.0",
"tightenco/collect": "^7.19"
},
"require-dev": {
"phpunit/phpunit": "^7.0"
Expand Down
29 changes: 29 additions & 0 deletions demo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Kduma\PdfImposition\LayoutGenerators\Markers\HeadersMarkings;
use Kduma\PdfImposition\LayoutGenerators\Markers\PrinterBoxCutMarkings;
use Kduma\PdfImposition\LayoutGenerators\AutoGridPageLayoutGenerator;
use Kduma\PdfImposition\DTO\PageMargins;
use Kduma\PdfImposition\DTO\PageSize;
use Kduma\PdfImposition\PdfImposer;
use Kduma\PdfImposition\PdfSource;
use Kduma\PdfImposition\DTO\Size;

require __DIR__.'/vendor/autoload.php';

$cardSize = Size::make(90, 50);
$pageSize = PageSize::fromName('A4');
$pageMargins = PageMargins::make();

$layoutGenerator = new AutoGridPageLayoutGenerator($cardSize, 0, 0, $pageSize, $pageMargins);
$layoutGenerator->center();

$layoutGenerator = new PrinterBoxCutMarkings($layoutGenerator);
$layoutGenerator->setPrintEvery(5);

$layoutGenerator = new HeadersMarkings($layoutGenerator, 'Page {PAGENO}, Sheet {SHEET}');

$PdfImposer = new PdfImposer($layoutGenerator);

$cards = (new PdfSource)->read(__DIR__ . '/tests/test_input.pdf', true);
$PdfImposer->export($cards, 'output.pdf');
6 changes: 3 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<!-- <log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>-->
<!-- <log type="coverage-text" target="build/coverage.txt"/>-->
<!-- <log type="coverage-clover" target="build/logs/clover.xml"/>-->
</logging>
</phpunit>
57 changes: 57 additions & 0 deletions src/DTO/Box.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php


namespace Kduma\PdfImposition\DTO;


class Box
{
/**
* @var Point
*/
protected Point $point;

/**
* @var Size
*/
protected Size $size;

/**
* Box constructor.
*
* @param Point $point
* @param Size $size
*/
public function __construct(Point $point, Size $size)
{
$this->point = $point;
$this->size = $size;
}

/**
* @param Point $point
* @param Size $size
*
* @return Box
*/
public static function make(Point $point, Size $size): Box
{
return new Box($point, $size);
}

/**
* @return Point
*/
public function getPoint(): Point
{
return $this->point;
}

/**
* @return Size
*/
public function getSize(): Size
{
return $this->size;
}
}
38 changes: 38 additions & 0 deletions src/DTO/DuplexPdfPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php


namespace Kduma\PdfImposition\DTO;


class DuplexPdfPage
{
protected PdfPage $front;
protected PdfPage $back;

public function __construct(PdfPage $front, PdfPage $back)
{
$this->front = $front;
$this->back = $back;
}

public static function make(PdfPage $front, PdfPage $back): DuplexPdfPage
{
return new DuplexPdfPage($front, $back);
}

/**
* @return PdfPage
*/
public function getFront(): PdfPage
{
return $this->front;
}

/**
* @return PdfPage
*/
public function getBack(): PdfPage
{
return $this->back;
}
}
108 changes: 108 additions & 0 deletions src/DTO/Line.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php


namespace Kduma\PdfImposition\DTO;


class Line
{
/**
* @var Point
*/
protected Point $start;

/**
* @var Point
*/
protected Point $end;

/**
* @var float
*/
protected float $width;

/**
* Line constructor.
*
* @param Point $start
* @param Point $end
* @param float $width
*/
public function __construct(Point $start, Point $end, float $width)
{
$this->start = $start;
$this->end = $end;
$this->width = $width;
}

/**
* @param Point $start
* @param Point $end
* @param float $width
*
* @return Line
*/
public static function make(Point $start, Point $end, float $width): Line
{
return new Line($start, $end, $width);
}

/**
* @param Point $start
* @param float $length
* @param float $width
*
* @return Line
*/
public static function horizontal(Point $start, float $length, float $width): Line
{
return new Line($start, $start->add($length, 0), $width);
}

/**
* @param Point $start
* @param float $length
* @param float $width
*
* @return Line
*/
public static function vertical(Point $start, float $length, float $width): Line
{
return new Line($start, $start->add(0, $length), $width);
}

/**
* @param Point $point
* @param float $width
*
* @return Line
*/
public static function dot(Point $point, float $width): Line
{
return new Line($point, $point, $width);
}

/**
* @return Point
*/
public function getStart(): Point
{
return $this->start;
}

/**
* @return Point
*/
public function getEnd(): Point
{
return $this->end;
}

/**
* @return float
*/
public function getWidth(): float
{
return $this->width;
}
}
Loading

0 comments on commit d71cc11

Please sign in to comment.