Visual FoxPro Requires Chilkat v11.7.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loPdf
LOCAL loJson
LOCAL loJsonOut
lnSuccess = 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
loPdf = CreateObject('Chilkat.Pdf')
lnSuccess = loPdf.LoadFile("qa_data/pdf/invoice_labels.pdf")
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
CANCEL
ENDIF
loJson = CreateObject('Chilkat.JsonObject')
loJsonOut = CreateObject('Chilkat.JsonObject')
* "Tracking Number:" is not on this invoice.
loJson.UpdateString("labels[0].label","Invoice Number:")
loJson.UpdateString("labels[0].value","INV-2026-0500")
loJson.UpdateString("labels[1].label","Tracking Number:")
loJson.UpdateString("labels[1].value","1Z999AA10123456784")
lnSuccess = loPdf.TextReplace("check",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
CANCEL
ENDIF
? "default: ok = " + STR(loJsonOut.BoolOf("ok")) + ', problem: "' + loJsonOut.StringOf("problems[0].label") + '" ' + loJsonOut.StringOf("problems[0].reason")
* With "ignore", the label that is not there is skipped.
loJson.UpdateString("unmatchedValues","ignore")
lnSuccess = loPdf.TextReplace("apply",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
CANCEL
ENDIF
? "ignore: applied = " + STR(loJsonOut.BoolOf("applied")) + ", replacements: " + STR(loJsonOut.SizeOfArray("replacements"))
lnSuccess = loPdf.WriteFile("qa_output/invoice_renumbered.pdf")
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
CANCEL
ENDIF
* Sample output:
* default: ok = false, problem: "Tracking Number:" notFound
* ignore: applied = true, replacements: 1
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut