SQL Server Requires Chilkat v11.7.0+
SQL Server
Exclude or Include Running Headers and Page Numbers
See more PDF Text Extraction Examples
Demonstrates the "repeatedHeadersFooters" filter. Text repeated at the same position on most pages, such as a running header and "Page N of 4" footers, is left out by default; set the filter to "include" to keep it.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 four-page PDF used in this example is available at running_header.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/running_header.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
-- Every page has the header "Harbor Lighthouse Society - Annual Report 2026" at the top right
-- and "Page N of 4" at the bottom. By default both are excluded, so the text of page 2 is just
-- its heading and paragraphs.
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'pages', '2'
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 (repeated headers and footers excluded) ----'
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'text'
PRINT @sTmp0
-- Include them. The detection looks at the neighbouring pages even when only one page is
-- selected, so a single page extracted on its own still loses its running head by default.
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'repeatedHeadersFooters', 'include'
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 '---- repeatedHeadersFooters: include ----'
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'text'
PRINT @sTmp0
-- Sample output:
-- ---- default (repeated headers and footers excluded) ----
-- The Work
--
-- The restoration society took ownership in 2021 with three goals: make the structure watertight, return the tower to public access, and relight the lantern with a historically accurate lens. The first two were met in the second season, and the lens arrived on loan in November.
--
-- The spiral stair is original and is the most fragile part of the building. Twelve of the ninety-one treads were cracked or missing, and the central column had corroded badly at the second landing. The treads were cast from patterns taken off an intact tread.
-- ---- repeatedHeadersFooters: include ----
-- Harbor Lighthouse Society - Annual Report 2026
--
-- The Work
--
-- The restoration society took ownership in 2021 with three goals: ...
--
-- The spiral stair is original and is the most fragile part of the building. ...
--
-- Page 2 of 4
EXEC @hr = sp_OADestroy @pdf
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @jsonOut
END
GO