Sample code for 30+ languages & platforms
SQL Server Requires Chilkat v11.7.0+

Why a PDF Optimization Was Skipped

See more PDF Optimization Examples

Demonstrates the "skipped" array, which lists the options that were asked for but not applied, each with a reason and, where it is page-specific, the pages. An option is skipped when it is reserved for a later release (mergeFontSubsets, compactType1Fonts), when the rules of the file forbid it (objectStreams in a PDF/A-1 file), or when the content could not be parsed safely (tidyContent and coalesceContent on a page whose content stream the parser does not understand). Nothing is ever changed on a guess: an option that cannot be applied safely is skipped and reported.

Chilkat SQL Server Downloads

SQL Server
--
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 grand_canyon_hiking_guide.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/grand_canyon_hiking_guide.pdf'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @pdf, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @pdf
        RETURN
      END

    --  Ask for the two options that are reserved for a later release.
    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'mergeFontSubsets', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'compactType1Fonts', 1

    DECLARE @jsonOut int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonOut OUT

    EXEC sp_OAMethod @pdf, 'Optimize', @success OUT, 'audit', @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

    DECLARE @i int
    SELECT @i = 0
    DECLARE @numSkipped int
    EXEC sp_OAMethod @jsonOut, 'SizeOfArray', @numSkipped OUT, 'skipped'

    PRINT 'skipped: ' + @numSkipped
    WHILE @i < @numSkipped
      BEGIN
        EXEC sp_OASetProperty @jsonOut, 'I', @i

        EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'skipped[i].option'

        EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp1 OUT, 'skipped[i].reason'
        PRINT '   ' + @sTmp0 + ' - ' + @sTmp1
        SELECT @i = @i + 1
      END

    --  A skipped option is not a failure: Optimize returns true, the other options are applied, and the
    --  report says exactly what was left undone.

    EXEC @hr = sp_OADestroy @pdf
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @jsonOut


END
GO