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

Exclude Rotated Margin Text from PDF Extraction

See more PDF Text Extraction Examples

Demonstrates the "rotatedText" filter. Text that is not aligned with the page, such as a vertical "CONFIDENTIAL" label in the margin, is included by default (after the upright text) and flagged in the quality report; "exclude" leaves it out.

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

    --  The page has a paragraph and, rotated 90 degrees along the left margin, "CONFIDENTIAL - DRAFT - NOT FOR DISTRIBUTION".
    EXEC sp_OAMethod @pdf, 'ExtractText', @success OUT, 'text', @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 (rotated text included) ----'
    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'text'
    PRINT @sTmp0

    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'quality.pages[0].issues[0].code'
    PRINT 'issue: ' + @sTmp0

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'rotatedText', 'exclude'
    EXEC sp_OAMethod @pdf, 'ExtractText', @success OUT, 'text', @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 '---- rotatedText: exclude ----'
    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'text'
    PRINT @sTmp0

    --  Sample output:

    --  ---- default (rotated text included) ----
    --  Restoration Budget Summary
    --  
    --  Spending for the season came in slightly under the approved budget, largely because the parapet work took less time than expected. The lens loan carries no fee, but the society is responsible for insurance and for the specialist cleaning.
    --  
    --  CONFIDENTIAL - DRAFT - NOT FOR DISTRIBUTION
    --  issue: rotatedText
    --  ---- rotatedText: exclude ----
    --  Restoration Budget Summary
    --  
    --  Spending for the season came in slightly under the approved budget, largely because the parapet work took less time than expected. The lens loan carries no fee, but the society is responsible for insurance and for the specialist cleaning.

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


END
GO