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

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 SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @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

    DECLARE @pdf int
    EXEC @hr = sp_OACreate 'Chilkat.Pdf', @pdf OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @pdf, 'LoadFile', @success OUT, 'qa_data/pdf/code_block.pdf'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @pdf, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @pdf
        RETURN
      END

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    DECLARE @jsonOut int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonOut OUT

    EXEC sp_OAMethod @pdf, 'ExtractText', @success OUT, 'markdown', @json, @jsonOut
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @pdf, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @pdf
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @jsonOut
        RETURN
      END

    PRINT '---- default (code: true) ----'
    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'markdown'
    PRINT @sTmp0

    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'code', 0
    EXEC sp_OAMethod @pdf, 'ExtractText', @success OUT, 'markdown', @json, @jsonOut
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @pdf, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @pdf
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @jsonOut
        RETURN
      END

    PRINT '---- code: false ----'
    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'markdown'
    PRINT @sTmp0

    --  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.

    EXEC @hr = sp_OADestroy @pdf
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @jsonOut


END
GO