Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) PDF File Encoding to Base64Demonstrates how to encode a PDF file to base64, and then decode.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @pdfData int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @pdfData OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @pdfData, 'LoadFile', @success OUT, 'qa_data/helloWorld.pdf' IF @success <> 1 BEGIN PRINT 'failed to load PDF file.' EXEC @hr = sp_OADestroy @pdfData RETURN END -- Encode the PDF to base64 -- Note: to produce base64 on multiple lines (as it would appear in the MIME of an email), -- pass the string "base64_mime" instead of "base64". DECLARE @b64 nvarchar(4000) EXEC sp_OAMethod @pdfData, 'GetEncoded', @b64 OUT, 'base64' PRINT @b64 -- Decode from base64 PDF. DECLARE @pdfData2 int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @pdfData2 OUT EXEC sp_OAMethod @pdfData2, 'AppendEncoded', @success OUT, @b64, 'base64' EXEC sp_OAMethod @pdfData2, 'WriteFile', @success OUT, 'qa_output/helloWorld2.pdf' IF @success <> 1 BEGIN PRINT 'failed to write PDF file.' EXEC @hr = sp_OADestroy @pdfData EXEC @hr = sp_OADestroy @pdfData2 RETURN END EXEC @hr = sp_OADestroy @pdfData EXEC @hr = sp_OADestroy @pdfData2 END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.