Hi Darin, I think you’re correct, as a layer can contain many forms. As a workaround you can copy and paste the code from appendFormAsLayer into your own code. LayerUtility might be removed in 2.0, as Form XObject creation is in the process of being simplified.
-- John > On 6 Jan 2015, at 05:12, Darin Broady <[email protected]> wrote: > > In version 1.8.8, LayerUtility.appendFormAsLayer() has a check to determine > if the layerName already exists in the targetDoc, and if it does, it throws > an IllegalArgumentException. My question is why? Would it not be better to > retrieve the PDOptionalContentGroup if it already exists and use it to add > the new form to the page? > I made the following change to my local copy, and on the tests that I've run, > it seems to cause no issues. Am I missing something in the spec that would > disallow this? > > from:-----------------------if (ocprops.hasGroup(layerName)){ throw new > IllegalArgumentException("Optional group (layer) already exists: " + > layerName);} > PDOptionalContentGroup layer = new > PDOptionalContentGroup(layerName);ocprops.addGroup(layer); > > to:-----------------------PDOptionalContentGroup layer = null;if > (ocprops.hasGroup(layerName)){ layer = ocprops.getGroup(layerName);}else{ > layer = new PDOptionalContentGroup(layerName); ocprops.addGroup(layer); > } > > > Darin [email protected]
