How can I edit an existing pdf using pdftk?

I hvae searched on google, stackoverflow and ChatGPT. I can’t find clear instructions on how to edit existing text or fill out a text field. I have checked the documentation and didn’t find anything that was really useful to me. Maybe I didn’t see something?

Anyway, I’m trying to fill out a text field in a pdf (Replacing a piece of text would also be a solution).

This is the code I have atm:

<?php

    $inputPdf = 'Test.pdf';
    $outputPdf = 'TestFertig.pdf';

    $FormFieldData = [
        'tbDocNum' => '123456',
        'tbTest' => 'Keine Ahnung alda',
    ];

    $pdftkCommand = "pdftk $inputPdf fill_form $inputPdf output $outputPdf";

    foreach ($FormFieldData as $fieldname => $fieldValue) {
        $pdftkCommand .= "flatten_fields output - ";
        $pdftkCommand .= "xfdf - < <(echo '<?xml version="1.0" encoding="UTF-8" ?><fields><field name="$fieldName"><value>$fieldValue</value></field></fields>') ";
    }

    exec($pdftkCommand);

    header('Content-type: application/pdf');
    readfile($outputPdf);

?>

I hope this is clear enough and thank you in advance.