Search code examples
phppdfpdflib

Adding a "watermark" on a PDF with PDFlib


sorry for not providing any sourcecode. So I am having PDF files (already made) and a website where I offer them for download (I am oversimplifying here) anyway, what I want to do is, when someone clicks on them, I want with PHP and PDFlib insert a watermark into them with the date and the time. How is that possible?

I have searched the web, but I did not find any sample code and since I have never used PDFLib in my life, I am not even sure where to start.

Just point me into the direction or ignore, no need to give me negative points :-)


Solution

  • check out http://www.pdflib.com/pdflib-cookbook/pdf-import/stamp-pages/ which place a stamp across the page to all imported PDF pages.

    For you case, you just have to adjust the

    p.fit_textline("PRELIMINARY", 50, 50, "font=" + font +
       " fontsize=1 textrendering=1 boxsize={500 700} stamp=ul2lr" +
       " strokecolor=red strokewidth=2");
    

    with the data and the position you need. For details about the fit_textline() options, check out the PDFlib API reference.