DataFlex Requires Chilkat v11.7.0+
DataFlex
PDF to Markdown Options: Page Breaks, Images, Tables, Emphasis, Heading Levels
See more PDF Text Extraction Examples
Demonstrates the options of the "markdown" operation: pageBreaks (comment, rule or none), images (placeholder or none), tables (ruled or none), emphasis, and maxHeadingLevel.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoPdf
Variant vJson
Handle hoJson
Variant vSbMarkdown
Handle hoSbMarkdown
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 two-page PDF used in this example is available at markdown_options.pdf
Get Create (RefClass(cComChilkatPdf)) To hoPdf
If (Not(IsComObjectCreated(hoPdf))) Begin
Send CreateComObject of hoPdf
End
Get ComLoadFile Of hoPdf "qa_data/pdf/markdown_options.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(cComChilkatStringBuilder)) To hoSbMarkdown
If (Not(IsComObjectCreated(hoSbMarkdown))) Begin
Send CreateComObject of hoSbMarkdown
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
If (Not(IsComObjectCreated(hoJsonOut))) Begin
Send CreateComObject of hoJsonOut
End
// First with the default options.
Get pvComObject of hoJson to vJson
Get pvComObject of hoSbMarkdown to vSbMarkdown
Get pvComObject of hoJsonOut to vJsonOut
Get ComExtractTextSb Of hoPdf "markdown" vJson vSbMarkdown vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "---- default options ----"
Get ComGetAsString Of hoSbMarkdown To sTemp1
Showln sTemp1
// Now change the options:
// pageBreaks: "comment" (the default) separates pages with <!-- page N -->,
// "rule" separates them with a horizontal rule (---), and "none" runs the pages together.
Get ComUpdateString Of hoJson "pageBreaks" "rule" To iSuccess
// images: "placeholder" (the default) marks where each image sits with ;
// "none" leaves images out.
Get ComUpdateString Of hoJson "images" "none" To iSuccess
// tables: "ruled" (the default) converts tables that have drawn cell borders into Markdown tables;
// "none" returns their cells as plain text.
Get ComUpdateString Of hoJson "tables" "none" To iSuccess
// emphasis: false leaves out the ** and * markers for bold and italic.
Get ComUpdateBool Of hoJson "emphasis" False To iSuccess
// maxHeadingLevel: inferred headings deeper than this level are folded into this level.
// The PDF has three heading levels; with maxHeadingLevel 2 the third level becomes ##.
Get ComUpdateInt Of hoJson "maxHeadingLevel" 2 To iSuccess
Send ComClear To hoSbMarkdown
Get pvComObject of hoJson to vJson
Get pvComObject of hoSbMarkdown to vSbMarkdown
Get pvComObject of hoJsonOut to vJsonOut
Get ComExtractTextSb Of hoPdf "markdown" vJson vSbMarkdown vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "---- custom options ----"
Get ComGetAsString Of hoSbMarkdown To sTemp1
Showln sTemp1
// Sample output:
// ---- default options ----
// <!-- page 1 -->
//
// # Community Garden Handbook
//
// ## Plots
//
// ### Plot Sizes
//
// Plots come in two sizes. A **full plot** is twenty feet by ten feet; a **half plot** is ten feet square. New gardeners are *strongly encouraged* to start with a half plot.
//
// 
//
// ### Plot Fees
//
// | Plot | Size | Annual Fee |
// | --- | --- | --- |
// | Full | 20 x 10 ft | $60 |
// | Half | 10 x 10 ft | $35 |
//
// <!-- page 2 -->
//
// ## Watering
//
// ### Schedule
//
// The shared tanks are filled on Monday and Thursday mornings. Please water by hand from the tanks rather than running a hose from the street tap, which is metered.
//
// ### Dry Spells
//
// During a declared drought the committee may limit watering to **two days a week**. Notices are posted on the shed door and sent by e-mail.
//
// ---- custom options ----
// # Community Garden Handbook
//
// ## Plots
//
// ## Plot Sizes
//
// Plots come in two sizes. A full plot is twenty feet by ten feet; a half plot is ten feet square. New gardeners are strongly encouraged to start with a half plot.
//
// ## Plot Fees
//
// Plot Size Annual Fee
//
// Full 20 x 10 ft $60
//
// Half 10 x 10 ft $35
//
// ---
//
// ## Watering
//
// ## Schedule
//
// The shared tanks are filled on Monday and Thursday mornings. Please water by hand from the tanks rather than running a hose from the street tap, which is metered.
//
// ## Dry Spells
//
// During a declared drought the committee may limit watering to two days a week. Notices are posted on the shed door and sent by e-mail.
End_Procedure