当用户尝试下载pdf文件时将水印应用于pdf文件 [英] Applying watermarks on pdf files when users try to download the files

查看:90
本文介绍了当用户尝试下载pdf文件时将水印应用于pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学校的作业解决方案都在PDF上印有水印,并在上面印有我们的用户名.

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

我想知道你们是否知道如何使用PHP做类似的事情?他们在下载过程之前运行脚本吗?

I was wondering if you guys know how to do something like that using PHP? Do they run a script prior to the download process?

谢谢.

推荐答案

尽管有一些非常好的PHP PDF库,但是如果我正在编写这样的程序,我将直接运行

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);

这篇关于当用户尝试下载pdf文件时将水印应用于pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆