SQL Server Requires Chilkat v11.7.0+
SQL Server
Put a Letterhead Behind the First Page of a PDF
See more PDF Watermark Examples
Demonstrates the pdfPage type, which places a page of another PDF as the watermark. It is the way to use a letterhead, a cover overlay or a vector logo that was saved as a PDF, and unlike an image it stays sharp at any size because it is drawn, not resampled. "zOrder" set to back puts it behind the existing content, where a letterhead belongs, and "pages" set to first restricts it to page one.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 two_page_memo.pdf
-- The PDF used in this example is available at letterhead.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/two_page_memo.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', 'pdfPage'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'pdf.path', 'qa_data/pdf/letterhead.pdf'
-- The page of the source PDF to use (1 by default). "match" instead of a number places source
-- page n on target page n, which suits a set of per-page backgrounds.
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'pdf.page', 1
-- Behind the memo's own text, on page one, scaled to the page.
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'zOrder', 'back'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'pages', 'first'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'scale.fit', 'page'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'id', 'letterhead'
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/memo_letterhead.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: letterhead pages: 1
EXEC @hr = sp_OADestroy @pdf
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @jsonOut
END
GO