Inserting comments into PDF stream - how?

  • Follow


I am creating a PDF stream manually (long story, don't ask) and when
debugging the resulting PDF by looking at the raw PDF stream, it would
be really handy if I could tell which parts of the PDF stream came
from which parts of my code, so I was trying to find some way to
insert comments into the PDF stream that I can see when looking at the
PDF contents, but don't affect the output when loading the PDF into
Reader etc..

I came up with this:
(my comment here) pop
which I thought would create a string object on the stack and then pop
it off, but this PDF code still confuses Adobe Reader.

Any suggestions on how I can insert stuff into the PDF stream that
doesn't affect Adobe Reader, but lets me distinguish different parts
of the PDF stream?

Thanks,
Chris
0
Reply Chris 6/16/2010 1:35:10 PM

In article <18d73941-e9dd-45d6-9036-
f62f3c1fc5ef@z13g2000prh.googlegroups.com>, 
chris.shearer.cooper@gmail.com says...

> from which parts of my code, so I was trying to find some way to
> insert comments into the PDF stream that I can see when looking at the
> PDF contents, but don't affect the output when loading the PDF into
> Reader etc..
> 
> I came up with this:
> (my comment here) pop
> which I thought would create a string object on the stack and then pop
> it off, but this PDF code still confuses Adobe Reader.

PDF doesn't have a pop operator, that's PostScript ;-)

 
> Any suggestions on how I can insert stuff into the PDF stream that
> doesn't affect Adobe Reader, but lets me distinguish different parts
> of the PDF stream?

Outside the stream you could use the comment character '%'. Inside 
streams you could use:

q
BT
Tr 3
(Your comment) Tj
ET
Q

This sequence saves the graphics state, starts a text sequence, sets the 
text rendering mode to 3 (neither stroke nor fill, invisible) 'shows' 
your comment, ends the text sequence and restores the graphics state.

Should have no side effects. Note, I'm assuming you won't emit this part 
way through a text block, you can't nest these, so you need to know if 
you are already in a text block, in which case just don't emit BT/ET.

			Ken
0
Reply ken 6/16/2010 2:37:34 PM


On Jun 16, 4:35=A0pm, Chris Shearer Cooper
<chris.shearer.coo...@gmail.com> wrote:
> ...
> insert comments into the PDF stream that I can see when looking at the
> PDF contents, but don't affect the output when loading the PDF into
> Reader etc..
> ...

If by =91stream=92 you actually mean =91contents stream=92, I would go with=
:

    BX (comment text goes here) COMMENT EX

This works anywhere between =91complete commands=92; that is, take care
not to insert it between an operator and its operands, between
operands, or inside inline data.

BX/ EX delimit the so-called =91compatibility sections=92, meaning =91ignor=
e
any unrecognized operators, together with their operands=92. And,
=91COMMENT=92 is an unknown (non-existent) operator; your =91pop=92 should =
do
the job too (personally I find =91COMMENT=92 more descriptive).

There are other uses of streams in PDF, like image data, but I don=92t
think you will find any way to insert comments there.
0
Reply SaGS 6/16/2010 5:27:17 PM

On Jun 16, 6:35=A0am, Chris Shearer Cooper
<chris.shearer.coo...@gmail.com> wrote:
> I am creating a PDF stream manually (long story, don't ask) and when
> debugging the resulting PDF by looking at the raw PDF stream, it would
> be really handy if I could tell which parts of the PDF stream came
> from which parts of my code, so I was trying to find some way to
> insert comments into the PDF stream that I can see when looking at the
> PDF contents, but don't affect the output when loading the PDF into
> Reader etc..
>
> I came up with this:
> (my comment here) pop
> which I thought would create a string object on the stack and then pop
> it off, but this PDF code still confuses Adobe Reader.
>
> Any suggestions on how I can insert stuff into the PDF stream that
> doesn't affect Adobe Reader, but lets me distinguish different parts
> of the PDF stream?
>
> Thanks,
> Chris

Hi Chris, could you shed more light on your debugging method and tools
you would use to carry it out ?

I want to debug why pdftk.exe doesnt uncompress all streams of a
certain pdf file I have. If I substitute some text by replacement
text, using acrobat, foxit or infix, then it would uncompress the
stream. Its very finicky. I want to know if multivalent is any better.

Thanks
0
Reply bolega 6/24/2010 6:17:22 AM

3 Replies
437 Views

(page loaded in 0.072 seconds)

Similiar Articles:













7/21/2012 2:12:20 AM


Reply: