SQL Server Requires Chilkat v11.7.0+
SQL Server
Extract Right-to-Left (Hebrew, Arabic) Text in Logical Order
See more PDF Text Extraction Examples
Demonstrates the "bidi" clean-up option. PDFs draw right-to-left text in visual order (the order of the glyphs on the page); by default the extracted text is reordered into logical order, so that it reads and compares correctly. Set "bidi" to false to get the glyphs in the order they are drawn.Chilkat SQL Server Downloads
--
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 hebrew_line.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/hebrew_line.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 line of Hebrew with a Latin word (PDF) and a number (2026) embedded in it.
-- In logical order the line reads: kovetz PDF mishnat 2026 muchan ("the PDF file from 2026 is ready"),
-- with the Hebrew words in reading order and "PDF" and "2026" kept left to right.
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 (bidi: true, logical order) ----'
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'text'
PRINT @sTmp0
-- Without reordering, the Hebrew words come out reversed and in the opposite order, as drawn.
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'bidi', 0
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 '---- bidi: false (as drawn) ----'
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'text'
PRINT @sTmp0
-- Sample output (the Hebrew is shown here transliterated):
-- ---- default (bidi: true, logical order) ----
-- Right-to-Left Text
--
-- The line below is Hebrew with a Latin word and a number embedded in it:
--
-- kovetz PDF mishnat 2026 muchan
-- ---- bidi: false (as drawn) ----
-- Right-to-Left Text
--
-- The line below is Hebrew with a Latin word and a number embedded in it:
--
-- nachum 2026 tanshim PDF ztevok (the words in reverse order, each Hebrew word with its letters reversed)
EXEC @hr = sp_OADestroy @pdf
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @jsonOut
END
GO