Classic ASP Requires Chilkat v11.7.0+
Classic ASP
Extract the OCR Text Layer of a Scanned PDF
See more PDF Text Extraction Examples
Demonstrates a scanned page that carries an invisible OCR text layer over the page image. The quality report identifies the page's textSource as "ocrLayer". The "invisibleText" filter is "auto" by default, which uses the invisible text only on pages that have no visible text; "exclude" ignores 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 (a page image with an invisible text layer, as an OCR program produces) is available at scanned_with_ocr.pdf
set pdf = Server.CreateObject("Chilkat.Pdf")
success = pdf.LoadFile("qa_data/pdf/scanned_with_ocr.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 page is a picture of a handwritten log with the OCR'd words drawn invisibly over it.
' "auto" (the default) includes invisible text exactly in this case: on a page with no visible text.
success = pdf.ExtractText("text",json,jsonOut)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "textSource: " & jsonOut.StringOf("quality.pages[0].textSource")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "rating: " & jsonOut.StringOf("quality.pages[0].rating")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( jsonOut.StringOf("text")) & "</pre>"
' The quality report flags the page, because OCR text is only as good as the OCR was.
Response.Write "<pre>" & Server.HTMLEncode( "issue: " & jsonOut.StringOf("quality.pages[0].issues[0].code") & " - " & jsonOut.StringOf("quality.pages[0].issues[0].message")) & "</pre>"
' "exclude" ignores invisible text altogether: the page then has no text at all.
success = json.UpdateString("invisibleText","exclude")
success = pdf.ExtractText("text",json,jsonOut)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "With invisibleText excluded, textSource: " & jsonOut.StringOf("quality.pages[0].textSource") & ", text: [" & jsonOut.StringOf("text") _
& "]") & "</pre>"
' Sample output:
' textSource: ocrLayer
' rating: good
' Keeper's Log, 12 October 1902
'
' Wind north-west, fresh. Lamp lit at 5.40 p.m. and burning well all night.
'
' Schooner Mary Ann passed inbound at 9 p.m. showing proper lights.
'
' Oil on hand: forty-one gallons. Cleaned the lens at dawn.
' issue: ocrLayer - The text is an invisible OCR layer over an image
' With invisibleText excluded, textSource: ocrLayer, text: []
%>
</body>
</html>