External developers need to be aware of layer titles only. The layers IDs and object numbers are not significant to the developer, so the implemented API will only use layer titles to insert layers and define the layer hierarchy.
Layers can be inserted within a PDF file while the document is being printed by calling Escape sequences. Escape sequences are GDI artifacts that enable developers to send custom data to a printer driver.
The first step to start adding layers is to check that the printer has support for the escape sequences that are defined by Amyuni.
The following calls are needed for that:
// check if PDF printer supports layers
#define ESCAPE_SETLAYER 248
CHAR technology[4];
int escape = ESCAPE_SETLAYER;
ExtEscape(hDC, GETTECHNOLOGY, 0, NULL, sizeof(technology),(LPSTR)technology);
// the technology should be PDF
if(lstrcmp(technology, "PDF"))
{
MessageBox(0, "Not an Amyuni PDF driver", "Error", MB_ICONERROR);
}
// and support the SETLAYER escape
if(!ExtEscape(hDC, QUERYESCSUPPORT, sizeof(escape), &escape, 0, NULL))
{
MessageBox(0, "Not an Amyuni PDF driver", "Error", MB_ICONERROR);
}
GETTECHNOLOGY and QUERYESCSUPPORT are escape sequences that are predefined by Windows GDI. ESCAPE_SETLAYER is a custom escape that is processed by the Amyuni printer.
The SETLAYER escape takes one parameter which is a Unicode string, The escape can be wrapped into a helper function such as:
void SetLayer(HDC hDC, LPWSTR LayerInfo)
{
switch(ExtEscape(hDC, ESCAPE_SETLAYER,(int)((wcslen(LayerInfo)+ 1)* sizeof(LayerInfo[0])), LayerInfo, 0, NULL))
{
default:
// positive return indicates success
case 0:
// no error
return;
case -1:
// error occured, closing a layer when none was open
break;
case -2:
// memory allocation error (low memory or invalid string)
break;
}
}
The same escape call is used to start a layer or sub-layer, end a layer or define the hierarchy of layers.