hanneskod / libmergepdf

PHP library for merging multiple PDFs
386 stars 77 forks source link

TcpdiDriver with PDF field #66

Open alexis-riot opened 2 years ago

alexis-riot commented 2 years ago

Hello,

I have a fillable PDF, when I save it with some fields filled, TCPDI Driver can't display they fields. You can simply reproduce this with the following PDF: example.pdf

firstname and lastname is filled (Toto / Rico). But if you pass it through TCPDI Driver (or FPDI), these data is not displayed.

Do you know how can I use TCPDI Driver with fillable PDF?

Thanks you.

alexis-riot commented 2 years ago

https://www.setasign.com/products/setapdf-merger/demos/assistant-demo/#p-300 This example should work for merging 2 PDF and conserve fields states.

In the code, we can see:


// merge all files
$document = $merger->merge();

// if form fields were merged, set a flag that introduce the
// reader application to re-render the form field appearances.
$acroForm = $document->getCatalog()->getAcroForm();
$fields = $acroForm->getFieldsArray();
if ($fields !== false && count($fields) > 0) {
    $acroForm->setNeedAppearances();
}
kaystrobach commented 2 years ago

please create a MR and possibly a testcase, i will take a look into it then

alexis-riot commented 2 years ago

please create a MR and possibly a testcase, i will take a look into it then

MR with what content ? I have no solution on your library for fix this problem about form fields.

kaystrobach commented 2 years ago

isn't that these 4 loc?

$acroForm = $document->getCatalog()->getAcroForm();
$fields = $acroForm->getFieldsArray();
if ($fields !== false && count($fields) > 0) {
    $acroForm->setNeedAppearances();
}

Seemed to me, that it's enough to put it in the end of the merge function - ?

alexis-riot commented 2 years ago

isn't that these 4 loc?

$acroForm = $document->getCatalog()->getAcroForm();
$fields = $acroForm->getFieldsArray();
if ($fields !== false && count($fields) > 0) {
    $acroForm->setNeedAppearances();
}

Seemed to me, that it's enough to put it in the end of the merge function - ?

I have take this code from SetaPDF-Merger. And your library is using TCPDI/FPDI Driver.

alexis-riot commented 2 years ago

isn't that these 4 loc?

$acroForm = $document->getCatalog()->getAcroForm();
$fields = $acroForm->getFieldsArray();
if ($fields !== false && count($fields) > 0) {
    $acroForm->setNeedAppearances();
}

Seemed to me, that it's enough to put it in the end of the merge function - ?

Because in your example, how you get $document ? On the example of SetaPDF, the document is returned by the merge() method. But in the case of your library, the merge method return the raw PDF merged and not the document.

alexis-riot commented 2 years ago

@kaystrobach Hello, any news?