0

I'm looking at creating an appearance stream for annotation of type markup highlight by applying raw commands and writing them to output stream. However, I could not pinpoint which correct classes to use.

And so far, I could not find a post on how to do it.

This is what I have.

ByteArrayOutputStream os = new ByteArrayOutputStream();
os.write("/Form Do".getBytes("ISO_8859_1"));
os.write("other commands to draw highlighted rectangle coordinates");

PdfStream stream = pdfAppearance.getFormXObject(0);
stream.writeContent(os);

Or are there any other classes involved needed for writing raw commands.

And correct me if I am wrong but it looks like drawing the rectangle coordinates in the PdfAppearance will have no effect since there seems to be a form necessary where the rectangle fills are drawn instead.

Elydasian
  • 2,016
  • 5
  • 23
  • 41
chitgoks
  • 311
  • 2
  • 6
  • 17
  • Do you really want to create raw content stream bytes? Why not making use at least of iText classes to create the stream contents? That should prevent some unnecessary issues... – mkl Sep 27 '17 at 09:41
  • hi mkl. i did this using a different library and thought of doing the same in iText but I had no luck today trying to how to use PdfStream and PdfFormXObject. – chitgoks Sep 27 '17 at 10:01
  • 1
    You might want to look at [this answer](https://stackoverflow.com/a/33959759/1729265). Near its bottom there is a section titles **Making it work with annotations**; in it there is a method `highlightPDFAnnotation` in which a `PdfAppearance appearance` is generated for a `PdfAnnotation highlight`, and you can see how an extended graphics state is set in it and then a rectangle is filled. Admittedly, that example is in C# using iText for .Net but the differences mostly are the capitalization of the initial method name character and Java getters and setters corresponding to C# properties. – mkl Sep 28 '17 at 10:44
  • hi mkl. thank you. i have seen that before but i did not get it to work before. now it does. seemed that i used the wrong quad values to draw the rectangle. I think i am contented with this for now. Acrobat's text highlight have some curves on the sides. the math for that is beyond me. or does it perhaps have some setting in the PdfGState to make it render like that? – chitgoks Oct 02 '17 at 05:09
  • *"or does it perhaps have some setting in the PdfGState to make it render like that?"* - No, you either have to draw those curves yourself or you have to not fill a rectangle but instead draw a thick line selecting round line caps. – mkl Oct 24 '17 at 10:34

0 Answers0