70001260 Order the layers in PDF out using the Layers collection order

Article 70001260
Type Wish
Product Engine
Version 7012
Date Added 2/1/2018
Fixed 7.7014.0.6 (2/2/2018)
Submitted by Steve Smith


Order the layers in PDF out using the Layers collection order


In version 7014 we short the layers depending on how they are in the Document's layers collection.
In previous versions the layers were added depending the draw order of the exported entities.

So you need to short the layers in the vdDocument’s Layers collection with the order you want before exporting this document to PDF. You can do this using the ChangeOrder Method (of vdLayers). The layer dialog of the VDF control might confuse you as in this dialog the layers are sorted ignoring the “real” order of the layer in document.Layers collection.
Note that unused layers (layers without objects using them) will not be exported in PDF. In order to sort the layers collection in VB6 with wrapper you can use a code like:

Private Sub Command3_Click()
Dim layArray() As String
Dim layCount As Integer
Dim I As Integer
    VDraw1.ActiveDocument.Open ""
    VDraw1.ActiveDocument.SaveAs "C:\Users\Administrator\Desktop\testsort_unsorted.pdf"
    layCount = VDraw1.ActiveDocument.Layers.Count
    ReDim layArray(layCount - 1)
    For I = 0 To layCount - 1
        layArray(I) = VDraw1.ActiveDocument.Layers(I).LayerName
    Next I

    Call BubbleSort(layArray) ' You can sort the layers collection as you wish here

    For I = layCount - 1 To 0 Step -1
        Call VDraw1.ActiveDocument.Layers.ChangeOrder(VDraw1.ActiveDocument.Layers.FindName(layArray(I)), 1)
    Next I
    VDraw1.ActiveDocument.SaveAs "C:\Users\Administrator\Desktop\testsort_Sorted.pdf"
End Sub

    Public Sub BubbleSort(ByRef pvarArray As Variant) ' a simple sort
        Dim I As Long
        Dim iMin As Long
        Dim iMax As Long
        Dim varSwap As Variant
        Dim blnSwapped As Boolean
        iMin = LBound(pvarArray)
        iMax = UBound(pvarArray) - 1
            blnSwapped = False
            For I = iMin To iMax
                If pvarArray(I) > pvarArray(I + 1) Then
                    varSwap = pvarArray(I)
                    pvarArray(I) = pvarArray(I + 1)
                    pvarArray(I + 1) = varSwap
                    blnSwapped = True
                End If
            iMax = iMax - 1
        Loop Until Not blnSwapped
    End Sub

Send comments on this topic.