PureBasic Requires Chilkat v11.7.0+
PureBasic
Exclude Rotated Margin Text from PDF Extraction
See more PDF Text Extraction Examples
Demonstrates the "rotatedText" filter. Text that is not aligned with the page, such as a vertical "CONFIDENTIAL" label in the margin, is included by default (after the upright text) and flagged in the quality report; "exclude" leaves it out.Chilkat PureBasic Downloads
IncludeFile "CkPdf.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
success.i = 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 rotated_margin.pdf
pdf.i = CkPdf::ckCreate()
If pdf.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkPdf::ckLoadFile(pdf,"qa_data/pdf/rotated_margin.pdf")
If success = 0
Debug CkPdf::ckLastErrorText(pdf)
CkPdf::ckDispose(pdf)
ProcedureReturn
EndIf
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
jsonOut.i = CkJsonObject::ckCreate()
If jsonOut.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; The page has a paragraph and, rotated 90 degrees along the left margin, "CONFIDENTIAL - DRAFT - NOT FOR DISTRIBUTION".
success = CkPdf::ckExtractText(pdf,"text",json,jsonOut)
If success = 0
Debug CkPdf::ckLastErrorText(pdf)
CkPdf::ckDispose(pdf)
CkJsonObject::ckDispose(json)
CkJsonObject::ckDispose(jsonOut)
ProcedureReturn
EndIf
Debug "---- default (rotated text included) ----"
Debug CkJsonObject::ckStringOf(jsonOut,"text")
Debug "issue: " + CkJsonObject::ckStringOf(jsonOut,"quality.pages[0].issues[0].code")
CkJsonObject::ckUpdateString(json,"rotatedText","exclude")
success = CkPdf::ckExtractText(pdf,"text",json,jsonOut)
If success = 0
Debug CkPdf::ckLastErrorText(pdf)
CkPdf::ckDispose(pdf)
CkJsonObject::ckDispose(json)
CkJsonObject::ckDispose(jsonOut)
ProcedureReturn
EndIf
Debug "---- rotatedText: exclude ----"
Debug CkJsonObject::ckStringOf(jsonOut,"text")
; Sample output:
; ---- default (rotated text included) ----
; Restoration Budget Summary
;
; Spending for the season came in slightly under the approved budget, largely because the parapet work took less time than expected. The lens loan carries no fee, but the society is responsible for insurance and for the specialist cleaning.
;
; CONFIDENTIAL - DRAFT - NOT FOR DISTRIBUTION
; issue: rotatedText
; ---- rotatedText: exclude ----
; Restoration Budget Summary
;
; Spending for the season came in slightly under the approved budget, largely because the parapet work took less time than expected. The lens loan carries no fee, but the society is responsible for insurance and for the specialist cleaning.
CkPdf::ckDispose(pdf)
CkJsonObject::ckDispose(json)
CkJsonObject::ckDispose(jsonOut)
ProcedureReturn
EndProcedure