The AddLayer method is used to insert a new layer to a document. This method takes 2 string parameters, a display name and a unique layer ID. In case the layer ID is not unique the method will internally generate a unique ID and return it. This returned layer ID (might be identical to input) should be used for all layer operations.
Sub AddLayer(displayName As String, ByRef newLayerID As String)
void AddLayer(string displayName, ref string newLayerID)
displayName
This is the name that should be displayed (by the viewer of the PDF) to the user.
newLayerID
This is the unique ID for this layer. It is important that this ID be saved by the caller.
The layer configuration is mandatory, otherwise, it will generate an exception at the moment to save the PDF document. The AddLayerConfiguration method is used to insert a new layer configuration to a document.
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.
Member of Amyuni.PDFCreator.IacDocument.
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();
}