you’re welcome. Maybe you can share a code snippet with us when you’re done - 
would like to make it part of the documentation.

BR
Maruan Sahyoun

Am 17.02.2014 um 17:57 schrieb Nikos Chantziaras <[email protected]>:

> That should work nicely for finding character sequences and constructing 
> rectangle coordinates.
> 
> Thank you very much for the help!
> 
> 
> On 17/02/14 17:45, Maruan Sahyoun wrote:
>> Hi,
>> 
>> you can take a look at 
>> org.apache.pdfbox.examples.util.PrintTextLocations.java which gives you a 
>> sample of outputting the location of individual characters.
>> 
>> BR
>> Maruan Sahyoun
>> 
>> 
>> Am 17.02.2014 um 16:18 schrieb Nikos Chantziaras <[email protected]>:
>> 
>>> I've come up with a good way to insert color-filled rectangles through the 
>>> use of Overlay (so that they are rendered behind the text instead of the 
>>> front of it.)
>>> 
>>> However, how do I get the text coordinates? For example, I'd like to get 
>>> the coordinates for every occurrence of the word "mark me" so that I can 
>>> create a new PDDocument with filled rectangles and then overlay the 
>>> original over it. Currently, I have:
>>> 
>>>  PDDocument document = PDDocument.load("src.pdf");
>>>  PDDocument underContent = new PDDocument();
>>>  PDPage underPage = new PDPage();
>>>  PDPageContentStream contStrm = new PDPageContentStream(underContent,
>>>                                                         underPage);
>>>  contStrm.setNonStrokingColor(Color.yellow);
>>> 
>>>  contStrm.fillRect(/* Here I need the coordinates */);
>>> 
>>>  contStrm.close();
>>>  underContent.addPage(underPage);
>>> 
>>>  Overlay overlay = new Overlay();
>>>  overlay.overlay(document, underContent);
>>>  underContent.save("out.pdf");
>>>  underContent.close();
>>> 
>>> 
>>> On 17/02/14 13:52, Maruan Sahyoun wrote:
>>>> [...]
>>>> If you would like to make the highlight part of the PDF you could
>>>> create an annotation or draw a rectangle behind the text.
>>>> 
>>>> Steps would be a. find the text b. get the coordinates of the text c.
>>>> create an annotation or a rectangle around the coordinates
>>>> 
>>>> You could also use the information in the highlight xml file to get
>>>> the coordinates for the annotation/rectangle
>>>> 
>>>> Am 17.02.2014 um 12:09 schrieb Nikos Chantziaras <[email protected]>:
>>>> 
>>>>> It is not apparent how to save a PDF after I highlight some text in
>>>>> it. For example:
>>>>> 
>>>>> PDDocument doc = PDDocument.load("source.pdf"); PDFHighlighter hl =
>>>>> new PDFHighlighter(); java.io.FileWriter xml = new
>>>>> java.io.FileWriter("tmp.xml"); hl.generateXMLHighlight(doc, "450",
>>>>> xml);
>>>>> 
>>>>> How do I now save source.pdf (or a copy of it, if overwriting is
>>>>> not possible) with the text highlighted?
>> 
>> 
> 

Reply via email to