Visual FoxPro Requires Chilkat v11.7.0+
Visual FoxPro
Why a PDF Text Replacement Is Refused: the Font Rule
See more PDF Text Replacement Examples
A PDF stores glyphs drawn with particular fonts, so new text can only be drawn when the original font can draw it. This example shows the two common refusals. A font embedded as a subset carries only the glyphs the document used: a value made of other characters is refused with the reason missingGlyph, and the report names the font and the characters it lacks. A font that is neither one of the standard 14 nor embedded (here Verdana) is refused with nonStandardUnembeddedFont, because Chilkat cannot know what a viewer will draw for it. A non-embedded Arial, Times New Roman or Courier New is treated as the standard font every viewer substitutes for it.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loPdf
LOCAL loJson
LOCAL loJsonOut
LOCAL loPdf2
LOCAL loJson2
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 quote_subset_font.pdf
* and letter_verdana.pdf
* 1. An embedded subset font: only the glyphs the document uses are in the PDF.
loPdf = CreateObject('Chilkat.Pdf')
lnSuccess = loPdf.LoadFile("qa_data/pdf/quote_subset_font.pdf")
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
CANCEL
ENDIF
loJson = CreateObject('Chilkat.JsonObject')
loJsonOut = CreateObject('Chilkat.JsonObject')
* The regular face's subset carries the characters of the quotation's text, among them the digits of
* "58341". A new number made of those digits can be drawn...
loJson.UpdateString("labels[0].label","Quote #:")
loJson.UpdateString("labels[0].value","58314")
lnSuccess = loPdf.TextReplace("check",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
CANCEL
ENDIF
? "58314: ok = " + STR(loJsonOut.BoolOf("ok"))
* ...but "Q" and "-" are not in the subset (nothing in the quotation's regular text uses them).
loJson.UpdateString("labels[0].value","Q-58341")
lnSuccess = loPdf.TextReplace("check",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
CANCEL
ENDIF
? "Q-58341: ok = " + STR(loJsonOut.BoolOf("ok"))
IF (loJsonOut.BoolOf("ok") = 0) THEN
* The problem names the font and the characters it cannot draw.
? " reason: " + loJsonOut.StringOf("problems[0].reason")
? " font: " + loJsonOut.StringOf("problems[0].font")
? " missing: " + loJsonOut.StringOf("problems[0].chars")
ENDIF
* "apply" with a problem returns false and changes nothing.
lnSuccess = loPdf.TextReplace("apply",loJson,loJsonOut)
? "apply returned " + STR(lnSuccess) + ", applied = " + STR(loJsonOut.BoolOf("applied"))
* 2. A font that is not embedded and not one of the standard 14.
loPdf2 = CreateObject('Chilkat.Pdf')
lnSuccess = loPdf2.LoadFile("qa_data/pdf/letter_verdana.pdf")
IF (lnSuccess = 0) THEN
? loPdf2.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loPdf2
CANCEL
ENDIF
loJson2 = CreateObject('Chilkat.JsonObject')
loJson2.UpdateString("labels[0].label","Account Number:")
loJson2.UpdateString("labels[0].value","0000099999")
lnSuccess = loPdf2.TextReplace("check",loJson2,loJsonOut)
IF (lnSuccess = 0) THEN
? loPdf2.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loPdf2
RELEASE loJson2
CANCEL
ENDIF
? "Verdana, not embedded: ok = " + STR(loJsonOut.BoolOf("ok")) + ", reason: " + loJsonOut.StringOf("problems[0].reason") + ", font: " + loJsonOut.StringOf("problems[0].font")
* Sample output:
* 58314: ok = true
* Q-58341: ok = false
* reason: missingGlyph
* font: AAAAAA+DejaVuSans
* missing: Q-
* apply returned false, applied = false
* Verdana, not embedded: ok = false, reason: nonStandardUnembeddedFont, font: Verdana
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loPdf2
RELEASE loJson2