$line) { if (strpos($line, 'InfoValue:') === 0) { $output[$index] = 'InfoValue:'; } } // write the updated metadata to a file $metadataFile = tempnam(sys_get_temp_dir(), 'pdf-meta-'); file_put_contents($metadataFile, implode("\n", $output)); // create a new PDF using the updated metadata $tmpFile = tempnam(sys_get_temp_dir(), 'pdf-tmp-'); $command = sprintf('pdftk %s update_info %s output %s', escapeshellarg($file), escapeshellarg($metadataFile), escapeshellarg($tmpFile)); $output = array(); $return = null; exec($command, $output, $return); if ($return) { throw new Exception('There was an error writing metadata to the PDF file'); } // clean up the temporary files rename($tmpFile, $file); unlink($metadataFile);