Classic ASP Requires Chilkat v11.7.0+
Classic ASP
A PDF Label That Is Not on the Page: notFound or Ignore
See more PDF Text Replacement Examples
Demonstrates the "unmatchedValues" option. A label or placeholder given a value but not found on the selected pages is a problem with the reason notFound, which stops "apply", because a missing label usually means the wrong document or a typo in the label. With unmatchedValues "ignore" such a value is skipped and the rest is applied -- the right choice when one set of values serves several document layouts.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_labels.pdf
set pdf = Server.CreateObject("Chilkat.Pdf")
success = pdf.LoadFile("qa_data/pdf/invoice_labels.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")
' "Tracking Number:" is not on this invoice.
success = json.UpdateString("labels[0].label","Invoice Number:")
success = json.UpdateString("labels[0].value","INV-2026-0500")
success = json.UpdateString("labels[1].label","Tracking Number:")
success = json.UpdateString("labels[1].value","1Z999AA10123456784")
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( "default: ok = " & jsonOut.BoolOf("ok") & ", problem: """ & jsonOut.StringOf("problems[0].label") & """ " & jsonOut.StringOf("problems[0].reason")) & "</pre>"
' With "ignore", the label that is not there is skipped.
success = json.UpdateString("unmatchedValues","ignore")
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( "ignore: applied = " & jsonOut.BoolOf("applied") & ", replacements: " & jsonOut.SizeOfArray("replacements")) & "</pre>"
success = pdf.WriteFile("qa_output/invoice_renumbered.pdf")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
Response.End
End If
' Sample output:
' default: ok = false, problem: "Tracking Number:" notFound
' ignore: applied = true, replacements: 1
%>
</body>
</html>