Skip to content

Commit

Permalink
feat: Add new examples
Browse files Browse the repository at this point in the history
  • Loading branch information
famoser committed Dec 28, 2024
1 parent c10b637 commit b337cac
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
13 changes: 13 additions & 0 deletions resources/examples/signed/sign.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# How to sign a PDF

generate certificate:
- gpgsm --generate-key (RSA, subject name CN=Florian Moser, self-signed yes)
- gpgsm --import, then paste the certificate followed by CTRL+D
- gpgsm --fingerprint, the copy ID field (e.g. `0x9C1A23DA`)

apply certificate:
- pdfsig signature.pdf signature_signed.pdf -add-signature -backend GPG -nick 0x9C1A23DA

review of other tools:
- not supported by pdftk, qpdf
- open-pdf-sign bad wrapper around Java PDFBox
Binary file added resources/examples/signed/signature.pdf
Binary file not shown.
38 changes: 38 additions & 0 deletions resources/examples/signed/signature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the famoser/pdf-generator project.
*
* (c) Florian Moser <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

include '../vendor/autoload.php';

use Famoser\PdfGenerator\Frontend\Content\Paragraph;
use Famoser\PdfGenerator\Frontend\Content\Style\DrawingStyle;
use Famoser\PdfGenerator\Frontend\Content\Style\TextStyle;
use Famoser\PdfGenerator\Frontend\Layout\ContentBlock;
use Famoser\PdfGenerator\Frontend\Layout\Flow;
use Famoser\PdfGenerator\Frontend\Layout\Parts\Row;
use Famoser\PdfGenerator\Frontend\Layout\Style\ColumnSize;
use Famoser\PdfGenerator\Frontend\Layout\Table;
use Famoser\PdfGenerator\Frontend\LinearDocument;
use Famoser\PdfGenerator\Frontend\Resource\Font;
use Famoser\PdfGenerator\IR\Document\Content\Common\Color;

$document = new LinearDocument([210, 297]);

$normalFont = Font::createFromDefault();
$normalText = new TextStyle($normalFont);

// target address
$margin = 15;
$printer = $document->createPrinter(0, $margin, $margin);
$printer->printText("Hello world", $normalText);

// TODO: sign document
$result = $document->save();
file_put_contents('signature.pdf', $result);
Binary file added resources/examples/signed/signature_signed.pdf
Binary file not shown.

0 comments on commit b337cac

Please sign in to comment.