AddLayerConfiguration Method

The AddLayerConfiguration method is used to insert a new layer configuration to a document. This method takes 1 string parameter, the unique layer configuration ID.

In case the layer configuration ID is not unique the method will internally generate a unique ID and return it. This returned layer configuration ID (might be identical to input) should be used for all layer configuration operations.

 

Syntax

Visual Basic .NET:

Sub AddLayerConfiguration(ByRef configID As String)

C#:

void AddLayerConfiguration(ref string configID)

 

Parameters

configID

This is the unique ID for this layer configuration. It is important that this ID be saved by the caller.

 

Remarks

Before creating a LayerConfig object, we need to check if the document already has a layer config and use it, rather than adding a new one.  Otherwise, it could corrupt the final PDF file.

 

If developer wants to add layers to existent PDF file, it is mandatory to delete any existent layer using the method DeleteAllLayers before adding the new layers.

 

For the moment, it is not possible to modify or append layers to existent layers.

 

The Layer and LayerConfiguration Attributes contains the details information for configure the layers.

 

Member of Amyuni.PDFCreator.IacDocument.

 

Example 1

Checking if the PDF file has Layer Configuration

Sub Sample()
    ' Constants for Activation codes
    Const strLicenseTo As String = "Amyuni PDF Creator .NET Evaluation"
    Const strActivationCode As String = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B"
 
    ' Initialize library
    ' This should be done once
    acPDFCreatorLib.Initialize()
 
    ' set license key This is needed only with licensed version
    acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode)
 
    ' Create new stream object
    Dim fileRead As System.IO.Stream = System.IO.File.OpenRead("C:\temp\PDFDocument.pdf")
 
    ' Create a new PDF document
    Dim doc As New Amyuni.PDFCreator.IacDocument()
 
    ' Open PDF file
    Dim password As String = ""
    doc.Open(fileRead, password)
 
    ' Create Layer Configuration Object
    Dim oLayerConfig As Amyuni.PDFCreator.IacObject
 
    ' Get ArrayList of LayerConfigs in the document
    Dim arList As System.Collections.ArrayList = doc.AttributeByName("LayerConfigs").Value
    If arList.Count = 0 Then
        Dim configID As String = ""
        doc.AddLayerConfiguration(configID)
        oLayerConfig = doc.ObjectByName("LayerConfigs[" + configID + "]")
    Else
        oLayerConfig = arList(0)
    End If
 
    ' Create the layer
    Dim layerId As String = ""
    doc.AddLayer("Layer 1", layerId)
 
    ' Define configuration
    oLayerConfig.Attribute("ConfigOrder").Value = "[(Main Document)" + layerId + "]"
 
    ' Adding a image in first page
    With doc.GetPage(1).CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypePicture, "Picture1")
        .Attribute("Left").Value = 1000
        .Attribute("Right").Value = 5000
        .Attribute("Top").Value = 1000
        .Attribute("Bottom").Value = 8500
        .Attribute("BorderColor").Value = &HFFFFFF
        .Attribute("BorderWidth").Value = Amyuni.PDFCreator.IacBorderWidth.acBorderWidthTriple
        ' Picture Attributes
        .Attribute("FileName").Value = "C:\temp\photo1.jpg"
        .Attribute("LayerID").Value = layerId
    End With
 
    ' Create new stream object
    Dim fileWrite As System.IO.Stream = System.IO.File.OpenWrite("C:\temp\CreatePDFDocument_resulting.pdf")
 
    ' Save stream
    doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView)
 
    ' Close the streams
    fileRead.Close()
    fileWrite.Close()
 
    ' dispose objects
    oLayerConfig.Dispose()
    doc.Dispose()
 
    ' terminate library to free resources
    acPDFCreatorLib.Terminate()
End Sub
static void Sample()
{
    // Constants for Activation codes
    const string strLicenseTo = "Amyuni PDF Creator .NET Evaluation";
    const string strActivationCode = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B";
 
    // Initialize library
    // This should be done once
    acPDFCreatorLib.Initialize();
 
    // set license key This is needed only with licensed version
    acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode);
 
    // Create new stream object
    System.IO.FileStream fileRead = new System.IO.FileStream(@"C:\temp\PDFDocument.pdf",
            System.IO.FileMode.Open,
            System.IO.FileAccess.Read,
            System.IO.FileShare.Read);
 
    // Create a new PDF document
    Amyuni.PDFCreator.IacDocument doc = new Amyuni.PDFCreator.IacDocument();
 
    // Open PDF file
    String password = "";
    doc.Open(fileRead, password);
 
    // Create Layer Configuration Object
    Amyuni.PDFCreator.IacObject oLayerConfig;
 
    // Get ArrayList of LayerConfigs in the document
    System.Collections.ArrayList arList = (System.Collections.ArrayList)doc.AttributeByName("LayerConfigs").Value;
    if (arList.Count == 0)
    {
        string configID = "";
        doc.AddLayerConfiguration(ref configID);
        oLayerConfig = doc.ObjectByName("LayerConfigs[" + configID + "]");
    }
    else
    {
        oLayerConfig = (Amyuni.PDFCreator.IacObject)arList[0];
    }
 
    // Create the layer
    string layerId = "";
    doc.AddLayer("Layer 1", ref layerId);
 
    // Define configuration
    oLayerConfig.Attribute("ConfigOrder").Value = "[(Main Document)" + layerId + "]";
 
    // Adding a image in first page
    using (Amyuni.PDFCreator.IacObject oPic = doc.GetPage(1).CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypePicture, "Picture1"))
    {
        // Set-up the Picture
        oPic.Attribute("Left").Value = 1000;
        oPic.Attribute("Right").Value = 5000;
        oPic.Attribute("Top").Value = 1000;
        oPic.Attribute("Bottom").Value = 8500;
        oPic.Attribute("BorderColor").Value = 0xFFFFFF;
        oPic.Attribute("BorderWidth").Value = Amyuni.PDFCreator.IacBorderWidth.acBorderWidthTriple;
        // Picture Attributes
        oPic.Attribute("Filename").Value = @"c:\temp\photo1.jpg";
        oPic.Attribute("LayerID").Value = layerId;
    }
 
    // Create new stream object
    System.IO.FileStream fileWrite = new System.IO.FileStream(@"C:\Temp\CreatePDFDocument_resulting.pdf",
            System.IO.FileMode.Create,
            System.IO.FileAccess.Write,
            System.IO.FileShare.Read);
 
    // Save stream
    doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView);
 
    // Close the streams
    fileRead.Close();
    fileWrite.Close();
 
    // dispose objects
    oLayerConfig.Dispose();
    doc.Dispose();
 
    // terminate library to free resources
    acPDFCreatorLib.Terminate();
}

 

Example 2

Sub Sample()
    ' Constants for Activation codes
    Const strLicenseTo As String = "Amyuni PDF Creator .NET Evaluation"
    Const strActivationCode As String = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B"
 
    ' Initialize library
    ' This should be done once
    acPDFCreatorLib.Initialize()
 
    ' set license key
    acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode)
 
    ' Create a new PDF document
    Dim doc As New Amyuni.PDFCreator.IacDocument()
 
    ' Create all the Layers
    Dim layerID1 As String = ""
    Dim layerID2 As String = ""
    doc.AddLayer("Layer 1", layerID1)
    doc.AddLayer("Layer 2", layerID2)
 
    ' Define the layer configuration as it will appear in a PDF Viewer, e.g.the order And visibility of layers
    Dim configID As String = ""
    doc.AddLayerConfiguration(configID)
    Using oLayerConfig As Amyuni.PDFCreator.IacObject = doc.ObjectByName("LayerConfigs[" + configID + "]")
        ' order of appearance in the tree
        oLayerConfig.Attribute("ConfigOrder").Value = "[(Main Document)[" + layerID2 + " " + layerID1 + "]]"
 
        ' set one of the layers visibility to off by default
        oLayerConfig.Attribute("ConfigOFF").Value = "[" + layerID2 + "]"
    End Using
 
    ' Create page object
    Dim page As Amyuni.PDFCreator.IacPage
 
    ' Define first page of PDF document
    page = doc.GetPage(1)
 
    ' Create Photo 1
    With page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypePicture, "Picture1")
        .Attribute("Left").Value = 1000
        .Attribute("Right").Value = 5000
        .Attribute("Top").Value = 1000
        .Attribute("Bottom").Value = 8500
        .Attribute("BorderColor").Value = &HFFFFFF
        .Attribute("BorderWidth").Value = Amyuni.PDFCreator.IacBorderWidth.acBorderWidthTriple
        ' Picture Attributes
        .Attribute("FileName").Value = "C:\temp\photo1.jpg"
        .Attribute("LayerID").Value = layerID1
    End With
 
    ' Create Photo 2
    With page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypePicture, "Picture2")
        .Attribute("Left").Value = 6000
        .Attribute("Right").Value = 10000
        .Attribute("Top").Value = 1000
        .Attribute("Bottom").Value = 8500
        .Attribute("BorderColor").Value = &HFFFFFF
        .Attribute("BorderWidth").Value = Amyuni.PDFCreator.IacBorderWidth.acBorderWidthTriple
        ' Picture Attributes
        .Attribute("FileName").Value = "C:\temp\photo2.jpg"
        .Attribute("LayerID").Value = layerID1
    End With
 
    ' Create Photo 3
    With page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypePicture, "Picture3")
        .Attribute("Left").Value = 1000
        .Attribute("Right").Value = 5000
        .Attribute("Top").Value = 9000
        .Attribute("Bottom").Value = 17500
        .Attribute("BorderColor").Value = &HFFFFFF
        .Attribute("BorderWidth").Value = Amyuni.PDFCreator.IacBorderWidth.acBorderWidthTriple
        ' Picture Attributes
        .Attribute("FileName").Value = "C:\temp\photo3.jpg"
        .Attribute("LayerID").Value = layerID1
    End With
 
    ' Create Photo 4
    With page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypePicture, "Picture4")
        .Attribute("Left").Value = 6000
        .Attribute("Right").Value = 10000
        .Attribute("Top").Value = 9000
        .Attribute("Bottom").Value = 17500
        .Attribute("BorderColor").Value = &HFFFFFF
        .Attribute("BorderWidth").Value = Amyuni.PDFCreator.IacBorderWidth.acBorderWidthTriple
        ' Picture Attributes
        .Attribute("FileName").Value = "C:\temp\photo4.jpg"
        .Attribute("LayerID").Value = layerID1
    End With
 
    ' Create new stream object
    Dim fileWrite As System.IO.Stream = System.IO.File.OpenWrite("C:\temp\CreatePDFDocument_resulting.pdf")
 
    ' Save stream
    doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView)
 
    ' Close the stream
    fileWrite.Close()
 
    ' terminate library to free resources
    acPDFCreatorLib.Terminate()
End Sub
static void Sample()
{
    // Constants for Activation codes
    const string strLicenseTo = "Amyuni PDF Creator .NET Evaluation";
    const string strActivationCode = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B";
 
    // Initialize library
    // This should be done once
    acPDFCreatorLib.Initialize();
 
    // set license key
    acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode);
 
    // Create a new PDF document
    Amyuni.PDFCreator.IacDocument doc = new Amyuni.PDFCreator.IacDocument();
 
    // Create all the Layers
    string layerID1 = "";
    string layerID2 = "";
    doc.AddLayer("Layer 1", ref layerID1);
    doc.AddLayer("Layer 2", ref layerID2);
 
    // Define the layer configuration as it will appear in a PDF Viewer, e.g.the order and visibility of layers
    string configID = "";
    doc.AddLayerConfiguration(ref configID);
    using (Amyuni.PDFCreator.IacObject oLayerConfig = doc.ObjectByName("LayerConfigs[" + configID + "]"))
    {
        // order of appearance in the tree
        oLayerConfig.Attribute("ConfigOrder").Value = "[(Main Document)[" + layerID2 + " " + layerID1 + "]]";
 
        // set one of the layers visibility to off by default
        oLayerConfig.Attribute("ConfigOFF").Value = "[" + layerID2 + "]";
    }
 
    // Create page object
    Amyuni.PDFCreator.IacPage page;
 
    // Define first page of PDF document
    page = doc.GetPage(1);
 
    //  Adding Photo 1
    using (Amyuni.PDFCreator.IacObject oPic = page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypePicture, "Picture1"))
    {
        // Set-up the Picture
        oPic.Attribute("Left").Value = 1000;
        oPic.Attribute("Right").Value = 5000;
        oPic.Attribute("Top").Value = 1000;
        oPic.Attribute("Bottom").Value = 8500;
        oPic.Attribute("BorderColor").Value = 0xFFFFFF;
        oPic.Attribute("BorderWidth").Value = Amyuni.PDFCreator.IacBorderWidth.acBorderWidthTriple;
        // Picture Attributes
        oPic.Attribute("Filename").Value = @"c:\temp\photo1.jpg";
        oPic.Attribute("LayerID").Value = layerID1;
    }
 
    // Adding Photo 2
    using (Amyuni.PDFCreator.IacObject oPic = page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypePicture, "Picture2"))
    {
        // Set-up the Picture
        oPic.Attribute("Left").Value = 6000;
        oPic.Attribute("Right").Value = 10000;
        oPic.Attribute("Top").Value = 1000;
        oPic.Attribute("Bottom").Value = 8500;
        oPic.Attribute("BorderColor").Value = 0xFFFFFF;
        oPic.Attribute("BorderWidth").Value = Amyuni.PDFCreator.IacBorderWidth.acBorderWidthTriple;
        // Picture Attributes
        oPic.Attribute("Filename").Value = @"c:\temp\photo2.jpg";
        oPic.Attribute("LayerID").Value = layerID1;
    }
 
    //  Adding Photo 3
    using (Amyuni.PDFCreator.IacObject oPic = page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypePicture, "Picture3"))
    {
        // Set-up the Picture
        oPic.Attribute("Left").Value = 1000;
        oPic.Attribute("Right").Value = 5000;
        oPic.Attribute("Top").Value = 9000;
        oPic.Attribute("Bottom").Value = 17500;
        oPic.Attribute("BorderColor").Value = 0xFFFFFF;
        oPic.Attribute("BorderWidth").Value = Amyuni.PDFCreator.IacBorderWidth.acBorderWidthTriple;
        // Picture Attributes
        oPic.Attribute("Filename").Value = @"c:\temp\photo3.jpg";
        oPic.Attribute("LayerID").Value = layerID2;
    }
 
    // Adding Photo 4
    using (Amyuni.PDFCreator.IacObject oPic = page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypePicture, "Picture4"))
    {
        // Set-up the Picture
        oPic.Attribute("Left").Value = 6000;
        oPic.Attribute("Right").Value = 10000;
        oPic.Attribute("Top").Value = 9000;
        oPic.Attribute("Bottom").Value = 17500;
        oPic.Attribute("BorderColor").Value = 0xFFFFFF;
        oPic.Attribute("BorderWidth").Value = Amyuni.PDFCreator.IacBorderWidth.acBorderWidthTriple;
        // Picture Attributes
        oPic.Attribute("Filename").Value = @"c:\temp\photo4.jpg";
        oPic.Attribute("LayerID").Value = layerID2;
    }
 
    // Create new stream object
    System.IO.FileStream fileWrite = new System.IO.FileStream(@"C:\Temp\CreatePDFDocument_resulting.pdf",
            System.IO.FileMode.Create,
            System.IO.FileAccess.Write,
            System.IO.FileShare.Read);
 
    // Save stream
    doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView);
 
    // Close the stream
    fileWrite.Close();
 
    // terminate library to free resources
    acPDFCreatorLib.Terminate();
}