PDDocument targetDoc = PDDocument.load(mainPDF);
PDDocument overlay1Doc = PDDocument.load(overlay1);
try
{
LayerUtility layerUtil = new LayerUtility(targetDoc);
PDFormXObject form = layerUtil.importPageAsForm(overlay1Doc, 0);
PDPage targetPage = targetDoc.getPage(0);
layerUtil.wrapInSaveRestore(targetPage);
AffineTransform at = new AffineTransform();
PDOptionalContentGroup ocg = layerUtil.appendFormAsLayer(
targetPage, form, at, "overlay");