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

Place and Size a PDF Watermark: Alignment, Margins and Fitting

See more PDF Watermark Examples

Demonstrates where the stamp goes and how large it is drawn. position.align picks one of nine spots, position.margin insets it from the page edges, and position.offsetX and offsetY nudge it from there. For the size, scale.factor multiplies the natural size, scale.fit fits the rotated stamp inside the margin box (none, page, width or height) with scale.fitPercent saying how much of that box to fill, and scale.maxWidth and maxHeight cap the result. The units member applies to all of the measurements except font size, which is always in points.

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 four_pages.pdf

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

set json = Server.CreateObject("Chilkat.JsonObject")
set jsonOut = Server.CreateObject("Chilkat.JsonObject")

'  A banner across the top, inset three quarters of an inch, filling 60% of the width.
success = json.UpdateString("type","text")
success = json.UpdateString("text","REVIEW COPY")
success = json.UpdateString("id","banner")
success = json.UpdateString("units","in")
success = json.UpdateString("position.align","top")
success = json.UpdateNumber("position.margin","0.75")
success = json.UpdateString("scale.fit","width")
success = json.UpdateNumber("scale.fitPercent","60")
success = json.UpdateString("color","#1F4E79")
success = pdf.Watermark("add",json,jsonOut)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "banner pages: " & jsonOut.StringOf("pages")) & "</pre>"

'  A second stamp in the bottom-left corner, nudged a quarter inch to the right and up, with its
'  size capped rather than fitted.
set json2 = Server.CreateObject("Chilkat.JsonObject")
success = json2.UpdateString("type","text")
success = json2.UpdateString("text","Not for distribution")
success = json2.UpdateString("id","footnote")
success = json2.UpdateString("units","in")
success = json2.UpdateString("position.align","bottomLeft")
success = json2.UpdateNumber("position.margin","0.5")
success = json2.UpdateNumber("position.offsetX","0.25")
success = json2.UpdateNumber("position.offsetY","-0.25")
success = json2.UpdateNumber("font.size","9")
success = json2.UpdateNumber("scale.maxWidth","3.0")
success = pdf.Watermark("add",json2,jsonOut)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "footnote pages: " & jsonOut.StringOf("pages")) & "</pre>"

'  Each call adds one watermark, so a banner plus a note is two calls.
success = pdf.WriteFile("qa_output/four_pages_placed.pdf")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
    Response.End
End If

'  Sample output:

'  banner pages: 1-4
'  footnote pages: 1-4

%>
</body>
</html>