This content has been marked as final.
Show 8 replies
-
1. Re: How to get more info from "This direct object already has a container." exception?
(Aandi_Inston) Sep 2, 2008 11:54 PM (in response to andrejusc)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 -
2. Re: How to get more info from "This direct object already has a container." exception?
andrejusc Sep 3, 2008 5:08 AM (in response to andrejusc)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? -
3. Re: How to get more info from "This direct object already has a container." exception?
(Aandi_Inston) Sep 3, 2008 5:42 AM (in response to (Aandi_Inston))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 -
4. Re: How to get more info from "This direct object already has a container." exception?
andrejusc Sep 3, 2008 6:08 AM (in response to andrejusc)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. -
5. Re: How to get more info from "This direct object already has a container." exception?
(Aandi_Inston) Sep 3, 2008 6:20 AM (in response to andrejusc)I'm not familiar with these methods enough to guess at the cause so
I'll have to pass.
Aandi Inston -
6. Re: How to get more info from "This direct object already has a container." exception?
Polda1 Sep 3, 2008 6:47 AM (in response to andrejusc)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 -
7. Re: How to get more info from "This direct object already has a container." exception?
andrejusc Sep 3, 2008 7:25 AM (in response to andrejusc)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? -
8. Re: How to get more info from "This direct object already has a container." exception?
andrejusc Sep 3, 2008 8:57 AM (in response to andrejusc)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?
