This content has been marked as final.
Show 27 replies
-
1. Re: How to properly move image on a page via PDE or other methods?
(Leonard_Rosenthol) Sep 4, 2008 2:24 AM (in response to andrejusc)Yes, you need to move the container as well or at least adjust the clipping area. -
2. Re: How to properly move image on a page via PDE or other methods?
andrejusc Sep 4, 2008 2:50 AM (in response to andrejusc)Leonard,
Could you tell me how should I do that - either container move or clipping area adjustment? Is it possible via PDE layer or Cos should be used instead? Do you have any code snippet or any pseudo code, which demonstrates that?
If there is any sample I could look at - please send me URL
Thanks in advance! -
3. Re: How to properly move image on a page via PDE or other methods?
(Leonard_Rosenthol) Sep 4, 2008 3:00 AM (in response to andrejusc)I don't know why the docs say that you can't apply a matrix to a container - you should indeed be able to. -
4. Re: How to properly move image on a page via PDE or other methods?
andrejusc Sep 4, 2008 3:31 AM (in response to andrejusc)Well,
We have similar post in this forum:
http://www.adobeforums.com/webx/.59b529ba/1?14@@
and as other person I'm getting also that "Bad parameter" message when trying to save a document inside which container was moved via PDEElementSetMatrix. For PDEContainer I've tried to apply this way:
ASFixedMatrix transMatrix; // The target translation matrix
// Initialize the target transformation matrix for horizontal move
transMatrix.a = fixedOne;
transMatrix.b = fixedZero;
transMatrix.c = fixedZero;
transMatrix.d = fixedOne;
transMatrix.h = ASInt32ToFixed(10);
transMatrix.v = fixedZero;
ASFixedMatrix elemMatrix;
ASFixedMatrix newMatrix;
PDEElementGetMatrix((PDEElement)pdeContainer, &elemMatrix);
ASFixedMatrixConcat( &newMatrix, &transMatrix, &elemMatrix );
// Set new matrix
PDEElementSetMatrix((PDEElement)pdeContainer, &newMatrix);
Anything wrong with this approach? -
5. Re: How to properly move image on a page via PDE or other methods?
Polda1 Sep 4, 2008 3:58 AM (in response to andrejusc)Unfortunately, you need to use Cos Layer to do that.
Many developers (including me) started with PDE Layer, found a lot of restrictions and ended using only basic Cos methods. However, you will need to read PDF Reference carefully.
Sometimes its easier to create an element with PDE methods, then get the CosObj of the element and add appropriate matrix and object right into the content stream.
Polda -
6. Re: How to properly move image on a page via PDE or other methods?
andrejusc Sep 4, 2008 4:15 AM (in response to andrejusc)Could you tell me how could I add to/apply over CosObj an appropriate matrix then? What is the Cos layer API call for that?
Sorry, I can't find it myself... -
7. Re: How to properly move image on a page via PDE or other methods?
andrejusc Sep 4, 2008 5:26 AM (in response to andrejusc)And in addition:<br /><br />In Adobe SDK 7.0.5 we have that ObjShiftSnip.cpp sample code. This is the only place (besides API description), which demonstrates PDEElementSetMatrix usage and this code as you could see here actually omits any work with PDEContainer:<br /><br /> case kPDEContainer:<br /> {<br /> PDEContent containerContent = PDEContainerGetContent((PDEContainer)pdeElement);<br /> ASInt32 numElems = PDEContentGetNumElems(containerContent);<br /> PDEElement theElem;<br /><br /> for (ASInt32 j=0; j<numElems; j++)<br /> {<br /> theElem = PDEContentGetElem(containerContent, j);<br /> ShiftObjects(theElem, xMatrix);<br /> }<br /> }<br /> break;<br /><br />and mostly does that for other PDE objects:<br /><br /> case kPDEPath: // Perform the same matrix manipulation for both path and image objects<br /> case kPDEImage:<br /> PDEElementGetMatrix(pdeElement, &elemMatrix);<br /> ASFixedMatrixConcat( &newMatrix, &xMatrix, &elemMatrix );<br /> // Set new matrix<br /> PDEElementSetMatrix(pdeElement, &newMatrix);<br /> break;<br /><br />So, who are the guru of that container movement programming? I'm loosing all my hopes... -
8. Re: How to properly move image on a page via PDE or other methods?
(Aandi_Inston) Sep 4, 2008 5:31 AM (in response to andrejusc)>Could you tell me how could I add to/apply over CosObj an appropriate matrix then? What is the Cos layer API call for that?
There is no abstraction to do this. You need to deal with the actual
objects in the PDF. You'd need to add a stream object that contained a
cm operator, and update Contents in the page object.
Aandi Inston -
9. Re: How to properly move image on a page via PDE or other methods?
andrejusc Sep 4, 2008 6:29 AM (in response to andrejusc)Aandi
> You'd need to add a stream object that contained a
cm operator, and update Contents in the page object.
Is it possible via CosStreamDict call obtain such part of a stream:
q 1 0 0 1 23.0488 57.6792 cm
Will it be then that 'q' as separate stream dictionaty attribute? If not - should I just scan stream for all occurences of such sequence with 'q' in front? -
10. Re: How to properly move image on a page via PDE or other methods?
(Aandi_Inston) Sep 4, 2008 6:45 AM (in response to andrejusc)If you find streams that exactly match your needs you can replace them
in a Contents array. Bear in mind you cannot edit a stream, you can
only make a new one.
Aandi Inston -
11. Re: How to properly move image on a page via PDE or other methods?
(Leonard_Rosenthol) Sep 4, 2008 6:53 AM (in response to andrejusc)I forget the name offhand, but there is a high level API that you can use to let Acrobat parse the stream for you and just hand you each "operator/operand"... -
12. Re: How to properly move image on a page via PDE or other methods?
andrejusc Sep 4, 2008 7:30 AM (in response to andrejusc)I've found only one called PDEPathGetData, which talks about operator/operand. Not sure if it's the one you were thinking about. -
13. Re: How to properly move image on a page via PDE or other methods?
(Leonard_Rosenthol) Sep 4, 2008 8:08 AM (in response to andrejusc)PDPageStmGetToken -
14. Re: How to properly move image on a page via PDE or other methods?
andrejusc Sep 5, 2008 2:26 AM (in response to andrejusc)Hi Leonard,<br /><br />I'm trying to utilize that mentioned PDPageStmGetToken method for a stream, which at the beginning contains these data:<br /><br />/OC /MC0 BDC <br />q<br />0 226.772 170.079 -226.772 re<br />W n<br />0.5 0.5 0.6 0.25 k<br />/GS0 gs<br />q 1 0 0 1 81.9438 161.4658 cm<br />0 0 m<br /><skipped data><br /><br />Stream was opened in this way:<br />dataStm = CosStreamOpenStm (contentObj, cosOpenFiltered);<br /><br />Am I doing anything wrong? Is it possible to parse those data to something more suitable to analyze? Is it safe if I'd like to remove let say data belonging to /MC3 (I have /MC1,.., /MC4) from this stream (of course by creating new stream)<br /><br />Still kind of missing the light...<br />But when I print out what I get it is like this:<br /><br />0<br />0<br />0<br />0<br />0<br />14861730<br />11146297<br />-14861730<br />0<br />0<br />0<br />32768<br />32768<br />39322<br /><skipped data><br /><br />16384 -
15. Re: How to properly move image on a page via PDE or other methods?
(Leonard_Rosenthol) Sep 5, 2008 3:13 AM (in response to andrejusc)given that I have no idea what your code does, it's not really possible for me to comment. Also, you can always write your own code to parse the content stream - it's not difficult but it DOES require a FULL Cos parser (since you can have all possible Cos types in a content stream). -
16. Re: How to properly move image on a page via PDE or other methods?
(Aandi_Inston) Sep 5, 2008 3:49 AM (in response to andrejusc)>But when I print out what I get it is like this:
>
>0
>0
Are you checking the returned type of each element? You need to go to
different variants of pageStmToken.
Aandi Inston -
17. Re: How to properly move image on a page via PDE or other methods?
andrejusc Sep 5, 2008 4:20 AM (in response to andrejusc)Aaandi,
I have this part of code right now:
while (bytesRead > 0) {
bytesRead = PDPageStmGetToken(dataStm, kPDPageStmSkipComments, NULL, NULL, &pageStmTokenRec);
CosType recType = pageStmTokenRec.type;
if (recType == CosString) {
displayString(pageStmTokenRec.sVal);
}
else {
char val[256];
sprintf(val, "%d", pageStmTokenRec.iVal);
displayString(val);
}
}
where displayString is defined just as fprintf. -
18. Re: How to properly move image on a page via PDE or other methods?
(Leonard_Rosenthol) Sep 5, 2008 5:25 AM (in response to andrejusc)Did you step through the debugger to check the actual values for recType? -
19. Re: How to properly move image on a page via PDE or other methods?
andrejusc Sep 5, 2008 5:48 AM (in response to andrejusc)> Did you step through the debugger to check the actual values for recType?
I don't have the ability to do step by step debugging. Thus I'm using various string output into file to look through later.
OK, another stream related question. If I create new stream via CosNewStream and want only part of data from old stream - do I need first to create memory buffer large enough to contain required data from old stream and then provide it through ASMemStmRdOpen to new stream creation procedure?
I don't see if I could tell new stream creation procedure what to skip during reading old stream. Would be handy to have such callback procedure to provide as additional parameter. -
20. Re: How to properly move image on a page via PDE or other methods?
Patrick Leckey Sep 5, 2008 5:59 AM (in response to andrejusc)> I don't have the ability to do step by step debugging.
Can I ask why not? It is a standard feature in most IDEs, including VS2005 which is what the SDK was designed to be used with. -
21. Re: How to properly move image on a page via PDE or other methods?
(Aandi_Inston) Sep 5, 2008 6:09 AM (in response to andrejusc)Seems to me you are missing out the really important case where the
token is a name (as would be expected).
Aandi Inston -
22. Re: How to properly move image on a page via PDE or other methods?
andrejusc Sep 5, 2008 6:40 AM (in response to andrejusc)Well, probably. But this is not problem for me right now. Right now I have this situation:
Inside Contents stream I have this initial line (for some path inside there):
q 1 0 0 1 81.9438 161.4658 cm
Now I've saved that stream content into a file and changed this line to be:
q 1 0 0 1 101.9438 161.4658 cm
i.e. x transformation by 20.
Now I could on screen that my path is shifted right, but again as it was at the beginning of yesterday when I did similar with PDE layer - I have that path clipped. MediaBox and CropBox were both already enlarged to show whole area with shifted path.
So back to my original question - what else I should change to have that path not clipped??? -
23. Re: How to properly move image on a page via PDE or other methods?
(Leonard_Rosenthol) Sep 5, 2008 6:53 AM (in response to andrejusc)Look for something earlier in the stream that is clipping...
You aren't providing us with the PDF in question - we can only guess... -
24. Re: How to properly move image on a page via PDE or other methods?
andrejusc Sep 5, 2008 6:54 AM (in response to andrejusc)OK.
I was able finally to troubleshoot my problem!
The thing is in fact that path could have attached rectangle to it. In my case it was these 2 original lines:
0 226.772 170.079 -226.772 re
q 1 0 0 1 81.9438 161.4658 cm
Now, if I change only line with 'cm' to this one:
q 1 0 0 1 101.9438 161.4658 cm
then shifting works, but we get clipping and to have things moved together, we need change in line with 're' as well:
20 226.772 170.079 -226.772 re
NOW! I REALLY want to ask you guys why it doesn't work through PDEElementSetMatrix when I have PDEElement of type kPDEPath???
Well, it took almost 2 days to reach this point. Of course now I could do everything I need and even tweak streams the way I want. Good price for that knowledge :). -
25. Re: How to properly move image on a page via PDE or other methods?
andrejusc Sep 17, 2008 10:03 AM (in response to andrejusc)Hi,
After doing now a lot of things with Cos layer - I really want to ask you about PDE layer. Suppose I have such construction inside my Contents stream at the beginning:
/OC /MC0 BDC
q
0 226.772 170.079 -226.772 re
W n
q
1 0 0 1 81.9438019 161.4658051 cm
0.5 0.5 0.6 0.25 k
1 i
/GS0 gs
-skipped-
While enumerating it via PDE - I can't obtain that initial rectangle data via kPDEPath filtering of PDEElement. Is it supposed behaviour? I'm using Adobe Acrobat SDK 7.0.5. Initially I obtain that container PDEContent and then go through it.
Any comments would be appreciated. -
26. Re: How to properly move image on a page via PDE or other methods?
(Leonard_Rosenthol) Sep 17, 2008 10:43 AM (in response to andrejusc)That initial path is a clipping path - so it's handled differently. -
27. Re: How to properly move image on a page via PDE or other methods?
andrejusc Sep 17, 2008 11:07 AM (in response to andrejusc)Why then it's not enumerated via kPDEClip object type inside container's content?

