Hello and thank you for the helpful response, and the great explanation of that
each of those commands do. I've read the PDF Reference but it's HUGE and a lot
of it is over my head, and most of it isn't applicable to what I need to do.
I've been trying to modify your code ... I get the general idea. However, there
are some basic problems with your approach with regards to what I need to do.
First, I don't think I can work at the Stream level, since the Ovals are
scattered all over the place, in different streams. Plus, I don't have a 'key'
to look for. What I need to do (I think) is to be able to get all Ovals and
then programmatically mark the 1st one ... the 5th one ... the 99th one, etc.
Is there any way to get all the 'Oval blocks' - the 6 lines, from '116.28
662.58 m' to 'b*' ? From the Dictionary? Catalog?
How would I add a new 'g operator' to the 'block' ?
I know what I am doing when working with the PDF as text but I would prefer NOT
to work that way (which is why I am trying to use iText) since 1) in order to
even begin working with a PDF as text I have to use PDFReader and PDFStamper to
turn it into text, and even doing that sometimes some streams aren't converted,
and 2) if I add anything it corrupts the document, forcing me to take the
corrupt document and use iText to read it and then write it to a new,
non-corrupt document.
Any help much obliged ...
>________________________________
> From: iText Info <i...@1t3xt.info>
>To: itext-questions@lists.sourceforge.net
>Sent: Thursday, August 2, 2012 12:38 PM
>Subject: Re: [iText-questions] How to mark ovals in a pdf
>
>
>Op 2/08/2012 12:17, Robert Bowen schreef:
>
>I have a ballot with a bunch of different contests (President, Vice-president,
>etc.) each with its candidates. Next to each candidate is an oval. I'd like to
>use iText to check a given oval for each contest.
>>
>>
>>The ovals are not within an AcroForm, and they are not checkboxes. I opened
>>my pdf with Acrobat and selected a random oval and they seem to be just
>>normal objects ... perhaps graphic objects, I'm not sure, I couldn't tell.
>>
>>
>>I used a combination of PDFReader, PDFStamper and Document to uncompress the
>>PDF, to be able to edit it in a normal text editor, and it seems that each
>>oval looks something like this:
>>
>>
>>01 g
>>>89.04 650.52 41.22 24 re
>>>f
>>>1 J 1 j 0.2 w 10 M
>>>1 i
>>>116.28 662.58 m
>>>116.28 664.56 112.44 666.12 107.7 666.12 c
>>>102.96 666.12 99.12 664.56 99.12 662.58 c
>>>99.12 660.6 102.96 658.98 107.7 658.98 c
>>>112.44 658.98 116.28 660.6 116.28 662.58 c
>>>b*
>>
>>
>>and if I manually add a '0 g' between '1 i' and '116.28 662.58 m', it marks
>>the oval. But if I write a program in Java to do this, to add '0 g' for each
>>oval, the resulting PDF is corrupt, because ... well, you can't just edit a
>>PDF like that, you have to update the stream, the dictionary, etc.
>>
>The path of the oval is defined using one moveTo (m) and four
curveTo (c) operators.
>The path is drawn using a closePathEoFillStroke command (b*).
>Close path means: add a path between start and end point if the
curves don't form a closed shape
>Eo means: use the Even-Odd algorithm to find out which areas need to
be filled.
>Fill means: fill the shape using the fill color
>Stroke means: draw the borders using the stroke color
>
>The fill color is defined with the g operator: 01 is the gray fill
value (0 is black, 1 is white).
>The line width is 0.2 user units (w), but I don't see any operator
defining the stroke color (maybe it's just the default: black).
>
>If you manually add "0 g" after "2 i", then the fill color will be
black, but you need to be very careful when doing so.
>If you're sure about the PDF syntax, then this is a code sample I
used to change the content of a form XObject.
>I'm sure you can adapt it to change the content stream of the page:
>
>// read file my.pdf
>PdfReader r = new PdfReader("my.pdf");
>// get page dictionary of page 1
>PdfDictionary p = r.getPageN(1);
>// get the resources
>PdfDictionary ps = p.getAsDict(PdfName.RESOURCES);
>// get the XObjects
>PdfDictionary xo = ps.getAsDict(PdfName.XOBJECT);
>// get the content stream of a specific XObject identified by key
>PRStream stream = (PRStream)xo.getAsStream(key);
>// change its content (in this case: empty the content)
>stream.setData(new byte[]{});
>// create a new (altered) PDF
>PdfStamper stamper = new PdfStamper(r, new
FileOutputStream("new.pdf"));
>stamper.close();
>
>With this code, the structure of your PDF will not be corrupted.
>However: if you use the wrong bytes, you can corrupt the content of
a page.
>Reading the syntax snippet however, I have the impression you know
what you're doing.
>
>------------------------------------------------------------------------------
>Live Security Virtual Conference
>Exclusive live event will cover all the ways today's security and
>threat landscape has changed and how IT managers can respond. Discussions
>will include endpoint security, mobile security and the latest in malware
>threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>_______________________________________________
>iText-questions mailing list
>iText-questions@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/itext-questions
>
>iText(R) is a registered trademark of 1T3XT BVBA.
>Many questions posted to this list can (and will) be answered with a reference
>to the iText book: http://www.itextpdf.com/book/
>Please check the keywords list before you ask for examples:
>http://itextpdf.com/themes/keywords.php
>
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php