Classic ASP Requires Chilkat v11.7.0+
Classic ASP
Get a PDF Field Value by its Label (Value to the Right)
See more PDF Text Extraction Examples
Demonstrates the "label" option, which captures the text that belongs to a caption such as "Invoice Number:" without needing coordinates. With labelValue "right", the value is the rest of the label's line. Label matching ignores case, extra spaces and a trailing colon.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 invoice used in this example is available at invoice_labels.pdf
set pdf = Server.CreateObject("Chilkat.Pdf")
success = pdf.LoadFile("qa_data/pdf/invoice_labels.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 invoice has lines such as "Invoice Number: INV-2026-0412".
' The label option restricts the "text" operation to the text belonging to the label.
success = json.UpdateString("label","Invoice Number")
' "right" means the value is the rest of the label's line.
' (The default, "auto", uses the rest of the line if there is text there, otherwise the block below.)
success = json.UpdateString("labelValue","right")
success = pdf.ExtractText("text",json,jsonOut)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
Response.End
End If
' The value is returned as the text.
Response.Write "<pre>" & Server.HTMLEncode( "Invoice Number: " & jsonOut.StringOf("text")) & "</pre>"
' The labelMatches array tells where the label was found and how it appeared in the PDF.
Response.Write "<pre>" & Server.HTMLEncode( "Found on page " & jsonOut.IntOf("labelMatches[0].page") & " as """ & jsonOut.StringOf("labelMatches[0].label") & """") & "</pre>"
' Matching ignores case and the trailing colon, so these all work:
success = json.UpdateString("label","CUSTOMER:")
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( "Customer: " & jsonOut.StringOf("text")) & "</pre>"
success = json.UpdateString("label","due date")
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( "Due Date: " & jsonOut.StringOf("text")) & "</pre>"
' The totals at the foot of the invoice are right-aligned labels with the amount beside them.
success = json.UpdateString("label","Total Due")
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( "Total Due: " & jsonOut.StringOf("text")) & "</pre>"
' A label that is not found is not an error. The text is empty, labelMatches is empty,
' and the quality report has an issue with the code "labelNotFound".
success = json.UpdateString("label","Tracking Number")
success = pdf.ExtractText("text",json,jsonOut)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
Response.End
End If
If (jsonOut.SizeOfArray("labelMatches") = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( "Tracking Number: (not found) " & jsonOut.StringOf("quality.pages[0].issues[0].code")) & "</pre>"
End If
' Sample output:
' Invoice Number: INV-2026-0412
' Found on page 1 as "Invoice Number:"
' Customer: Northwind Traders
' Due Date: April 13, 2026
' Total Due: $1,234.53
' Tracking Number: (not found) labelNotFound
%>
</body>
</html>