Applying watermarks on pdf files when users try to download the files

后端 未结 4 724
悲哀的现实
悲哀的现实 2020-12-28 21:46

The solutions for my school\'s assignments all have waterstamps on the PDFs with our username on it.

I was wondering if you guys know how to do something like that u

4条回答
  •  梦毁少年i
    2020-12-28 22:27

    Although there are several very good PDF libs for PHP, if I were writing such a program I'd just shell out to run pdftk but you' still need to generate your watermark.

    $tempfile=tempnam();
    system("pdftk input_file.pdf background watermark.pdf output $tempfile dont_ask", $errcode);
    if (!$errcode && $ih=fopen($tempfile, 'r')) {
        header('Content-Type: application/pdf');
        fpassthru($ih);
        fclose($ih);
    } else {
        print "Whoops";
    }
    unlink($tempfile);
    

提交回复
热议问题