PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Pdf
oleobject loo_Json
oleobject loo_JsonOut
li_Success = 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 code_block.pdf
loo_Pdf = create oleobject
li_rc = loo_Pdf.ConnectToNewObject("Chilkat.Pdf")
if li_rc < 0 then
destroy loo_Pdf
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Pdf.LoadFile("qa_data/pdf/code_block.pdf")
if li_Success = 0 then
Write-Debug loo_Pdf.LastErrorText
destroy loo_Pdf
return
end if
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_JsonOut = create oleobject
li_rc = loo_JsonOut.ConnectToNewObject("Chilkat.JsonObject")
li_Success = loo_Pdf.ExtractText("markdown",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Pdf.LastErrorText
destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut
return
end if
Write-Debug "---- default (code: true) ----"
Write-Debug loo_JsonOut.StringOf("markdown")
loo_Json.UpdateBool("code",0)
li_Success = loo_Pdf.ExtractText("markdown",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Pdf.LastErrorText
destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut
return
end if
Write-Debug "---- code: false ----"
Write-Debug loo_JsonOut.StringOf("markdown")
// 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.
destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut