Classic ASP Requires Chilkat v11.7.0+
Classic ASP
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 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 quote_subset_font.pdf
' and letter_verdana.pdf
' 1. An embedded subset font: only the glyphs the document uses are in the PDF.
set pdf = Server.CreateObject("Chilkat.Pdf")
success = pdf.LoadFile("qa_data/pdf/quote_subset_font.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")
' 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...
success = json.UpdateString("labels[0].label","Quote #:")
success = json.UpdateString("labels[0].value","58314")
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( "58314: ok = " & jsonOut.BoolOf("ok")) & "</pre>"
' ...but "Q" and "-" are not in the subset (nothing in the quotation's regular text uses them).
success = json.UpdateString("labels[0].value","Q-58341")
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( "Q-58341: ok = " & jsonOut.BoolOf("ok")) & "</pre>"
If (jsonOut.BoolOf("ok") = 0) Then
' The problem names the font and the characters it cannot draw.
Response.Write "<pre>" & Server.HTMLEncode( " reason: " & jsonOut.StringOf("problems[0].reason")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( " font: " & jsonOut.StringOf("problems[0].font")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( " missing: " & jsonOut.StringOf("problems[0].chars")) & "</pre>"
End If
' "apply" with a problem returns false and changes nothing.
success = pdf.TextReplace("apply",json,jsonOut)
Response.Write "<pre>" & Server.HTMLEncode( "apply returned " & success & ", applied = " & jsonOut.BoolOf("applied")) & "</pre>"
' 2. A font that is not embedded and not one of the standard 14.
set pdf2 = Server.CreateObject("Chilkat.Pdf")
success = pdf2.LoadFile("qa_data/pdf/letter_verdana.pdf")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf2.LastErrorText) & "</pre>"
Response.End
End If
set json2 = Server.CreateObject("Chilkat.JsonObject")
success = json2.UpdateString("labels[0].label","Account Number:")
success = json2.UpdateString("labels[0].value","0000099999")
success = pdf2.TextReplace("check",json2,jsonOut)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf2.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Verdana, not embedded: ok = " & jsonOut.BoolOf("ok") & ", reason: " & jsonOut.StringOf("problems[0].reason") & ", font: " _
& jsonOut.StringOf("problems[0].font")) & "</pre>"
' 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
%>
</body>
</html>