Classic ASP Requires Chilkat v11.7.0+
Classic ASP
Extract PDF Text to a StringBuilder and Save to a File
See more PDF Text Extraction Examples
Demonstrates ExtractTextSb, which writes the extracted text to a StringBuilder instead of returning it as a JSON string. Use it for large documents. The JSON output still receives the quality report.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 long_report.pdf
set pdf = Server.CreateObject("Chilkat.Pdf")
success = pdf.LoadFile("qa_data/pdf/long_report.pdf")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Number of pages: " & pdf.NumPages) & "</pre>"
' ExtractTextSb takes the same operation and options as ExtractText, but the text
' goes to a StringBuilder. This avoids building a very large JSON string for
' documents with many pages.
set json = Server.CreateObject("Chilkat.JsonObject")
set sbText = Server.CreateObject("Chilkat.StringBuilder")
set jsonOut = Server.CreateObject("Chilkat.JsonObject")
success = pdf.ExtractTextSb("text",json,sbText,jsonOut)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Extracted " & sbText.Length & " characters.") & "</pre>"
' Save the text to a file.
success = sbText.WriteFile("qa_output/long_report.txt","utf-8",0)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( sbText.LastErrorText) & "</pre>"
Response.End
End If
' The JSON output does not contain the text, but it still has the quality report.
Response.Write "<pre>" & Server.HTMLEncode( "Quality: " & jsonOut.StringOf("quality.rating")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Pages with no text (need OCR): [" & jsonOut.StringOf("quality.pagesNeedingOcr") & "]") & "</pre>"
' Sample output:
' Number of pages: 3
' Extracted 4522 characters.
' Quality: good
' Pages with no text (need OCR): []
%>
</body>
</html>