Sample code for 30+ languages & platforms
PureBasic Requires Chilkat v11.7.0+

Rejoin Words Hyphenated at Line Ends

See more PDF Text Extraction Examples

Demonstrates the "dehyphenate" clean-up option (true by default). A word broken at the end of a line ("docu-" / "ment") is rejoined, while a hyphen that belongs to the word ("self-service") is kept. Set the option to false to keep the lines exactly as printed.

Chilkat PureBasic Downloads

PureBasic
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 hyphenated.pdf

    pdf.i = CkPdf::ckCreate()
    If pdf.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkPdf::ckLoadFile(pdf,"qa_data/pdf/hyphenated.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 paragraph breaks "document", "self-service", "underlying" and "re-issued" at line ends.
    ;  The default rejoins them.  "self-service" keeps its hyphen because the word appears with it,
    ;  unbroken, elsewhere on the page; "re-issued" appears nowhere else, so it becomes "reissued".
    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 (dehyphenate: true) ----"
    Debug CkJsonObject::ckStringOf(jsonOut,"text")

    CkJsonObject::ckUpdateBool(json,"dehyphenate",0)
    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 "---- dehyphenate: false ----"
    Debug CkJsonObject::ckStringOf(jsonOut,"text")

    ;  Sample output:

    ;  ---- default (dehyphenate: true) ----
    ;  Self-Service Kiosk Notes
    ;  
    ;  The new self-service kiosk in the lobby prints a visitor badge from the document number on the reservation. Staff should direct first-time visitors to the self-service kiosk rather than the desk, and should keep the paper tray topped up. The underlying software restarts itself overnight; a badge that fails to print is reissued at the desk on request.
    ;  ---- dehyphenate: false ----
    ;  Self-Service Kiosk Notes
    ;  
    ;  The new self-service kiosk in the lobby prints a visitor badge from the docu- ment number on the reservation. Staff should direct first-time visitors to the self- service kiosk rather than the desk, and should keep the paper tray topped up. The under- lying software restarts itself overnight; a badge that fails to print is re- issued at the desk on request.


    CkPdf::ckDispose(pdf)
    CkJsonObject::ckDispose(json)
    CkJsonObject::ckDispose(jsonOut)


    ProcedureReturn
EndProcedure