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) As String
void AddLayer(string displayName, ref string newLayerID)
void AddLayer(LPCTSTR displayName, [in, out] BSTR *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.
Sub Sample()
' Constants for Activation codes
Const strLicenseTo As String = "Amyuni PDF Creator Evaluation"
Const strActivationCode As String = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC"
' Initializing PDFCreativeX Object
Dim pdf As ACPDFCREACTIVEX.PDFCreactiveX = New ACPDFCREACTIVEX.PDFCreactiveX()
' set license key
pdf.SetLicenseKey(strLicenseTo, strActivationCode)
' Create all the Layers
Dim layerID1 As String = ""
Dim layerID2 As String = ""
pdf.AddLayer("Layer 1", layerID1)
pdf.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 = ""
pdf.AddLayerConfiguration(configID)
' order of appearance in the tree
pdf.ObjectAttribute("LayerConfigs[" + configID + "]", "ConfigOrder") = "[(Main Document)[" + layerID2 + " " + layerID1 + "]]"
' set one of the layers visibility to off by default
pdf.ObjectAttribute("LayerConfigs[" + configID + "]", "ConfigOFF") = "[" + layerID2 + "]"
' Set CurrentPage
pdf.CurrentPage = 1
' Adding Photo 1
pdf.CreateObject(ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypePicture, "Picture1")
Dim oPic As ACPDFCREACTIVEX.IacObject = pdf.GetObjectByName("Picture1")
' Set-up the Picture
oPic("Left") = 1000
oPic("Right") = 5000
oPic("Top") = 1000
oPic("Bottom") = 8500
oPic("BorderColor") = &HFFFFFF
oPic("BorderWidth") = ACPDFCREACTIVEX.acBorderWidth.acBorderWidthTriple
' Picture Attributes
oPic("Filename") = "c:\temp\photo1.jpg"
oPic("LayerID") = layerID1
' Adding Photo 2
pdf.CreateObject(ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypePicture, "Picture2")
oPic = pdf.GetObjectByName("Picture2")
' Set-up the Picture
oPic("Left") = 6000
oPic("Right") = 10000
oPic("Top") = 1000
oPic("Bottom") = 8500
oPic("BorderColor") = &HFFFFFF
oPic("BorderWidth") = ACPDFCREACTIVEX.acBorderWidth.acBorderWidthTriple
' Picture Attributes
oPic("Filename") = "c:\temp\photo2.jpg"
oPic("LayerID") = layerID1
' Adding Photo 3
pdf.CreateObject(ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypePicture, "Picture3")
oPic = pdf.GetObjectByName("Picture3")
' Set-up the Picture
oPic("Left") = 1000
oPic("Right") = 5000
oPic("Top") = 9000
oPic("Bottom") = 17500
oPic("BorderColor") = &HFFFFFF
oPic("BorderWidth") = ACPDFCREACTIVEX.acBorderWidth.acBorderWidthTriple
' Picture Attributes
oPic("Filename") = "c:\temp\photo3.jpg"
oPic("LayerID") = layerID2
' Adding Photo 4
pdf.CreateObject(ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypePicture, "Picture4")
oPic = pdf.GetObjectByName("Picture4")
' Set-up the Picture
oPic("Left") = 6000
oPic("Right") = 10000
oPic("Top") = 9000
oPic("Bottom") = 17500
oPic("BorderColor") = &HFFFFFF
oPic("BorderWidth") = ACPDFCREACTIVEX.acBorderWidth.acBorderWidthTriple
' Picture Attributes
oPic("Filename") = "c:\temp\photo4.jpg"
oPic("LayerID") = layerID2
' Save PDF
pdf.Save("c:\temp\CreatePDFDocument_resulting.pdf", ACPDFCREACTIVEX.FileSaveOptionConstants.acFileSaveView)
End Sub
static void Sample()
{
// Constants for Activation codes
const string strLicenseTo = "Amyuni PDF Creator Evaluation";
const string strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC";
// Initializing PDFCreativeX Object
ACPDFCREACTIVEX.PDFCreactiveX pdf = new ACPDFCREACTIVEX.PDFCreactiveX();
// set license key
pdf.SetLicenseKey(strLicenseTo, strActivationCode);
// Create all the Layers
string layerID1 = "";
string layerID2 = "";
pdf.AddLayer("Layer 1", ref layerID1);
pdf.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 = "";
pdf.AddLayerConfiguration(ref configID);
// order of appearance in the tree
pdf.ObjectAttribute["LayerConfigs[" + configID + "]", "ConfigOrder"] = "[(Main Document)[" + layerID2 + " " + layerID1 + "]]";
// set one of the layers visibility to off by default
pdf.ObjectAttribute["LayerConfigs[" + configID + "]", "ConfigOFF"] = "[" + layerID2 + "]";
// Set CurrentPage
pdf.CurrentPage = 1;
// Adding Photo 1
pdf.CreateObject(ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypePicture, "Picture1");
ACPDFCREACTIVEX.IacObject oPic = pdf.GetObjectByName("Picture1");
// Set-up the Picture
oPic["Left"] = 1000;
oPic["Right"] = 5000;
oPic["Top"] = 1000;
oPic["Bottom"] = 8500;
oPic["BorderColor"] = 0xFFFFFF;
oPic["BorderWidth"] = ACPDFCREACTIVEX.acBorderWidth.acBorderWidthTriple;
// Picture Attributes
oPic["Filename"] = @"c:\temp\photo1.jpg";
oPic["LayerID"] = layerID1;
// Adding Photo 2
pdf.CreateObject(ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypePicture, "Picture2");
oPic = pdf.GetObjectByName("Picture2");
// Set-up the Picture
oPic["Left"] = 6000;
oPic["Right"] = 10000;
oPic["Top"] = 1000;
oPic["Bottom"] = 8500;
oPic["BorderColor"] = 0xFFFFFF;
oPic["BorderWidth"] = ACPDFCREACTIVEX.acBorderWidth.acBorderWidthTriple;
// Picture Attributes
oPic["Filename"] = @"c:\temp\photo2.jpg";
oPic["LayerID"] = layerID1;
// Adding Photo 3
pdf.CreateObject(ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypePicture, "Picture3");
oPic = pdf.GetObjectByName("Picture3");
// Set-up the Picture
oPic["Left"] = 1000;
oPic["Right"] = 5000;
oPic["Top"] = 9000;
oPic["Bottom"] = 17500;
oPic["BorderColor"] = 0xFFFFFF;
oPic["BorderWidth"] = ACPDFCREACTIVEX.acBorderWidth.acBorderWidthTriple;
// Picture Attributes
oPic["Filename"] = @"c:\temp\photo3.jpg";
oPic["LayerID"] = layerID2;
// Adding Photo 4
pdf.CreateObject(ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypePicture, "Picture4");
oPic = pdf.GetObjectByName("Picture4");
// Set-up the Picture
oPic["Left"] = 6000;
oPic["Right"] = 10000;
oPic["Top"] = 9000;
oPic["Bottom"] = 17500;
oPic["BorderColor"] = 0xFFFFFF;
oPic["BorderWidth"] = ACPDFCREACTIVEX.acBorderWidth.acBorderWidthTriple;
// Picture Attributes
oPic["Filename"] = @"c:\temp\photo4.jpg";
oPic["LayerID"] = layerID2;
// Save PDF
pdf.Save(@"c:\temp\CreatePDFDocument_resulting.pdf", ACPDFCREACTIVEX.FileSaveOptionConstants.acFileSaveView);
}
#import "c:\users\amyuni\pdfcreactivex.dll" no_namespace
using namespace std;
int main()
{
// Constants for Activation codes
bstr_t strLicenseTo = "Amyuni PDF Creator Evaluation";
bstr_t strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC";
// Initialize the COM subsystem
CoInitialize(0);
// IPDFCreactiveXPtr is a smart pointer type defined in pdfcreactivex.tlh,
// the type library header file generated by the #import instruction above
IPDFCreactiveXPtr pdf;
// Create the PDFCreactiveX instance
pdf.CreateInstance(__uuidof(PDFCreactiveX));
// set license key
pdf->SetLicenseKey(_bstr_t(strLicenseTo), _bstr_t(strActivationCode));
// Create all the Layers
HRESULT hr;
_bstr_t layerID1;
_bstr_t layerID2;
hr = pdf->AddLayer("Layer 1", &layerID1.GetBSTR());
hr = pdf->AddLayer("Layer 2", &layerID2.GetBSTR());
// Define the layer configuration as it will appear in a PDF Viewer, e.g.the order and visibility of layers
_bstr_t configID = "";
hr = pdf->AddLayerConfiguration(&configID.GetBSTR());
// order of appearance in the tree
hr = pdf->ObjectAttributeStr("LayerConfigs[" + configID + "]", "ConfigOrder", "[(Main Document)[" + layerID2 + " " + layerID1 + "]]");
// set one of the layers visibility to off by default
hr = pdf->ObjectAttributeStr("LayerConfigs[" + configID + "]", "ConfigOFF", "[" + layerID2 + "]");
// Set CurrentPage
pdf->CurrentPage = 1;
// Variable for Attributes
_variant_t varAttribute;
varAttribute.vt = VT_I4; // integers
// Adding Photo 1
hr = pdf->CreateObject(acObjectTypePicture, "Picture1");
IacObjectPtr oPic = pdf->GetObjectByName("Picture1");
// Set-up the Picture
oPic->Attribute["Left"] = 1000;
oPic->Attribute["Right"] = 5000;
oPic->Attribute["Top"] = 1000;
oPic->Attribute["Bottom"] = 8500;
varAttribute.lVal = 0xFFFFFF;
oPic->Attribute["BorderColor"] = varAttribute;
varAttribute.lVal = acBorderWidthSimple;
// Picture Attributes
oPic->Attribute["Filename"] = "c:\\temp\\photo1.jpg";
oPic->Attribute["LayerID"] = layerID1;
// Adding Photo 2
hr = pdf->CreateObject(acObjectTypePicture, "Picture2");
oPic = pdf->GetObjectByName("Picture2");
// Set-up the Picture
oPic->Attribute["Left"] = 6000;
oPic->Attribute["Right"] = 10000;
oPic->Attribute["Top"] = 1000;
oPic->Attribute["Bottom"] = 8500;
varAttribute.lVal = 0xFFFFFF;
oPic->Attribute["BorderColor"] = varAttribute;
varAttribute.lVal = acBorderWidthSimple;
// Picture Attributes
oPic->Attribute["Filename"] = "c:\\temp\\photo2.jpg";
oPic->Attribute["LayerID"] = layerID1;
// Adding Photo 3
hr = pdf->CreateObject(acObjectTypePicture, "Picture3");
oPic = pdf->GetObjectByName("Picture3");
// Set-up the Picture
oPic->Attribute["Left"] = 1000;
oPic->Attribute["Right"] = 5000;
oPic->Attribute["Top"] = 9000;
oPic->Attribute["Bottom"] = 17500;
varAttribute.lVal = 0xFFFFFF;
oPic->Attribute["BorderColor"] = varAttribute;
varAttribute.lVal = acBorderWidthSimple;
// Picture Attributes
oPic->Attribute["Filename"] = "c:\\temp\\photo3.jpg";
oPic->Attribute["LayerID"] = layerID2;
// Adding Photo 1
hr = pdf->CreateObject(acObjectTypePicture, "Picture4");
oPic = pdf->GetObjectByName("Picture4");
// Set-up the Picture
oPic->Attribute["Left"] = 6000;
oPic->Attribute["Right"] = 10000;
oPic->Attribute["Top"] = 9000;
oPic->Attribute["Bottom"] = 17500;
varAttribute.lVal = 0xFFFFFF;
oPic->Attribute["BorderColor"] = varAttribute;
varAttribute.lVal = acBorderWidthSimple;
// Picture Attributes
oPic->Attribute["Filename"] = "c:\\temp\\photo4.jpg";
oPic->Attribute["LayerID"] = layerID2;
// Save PDF
pdf->Save("c:\\temp\\CreatePDFDocument_resulting.pdf", acFileSaveView);
return 0;
}
Const acObjectTypeArrow = 36
Const acObjectTypeBarcode = 45
Const acObjectTypeCell = 33
Const acObjectTypeCheckBox = 21
Const acObjectTypeEllipse = 4
Const acObjectTypeExcel = 17
Const acObjectTypeField = 6
Const acObjectTypeGraph = 19
Const acObjectTypeHighlight = 23
Const acObjectTypeLine = 1
Const acObjectTypePicture = 7
Const acObjectTypePolygon = 8
Const acObjectTypeRoundFrame = 3
Const acObjectTypeRow = 32
Const acObjectTypeSelection = 24
Const acObjectTypeSignature = 39
Const acObjectTypeStickyNote = 22
Const acObjectTypeTable = 16
Const acObjectTypeText = 5
Const acFileSaveAll = 0
Const acFileSaveDefault = -1
Const acFileSaveView = 1
Const acFileSaveDesign = 2
Const acFileSavePDFA_7 = 3
Const acFileSavePDFA = 4
Const acFileSavePDF14 = 5
' Constants for Activation codes
Const strLicenseTo = "Amyuni PDF Creator Evaluation"
Const strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC"
' Initializing PDFCreativeX Object
Dim pdf
Set pdf = CreateObject("PDFCreactiveX.PDFCreactiveX.6.5")
' Set license key
pdf.SetLicenseKey strLicenseTo, strActivationCode
' Create all the Layers
Dim layerID1
layerID1 = "Layer-1"
Dim layerID2
layerID2 = "Layer-2"
pdf.AddLayer "Layer 1", (layerID1)
pdf.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
configID = "Cgf-1"
pdf.AddLayerConfiguration (configID)
' order of appearance in the tree
pdf.ObjectAttribute("LayerConfigs[" + configID + "]", "ConfigOrder") = "[(Main Document)[" + layerID2 + " " + layerID1 + "]]"
' set one of the layers visibility to off by default
pdf.ObjectAttribute("LayerConfigs[" + configID + "]", "ConfigOFF") = "[" + layerID2 + "]"
' Set CurrentPage
pdf.CurrentPage = 1
' Adding Photo 1
pdf.CreateObject acObjectTypePicture, "Picture1"
Dim oPic
Set oPic = pdf.GetObjectByName("Picture1")
' Set-up the Picture
oPic("Left") = 1000
oPic("Right") = 5000
oPic("Top") = 1000
oPic("Bottom") = 8500
oPic("BorderColor") = &HFFFFFF
oPic("BorderWidth") = 3
' Picture Attributes
oPic("Filename") = "c:\temp\photo1.jpg"
oPic("LayerID") = layerID1
' Adding Photo 2
pdf.CreateObject acObjectTypePicture, "Picture2"
Set oPic = pdf.GetObjectByName("Picture2")
' Set-up the Picture
oPic("Left") = 6000
oPic("Right") = 10000
oPic("Top") = 1000
oPic("Bottom") = 8500
oPic("BorderColor") = &HFFFFFF
oPic("BorderWidth") = 3
' Picture Attributes
oPic("Filename") = "c:\temp\photo2.jpg"
oPic("LayerID") = layerID1
' Adding Photo 3
pdf.CreateObject acObjectTypePicture, "Picture3"
Set oPic = pdf.GetObjectByName("Picture3")
' Set-up the Picture
oPic("Left") = 1000
oPic("Right") = 5000
oPic("Top") = 9000
oPic("Bottom") = 17500
oPic("BorderColor") = &HFFFFFF
oPic("BorderWidth") = 3
' Picture Attributes
oPic("Filename") = "c:\temp\photo3.jpg"
oPic("LayerID") = layerID2
' Adding Photo 4
pdf.CreateObject acObjectTypePicture, "Picture4"
Set oPic = pdf.GetObjectByName("Picture4")
' Set-up the Picture
oPic("Left") = 6000
oPic("Right") = 10000
oPic("Top") = 9000
oPic("Bottom") = 17500
oPic("BorderColor") = &HFFFFFF
oPic("BorderWidth") = 3
' Picture Attributes
oPic("Filename") = "c:\temp\photo4.jpg"
oPic("LayerID") = layerID2
' Save PDF
pdf.Save "c:\temp\CreatePDFDocument_resulting.pdf", acFileSaveView