SQL Server Requires Chilkat v11.7.0+
SQL Server
Tile a Watermark Across a PDF Page
See more PDF Watermark Examples
Demonstrates a tiled watermark, which repeats the stamp over the whole page instead of placing it once. Tiling overrides position.align; tile.spacingX and spacingY set the gaps, and tile.stagger offsets alternate rows by half a tile so the pattern does not line up in columns. A faint tiled stamp carrying the name or address is the usual way to mark a document so that a leaked copy can be traced back, and zOrder back keeps it behind the text where it does not hinder reading.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @sTmp1 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 long_report.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/long_report.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
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'type', 'text'
-- {date:FORMAT} is replaced per page when the watermark is added. The other placeholders are
-- {page}, {pages} and {filename}; {{ gives a literal brace.
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'text', 'jdoe@example.com {date:yyyy-MM-dd}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'id', 'trace'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'zOrder', 'back'
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'font.size', '14'
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'opacity', '0.15'
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'rotation', '30'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'tile.enabled', 1
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'tile.spacingX', '60'
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'tile.spacingY', '80'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'tile.stagger', 1
DECLARE @jsonOut int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonOut OUT
EXEC sp_OAMethod @pdf, 'Watermark', @success OUT, 'add', @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
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'id'
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp1 OUT, 'pages'
PRINT 'id: ' + @sTmp0 + ' pages: ' + @sTmp1
EXEC sp_OAMethod @pdf, 'WriteFile', @success OUT, 'qa_output/report_traced.pdf'
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
-- Sample output:
-- id: trace pages: 1-3
EXEC @hr = sp_OADestroy @pdf
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @jsonOut
END
GO