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

Replace PDF Text on Selected Pages Only

See more PDF Text Replacement Examples

Demonstrates the "pages" option, which limits the search for placeholders and labels to the given pages: "all" (the default), "first", "last", "odd", "even", or a list such as "1,3,5-9". The two-page order confirmation carries the same "Status:" label on both pages; the status is changed on page 2 only, then on both pages.

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

set pdf = Server.CreateObject("Chilkat.Pdf")
success = pdf.LoadFile("qa_data/pdf/order_confirmation.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")

'  Both pages have "Status:   Pending".  With pages "2", only page 2 is searched.
success = json.UpdateString("pages","2")
success = json.UpdateString("labels[0].label","Status:")
success = json.UpdateString("labels[0].value","Shipped")
success = pdf.TextReplace("check",json,jsonOut)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "pages 2: found on page(s) " & jsonOut.StringOf("replacements[0].pages")) & "</pre>"

'  With every page searched, the default occurrence ("first") still replaces one -- the first in reading order.
success = json.UpdateString("pages","all")
success = pdf.TextReplace("check",json,jsonOut)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "pages all, first occurrence: found on page(s) " & jsonOut.StringOf("replacements[0].pages")) & "</pre>"

'  Every occurrence on every page.
success = json.UpdateString("labels[0].occurrence","all")
success = pdf.TextReplace("apply",json,jsonOut)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "pages all, every occurrence: " & jsonOut.IntOf("replacements[0].count") & " replaced on page(s) " & jsonOut.StringOf("replacements[0].pages")) & "</pre>"

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

'  Sample output:

'  pages 2: found on page(s) 2
'  pages all, first occurrence: found on page(s) 1
'  pages all, every occurrence: 2 replaced on page(s) 1,2

%>
</body>
</html>