TIS2023-FMFI / pracovne-cesty

Projekt TIS 2023 pre Katedru aplikovanej informatiky
The Unlicense
3 stars 0 forks source link

Otestovať FPDI na našich generovaných dokumentoch #9

Closed Mcibula closed 1 year ago

Mcibula commented 1 year ago

FPDI dokumentácia FPDF dokumentácia

Mcibula commented 1 year ago

Ño, moje zistenia:

FPDI

<?php
// Import FPDF and FPDI library obtained by Composer dependency manager
use \setasign\Fpdi\Fpdi;
require 'vendor/autoload.php'

// Load existing document
$pdf = new Fpdi();
$pdf->AddPage();
$pdf->setSourceFile('resources/Cestne_prehlasenie_ZPC.pdf');

$templateIdx = $pdf->importPage(1);
$pdf->useImportedPage($templateIdx);

// Set up the text style and use it to write a text in the first field
$pdf->SetFont('Courier');
$pdf->SetTextColor(0, 0, 255);
$pdf->SetXY(110, 60);
$pdf->Write(0, 'This is just a simple text');

// Export the final filled-out form
$pdf->Output('F', 'resources/output_fpdi.pdf');

Výstup output_fpdi.pdf

PDF Forms

FPDM

<?php
require 'vendor/autoload.php';

// Value mapping to field names / IDs
$fields = array(
    'cislo' => '12345'
);

// Load PDF form and fill it out
$pdf = new FPDM('resources/Cestne_prehlasenie_ZPC.pdf');
$pdf->Load($fields, true);
$pdf->Merge();

// Export the final form
$pdf->Output('F', 'resources/output_fpdm.pdf');

Výstup output_fpdm.pdf

php-pdftk

<?php
use mikehaertl\pdftk\Pdf;
require 'vendor/autoload.php';

// Fill form with data array
$pdf = new Pdf('resources/Cestne_prehlasenie_ZPC.pdf');

$result = $pdf->fillForm([
    'cislo' => '12345 Áäéíýúô Čďňľĺšťž Ěřů'
])
    ->flatten()
    ->replacementFont('assets/fonts/DejaVuSans.ttf')
    ->needAppearances()
    ->saveAs('resources/output_pdftk.pdf');

// Check for errors
if ($result === false) {
    echo $pdf->getError();
}

Výstup output_pdftk.pdf

Mcibula commented 1 year ago

Rozhodli sme sa pre php-pdftk