Sample code for 30+ languages & platforms
Classic ASP Requires Chilkat v11.7.0+

Add a CONFIDENTIAL Watermark to Every Page of a PDF

See more PDF Watermark Examples

Demonstrates the simplest watermark: a line of text across every page. "rotation" set to diagonal runs the text from the bottom-left corner to the top-right, computed for each page size, and "scale" with fit page sizes it to fill 80 percent of the page. The watermark is stored as a marked artifact by default, which means viewers show it, text extraction leaves it out, and it can be found and removed again later. Nothing is written until WriteFile is called.

Chilkat Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

'  This example requires the Chilkat API to have been previously unlocked.
'  See Global Unlock Sample for sample code.

'  The PDF used in this example is available at long_report.pdf

set pdf = Server.CreateObject("Chilkat.Pdf")
success = pdf.LoadFile("qa_data/pdf/long_report.pdf")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
    Response.End
End If

set json = Server.CreateObject("Chilkat.JsonObject")
success = json.UpdateString("type","text")
success = json.UpdateString("text","CONFIDENTIAL")

'  An id of your own choosing, so that the watermark can be found and removed later.  One is
'  generated when you do not give one.
success = json.UpdateString("id","confidential")

success = json.UpdateString("color","#C00000")
success = json.UpdateNumber("opacity","0.25")
success = json.UpdateString("rotation","diagonal")
success = json.UpdateString("scale.fit","page")
success = json.UpdateNumber("scale.fitPercent","80")

set jsonOut = Server.CreateObject("Chilkat.JsonObject")
success = pdf.Watermark("add",json,jsonOut)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
    Response.End
End If

'  The id, and the pages it was stamped on.  "pages" defaults to all.
Response.Write "<pre>" & Server.HTMLEncode( "id: " & jsonOut.StringOf("id")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "pages: " & jsonOut.StringOf("pages")) & "</pre>"

success = pdf.WriteFile("qa_output/report_confidential.pdf")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
    Response.End
End If

'  Sample output:

'  id: confidential
'  pages: 1-3

%>
</body>
</html>