How to get more info from"This direct object already has a container."exception? - Adobe Acrobat

This is a discussion on How to get more info from"This direct object already has a container."exception? - Adobe Acrobat ; Hi, I'm experimenting with PDF tree via PDE and Cos layers and after copying all elements from initial content to destination content via PDE layer and trying to set Resources/Contents at the end of my method via Cos - I ...

+ Reply to Thread
Results 1 to 9 of 9

How to get more info from"This direct object already has a container."exception?

  1. Default How to get more info from"This direct object already has a container."exception?

    Hi,

    I'm experimenting with PDF tree via PDE and Cos layers and after copying all elements from initial content to destination content via PDE layer and trying to set Resources/Contents at the end of my method via Cos - I get this exception: This direct object already has a container.

    Is it possible to understand what is that direct object, which is not happy with my manipulations? Does this exception means that direct object belongs to some container already or some container contains this direct object?

    Any help would be appreciated!

  2. Default Re: How to get more info from"This direct object already has a container."exception?

    The "container" here is a Cos object. A direct object cannot be stored
    into more than one other object (it does not matter whether the parent
    is direct or indirect). To see why this is the case, consider that
    direct objects are written inline when a PDF is saved. It cannot be
    written in two places.

    A = new direct object
    CosDictPut ( oneplace ... A ) - will succeed
    CosDictPut ( anotherplace ... A ) - will fail

    To find out which object is concerned, use normal debugging
    techniques; an exception is raised on your API call. (Tip: set a
    breakpoint on a longjmp in PIMain to catch all exceptions as early as
    possible).

    You cannot find out what the other parent is by any API.


    Aandi Inston

  3. Default Re: How to get more info from"This direct object already has a container."exception?

    Strange thing is that (after some debugging) I get such exception during this call:

    CosObj contentObj, resObj;

    PDEContentToCosObj(newPdeContent, kPDEContentToPage, 0, 0, destDoc, 0, &contentObj, &resObj);

    Why? Does it mean that my new PDEContent with some added PDE elements by some reason cannot be converted into Cos?

  4. Default Re: How to get more info from"This direct object already has a container."exception?

    This is odd and suggests that an object needed to generate the page
    was not set up correctly, or perhaps was taken from somewhere else
    without copying.

    How is the PDEContent obtained or made?

    Aandi Inston

  5. Default Re: How to get more info from"This direct object already has a container."exception?

    I have constructed new PDEContent in this way:

    PDEContent newPdeContent = PDEContentCreate();

    after that I'm trying to go through initial page content (pdeContent) via such cycle with recursion and add each found element (I'm planning to do some filtering later) into new page:

    part of CopyElems:

    for (ASInt32 elemIdx = 0; elemIdx < pdeContentNumElems; elemIdx++) { // get element PDEElement pdeElement = PDEContentGetElem (pdeContent, elemIdx); PDEElement newPdeElement = PDEElementCopy (pdeElement, kPDEElementCopyForClip); // insert it into new content PDEContentAddElem(newPdeContent, kPDEAfterLast, newPdeElement); PDERelease((PDEObject)newPdeElement); // if it's container or group, then call CopyElems again //... }

    and after that if I call PDEContentToCosObj - it hangs. Do I need any flushing of content before that call?

    What I'm trying to achieve is currently via PDE layer only selectively copy some elements into new doc with one page.

    Maybe there is a better way for that.

  6. Default Re: How to get more info from"This direct object already has a container."exception?

    I'm not familiar with these methods enough to guess at the cause so
    I'll have to pass.

    Aandi Inston

  7. Default Re: How to get more info from"This direct object already has a container."exception?

    Its hard to tell from this part of the code, but I see that you release the newPdeElement and THEN your comment suggests that you are going to check for the type of it and copy it with recursion. That might be the mistake.

    Polda

  8. Default Re: How to get more info from"This direct object already has a container."exception?

    I'm doing type checking only for original PDEElement, which is in my case pdeElement variable. And I'm releasing newPdeElement assuming that

    PDEContentAddElem(newPdeContent, kPDEAfterLast, newPdeElement);

    call already increments reference count to it. Do I need to keep newPdeElement unreleased until I'm done with recursion copy of childs into it, i.e. release it after all childs recursion?

  9. Default Re: How to get more info from"This direct object already has a container."exception?

    I think I was wrong with PDEElementCopy.

    In description it says:
    Makes a copy of an element.

    But it doesn't say if that new copy is detached from any parent container or not. And I now suspect on the Cos level it still handles that relation.

    So what I really need to not mess all those things is to create new PDE elements (in case I want them on a new page in a new document) and copy source PDE elements into them without PDEElementCopy usage.

    Am I right?

    Btw, if I use PDEContentToCosObj with indirect flag set to true - could it happen that those indirect objects will be placed inside resulting tree once again after my recusion copy step? Or will it throw exception again?

+ Reply to Thread