DataFlex Requires Chilkat v11.7.0+
DataFlex
Code Blocks and Code Spans in PDF to Markdown
See more PDF Text Extraction Examples
Demonstrates how monospaced text is converted by the "markdown" operation: a monospaced block becomes a fenced code block and a monospaced run inside a sentence becomes a code span. Set "code" to false to treat it as ordinary text.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoPdf
Variant vJson
Handle hoJson
Variant vJsonOut
Handle hoJsonOut
String sTemp1
Move False To iSuccess
// 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 code_block.pdf
Get Create (RefClass(cComChilkatPdf)) To hoPdf
If (Not(IsComObjectCreated(hoPdf))) Begin
Send CreateComObject of hoPdf
End
Get ComLoadFile Of hoPdf "qa_data/pdf/code_block.pdf" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
If (Not(IsComObjectCreated(hoJsonOut))) Begin
Send CreateComObject of hoJsonOut
End
Get pvComObject of hoJson to vJson
Get pvComObject of hoJsonOut to vJsonOut
Get ComExtractText Of hoPdf "markdown" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "---- default (code: true) ----"
Get ComStringOf Of hoJsonOut "markdown" To sTemp1
Showln sTemp1
Get ComUpdateBool Of hoJson "code" False To iSuccess
Get pvComObject of hoJson to vJson
Get pvComObject of hoJsonOut to vJsonOut
Get ComExtractText Of hoPdf "markdown" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "---- code: false ----"
Get ComStringOf Of hoJsonOut "markdown" To sTemp1
Showln sTemp1
// Sample output:
// ---- default (code: true) ----
// <!-- page 1 -->
//
// # Extracting Text
//
// Load the PDF and call `ExtractText` with the operation and an options object. The result is returned as JSON:
//
// ```
// new Pdf pdf;
// success = pdf.LoadFile("report.pdf");
// new JsonObject json;
// new JsonObject jsonOut;
// success = pdf.ExtractText("text",json,jsonOut);
// println jsonOut.StringOf("text");
// ```
//
// An empty options object extracts every page with the default clean-up. Set `pages` to limit the extraction.
// ---- code: false ----
// <!-- page 1 -->
//
// # Extracting Text
//
// Load the PDF and call ExtractText with the operation and an options object. The result is returned as JSON:
//
// new Pdf pdf; success = pdf.LoadFile("report.pdf"); new JsonObject json; new JsonObject jsonOut; success = pdf.ExtractText("text",json,jsonOut); println jsonOut.StringOf("text");
//
// An empty options object extracts every page with the default clean-up. Set pages to limit the extraction.
End_Procedure