Skip to content

Commit

Permalink
[TASK] Streamline PDF Layouts (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkott committed Nov 24, 2021
1 parent 07c0e5d commit 85175b4
Show file tree
Hide file tree
Showing 15 changed files with 259 additions and 73 deletions.
1 change: 1 addition & 0 deletions assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@
@import 'modules/badge';
@import 'modules/optionswitch';
@import 'modules/switchto';
@import 'modules/inlinepdf';
@import 'modules/example';
19 changes: 19 additions & 0 deletions assets/css/modules/_inlinepdf.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Inline PDF
//
.inline-pdf {
position: relative;
display: block;
width: 100%;
padding-bottom: 60%;
iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
.inline-pdf-a4 {
padding-bottom: 141.4%;
}
27 changes: 27 additions & 0 deletions src/Controller/StyleguideController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use T3G\Bundle\TemplateBundle\Pdf\AssociationLayoutPdf;
use T3G\Bundle\TemplateBundle\Pdf\GmbhLayoutPdf;
use T3G\Bundle\TemplateBundle\Pdf\SimplePdf;
use T3G\Bundle\TemplateBundle\ThemeConstants;

class StyleguideController extends AbstractController
Expand Down Expand Up @@ -209,4 +212,28 @@ public function componentText(): Response
{
return $this->render('@Template/styleguide/component/text.html.twig');
}

/**
* @return Response
*/
public function componentPdfGmbH(): Response
{
$pdf = new SimplePdf(new GmbhLayoutPdf());
$pdf->addPage();
return $this->render('@Template/styleguide/component/pdf.html.twig', [
'pdf' => $pdf
]);
}

/**
* @return Response
*/
public function componentPdfAssoc(): Response
{
$pdf = new SimplePdf(new AssociationLayoutPdf());
$pdf->addPage();
return $this->render('@Template/styleguide/component/pdf.html.twig', [
'pdf' => $pdf
]);
}
}
190 changes: 135 additions & 55 deletions src/Pdf/AssociationLayoutPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,75 +28,155 @@ public function getSenderAddress(): string
public function Header()
{
// Logo
$width = 45;
$height = $width / 3.70;
$logoWidth = 35;
$logoHeight = $logoWidth / 3.70;
$this->ImageSVG(
__DIR__ . '/../../assets/pdf/images/logo.svg',
25,
10,
$width,
$height
17,
$logoWidth,
$logoHeight
);

$this->SetY(12.75);
$this->SetX(80);
$this->setCellPaddings(2.5, 2.5, 2.5, 2.5);
$this->SetFillColor(255, 130, 0);
$this->SetTextColor(255, 255, 255);
$this->MultiCell(
0,
0,
'TYPO3 Association, Sihlbruggstrasse 105, 6340 Baar, Switzerland',
// Edge
$edgeWidth = 72;
$edgeHeight = 34;
$this->ImageSVG(
__DIR__ . '/../../assets/pdf/images/edge.svg',
138,
0,
'C',
true
$edgeWidth,
$edgeHeight
);

// Marker
$markerWidth = 4;
$markerHeight = 4;
$this->ImageSVG(
__DIR__ . '/../../assets/pdf/images/icon-caret-right.svg',
0.7,
103.2,
$markerWidth,
$markerHeight
);
$this->ImageSVG(
__DIR__ . '/../../assets/pdf/images/icon-caret-right.svg',
0.7,
208.2,
$markerWidth,
$markerHeight
);
}

public function Footer()
{
// Line
$this->SetLineStyle([
'width' => 0.25,
'cap' => 'butt',
'join' => 'miter',
'dash' => 0,
'color' => [200, 200, 200],
]);
$this->Line(25, 28, 190, 28);
}
$this->Line(25, 262, 190, 262);

public function Footer()
{
$this->SetTextColor(100, 100, 100);
$this->writeHTML('
<table>
<tr>
<td>
<strong>Contact</strong><br>
Telephone : +41 41 511 00 35<br>
E-Mail : info@typo3.org<br>
Backoffice: backoffice@typo3.org<br>
Web: association.typo3.org
</td>
<td>
<strong>TAX and Legal</strong><br>
CH-VAT: CHE-112.256.297 MWST<br>
DE-VAT: DE267 19843<br>
CH-Tax-ID: CHE-112.256.297<br>
DE-Tax-ID: 09431/35027
</td>
<td>
<strong>Payment in EUR</strong><br>
Sparkasse Hochrhein<br>
79761 Waldshut-Tiengen<br>
IBAN: DE18 6845 2290 0077 0154 28<br>
BIC (SWIFT): SKHRDE6W
</td>
<td>
<strong>Payment in CHF</strong><br>
Credit Suisse<br>
CH-8070 Zürich<br>
IBAN: CH55 0484 2039 5125 5100 0<br>
BIC (SWIFT): CRESCHZZ80C
</td>
</tr>
</table>
');
$iconWidth = 4;
$iconHeight = 4;

// Address
$this->ImageSVG(
__DIR__ . '/../../assets/pdf/images/icon-marker.svg',
24.3,
270,
$iconWidth,
$iconHeight
);
$this->writeHTMLCell(
0,
0,
29.7,
270.1,
implode(
'<br>',
[
'TYPO3 Association',
'Sihlbruggstrasse 105',
'6340 Baar',
'Switzerland',
]
)
);

// Contact
$this->ImageSVG(
__DIR__ . '/../../assets/pdf/images/icon-globe-alt.svg',
58.7,
270,
$iconWidth,
$iconHeight
);
$this->writeHTMLCell(
0,
0,
64.5,
270.1,
implode(
'<br>',
[
'association.typo3.org',
'info@typo3.org',
'backoffice@typo3.org',
'+41 41 511 00 35',
]
)
);

// Register
$this->ImageSVG(
__DIR__ . '/../../assets/pdf/images/icon-university.svg',
95.6,
270,
$iconWidth,
$iconHeight
);
$this->writeHTMLCell(
0,
0,
101.3,
270.1,
implode(
'<br>',
[
'CH-VAT: CHE-112.256.297 MWST',
'DE-VAT: DE267 19843',
'CH-Tax-ID: CHE-112.256.297',
'DE-Tax-ID: 09431/35027',
]
)
);

// Bank
$this->ImageSVG(
__DIR__ . '/../../assets/pdf/images/icon-credit-card.svg',
144.5,
270,
$iconWidth,
$iconHeight
);
$this->writeHTMLCell(
0,
0,
150.2,
270.1,
implode(
'<br>',
[
'Bank EUR: Sparkasse Hochrhein',
'IBAN: DE18 6845 2290 0077 0154 28',
'Bank CHF: Credit Suisse',
'IBAN: CH55 0484 2039 5125 5100 0',
]
)
);
}
}
25 changes: 14 additions & 11 deletions src/Pdf/SimplePdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ public function setUp(): void

public function setBadge(string $path)
{
if ($this->pdf instanceof GmbhLayoutPdf) {
$this->pdf->ImageSVG(
$path,
158,
10,
40,
40
);
}
$this->pdf->ImageSVG(
$path,
158,
10,
40,
40
);
}

public function addDate(\DateTimeInterface $date)
Expand Down Expand Up @@ -137,8 +135,13 @@ public function addHTML(string $html)
$this->pdf->writeHTML($html, false, false, true, false, '');
}

public function output(string $filename, string $destination = 'D')
public function output(string $filename, string $destination = 'I')
{
return $this->pdf->Output($filename, $destination);
}

public function __toString(): string
{
$this->pdf->Output($filename, $destination);
return (string) $this->pdf->Output('doc.pdf', 'S');
}
}
8 changes: 8 additions & 0 deletions src/Resources/config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@ _template_styleguide_component_guide:
_template_styleguide_component_text:
path: /styleguide/component/text
controller: T3G\Bundle\TemplateBundle\Controller\StyleguideController::componentText

_template_styleguide_component_pdf_gmbh:
path: /styleguide/component/pdf/gmbh
controller: T3G\Bundle\TemplateBundle\Controller\StyleguideController::componentPdfGmbH

_template_styleguide_component_pdf_assoc:
path: /styleguide/component/pdf/assoc
controller: T3G\Bundle\TemplateBundle\Controller\StyleguideController::componentPdfAssoc
4 changes: 4 additions & 0 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ services:
tags:
- name: twig.extension

T3G\Bundle\TemplateBundle\Twig\Extension\PdfExtension:
tags:
- name: twig.extension

T3G\Bundle\TemplateBundle\Twig\Extension\TemplateExtension:
tags:
- name: twig.extension
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Resources/public/entrypoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"entrypoints": {
"app": {
"css": [
"/bundles/template/app.8e7fe44b.css"
"/bundles/template/app.5b978ba3.css"
],
"js": [
"/bundles/template/app.bd0dc890.js"
"/bundles/template/app.b372be04.js"
]
},
"webfont": {
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"bundles/template/app.css": "/bundles/template/app.8e7fe44b.css",
"bundles/template/app.js": "/bundles/template/app.bd0dc890.js",
"bundles/template/app.css": "/bundles/template/app.5b978ba3.css",
"bundles/template/app.js": "/bundles/template/app.b372be04.js",
"bundles/template/webfont.css": "/bundles/template/webfont.eb64eebe.css",
"bundles/template/885.34953fcd.js": "/bundles/template/885.34953fcd.js",
"bundles/template/images/fa-solid-900.svg": "/bundles/template/images/fa-solid-900.7a8b4f13.svg",
Expand Down
12 changes: 12 additions & 0 deletions src/Resources/views/styleguide/component/pdf.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends '@Template/styleguide/layout.html.twig' %}
{% block title %}Accordion{% endblock %}

{% block body %}

{% frame %}

{{ pdf|inlinePdf }}

{% endframe %}

{% endblock %}
2 changes: 2 additions & 0 deletions src/Resources/views/styleguide/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<a href="{{ path('_template_styleguide_component_review') }}" class="list-group-item list-group-item-action">Review</a>
<a href="{{ path('_template_styleguide_component_status') }}" class="list-group-item list-group-item-action">Status</a>
<a href="{{ path('_template_styleguide_component_text') }}" class="list-group-item list-group-item-action">Text</a>
<a href="{{ path('_template_styleguide_component_pdf_gmbh') }}" class="list-group-item list-group-item-action">PDF GmbH</a>
<a href="{{ path('_template_styleguide_component_pdf_assoc') }}" class="list-group-item list-group-item-action">PDF Assoc</a>
</div>
{% endframe %}
{% endblock %}
Loading

0 comments on commit 85175b4

Please sign in to comment.