|Syntactic Confectionery Delight|
Re^5: PDF Document Level Scriptby vr (Curate)
|on Jan 11, 2018 at 17:42 UTC ( #1207124=note: print w/replies, xml )||Need Help??|
For some reason, I'm not sure that's the way CAM::PDF was meant to be used...
:-) Maybe not. Here I formatted your code a little, to be able to read it:
It's good you found solution that works for your template, and I understand (you said it yourself) this code wasn't meant to be universal. And yet, it wasn't necessary to make so many assumptions.
In 1st line, node's type is assumed to be 'reference' (i.e., it's indirect object in PDF structure). In 2nd line it's assumed to be direct object, in this case node's type is 'dictionary', which dictionary has an entry keyed by 'a_key' which (entry), in turn, is assumed to be indirect object, i.e. that node's type assumed as 'reference'! Don't do that. Consider:
If node's type is 'reference', then these 2 lines return same result. But, not only 2nd line is shorter, it will also work for direct objects, i.e. if node's type is dictionary, array, number, etc. In fact, I don't remember to ever use the getObjValue.
These 2 lines produce the same result :-) (i.e., if node's type is 'reference'). But of course it's better to add new stream using designated method, then it won't be necessary to hack the 'Length' property (it will be added automatically).
In Section Seekers of Perl Wisdom