Classic ASP Requires Chilkat v11.7.0+
Classic ASP
Watermark Only Some of a PDF's Pages
See more PDF Watermark Examples
Demonstrates choosing the pages to stamp. "pages" takes all (the default), first, last, odd, even, or a list of 1-based pages and ranges such as 1,3,5-9,12- where a trailing dash means "to the end". "excludePages" takes the same syntax and is applied afterwards, which is how you say "every page except the cover". The result reports the pages the watermark actually landed on.Chilkat Classic ASP Downloads
<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
Response.Write "<pre>" & Server.HTMLEncode( "pages in the document: " & pdf.NumPages) & "</pre>"
set json = Server.CreateObject("Chilkat.JsonObject")
set jsonOut = Server.CreateObject("Chilkat.JsonObject")
success = json.UpdateString("type","text")
success = json.UpdateString("text","INTERNAL")
success = json.UpdateString("id","internal")
' Every page except the first.
success = json.UpdateString("pages","all")
success = json.UpdateString("excludePages","1")
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( "every page but the cover: " & jsonOut.StringOf("pages")) & "</pre>"
' A list of pages and ranges, on a second copy of the document.
set pdf2 = Server.CreateObject("Chilkat.Pdf")
success = pdf2.LoadFile("qa_data/pdf/four_pages.pdf")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf2.LastErrorText) & "</pre>"
Response.End
End If
set json2 = Server.CreateObject("Chilkat.JsonObject")
success = json2.UpdateString("type","text")
success = json2.UpdateString("text","APPENDIX")
success = json2.UpdateString("id","appendix")
success = json2.UpdateString("pages","2,4-")
success = pdf2.Watermark("add",json2,jsonOut)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf2.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "page 2 and 4 onwards: " & jsonOut.StringOf("pages")) & "</pre>"
success = pdf.WriteFile("qa_output/four_pages_internal.pdf")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
Response.End
End If
' Sample output:
' pages in the document: 4
' every page but the cover: 2-4
' page 2 and 4 onwards: 2,4
%>
</body>
</html>