Classic ASP Requires Chilkat v11.7.0+
Classic ASP
What PDF Text Replacement Does Not Change: Metadata, Links, Form Fields
See more PDF Text Replacement Examples
TextReplace changes the page content only. A placeholder that also appears in the document's metadata (the Title, Author, Subject, Keywords, Creator or Producer), in a link's target URL, or in a form field's value is left as it is and reported in "notReplaced" with "where" saying which. The invoice template's title is "Invoice for {{customer}}" and its "View this invoice online" link points at a URL that holds {{customer}}.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 invoice_template.pdf
set pdf = Server.CreateObject("Chilkat.Pdf")
success = pdf.LoadFile("qa_data/pdf/invoice_template.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("placeholders.customer","Acme Corp")
' (The other placeholders are left as they are for this example.)
success = json.UpdateString("unusedPlaceholders","keep")
set jsonOut = Server.CreateObject("Chilkat.JsonObject")
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( "In the page content, customer was replaced " & jsonOut.IntOf("replacements[0].count") & " times.") & "</pre>"
' Where else the placeholder occurs, untouched:
i = 0
count_i = jsonOut.SizeOfArray("notReplaced")
Do While i < count_i
jsonOut.I = i
Response.Write "<pre>" & Server.HTMLEncode( "not replaced: {{" & jsonOut.StringOf("notReplaced[i].field") & "}} in " & jsonOut.StringOf("notReplaced[i].where")) & "</pre>"
i = i + 1
Loop
success = pdf.WriteFile("qa_output/invoice_customer.pdf")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
Response.End
End If
' Sample output:
' In the page content, customer was replaced 2 times.
' not replaced: {{customer}} in metadata
' not replaced: {{customer}} in linkTarget
%>
</body>
</html>