[EMAIL PROTECTED] wrote:
Hi folks,my task is to highlight/mark text passages in pdf files.The coordinates/rectangles of the lines in user space coordinates are known.
You have given two interesting ways to solve this:
I did not figure out the semantic difference of the parameters rectangle and the floating point quad.
Quadpoints are defined as "An array of 8 × n numbers specifying the coordinates of n quadrilaterals in default user space. Each quadrilateral encompasses a word or group of contiguous words in the text underlying the annotation. The coordinates for each quadrilateral are given in the order x1 y1 x2 y2 x3 y3 x4 y4 specifying the quadrilateral’s four vertices in counterclockwise order. The text is oriented with respect to the edge connecting points (x1 , y1) and (x2 , y2)." To be honest, I've tried applying this 'definition,' and I must be missing something because the result is odd (see attachment). First let's translate the definition into human language: a rectangle can be define by its lower left coordinate (llx, lly) and its upper right coordinate (urx, ury). The other coordinate are implied: (ulx, uly) and (lrx, lry). If you'd translate such a rectangle into quadpoints, you'd need llx, lly, lrx, lry, urx, ury, ulx, uly (4 corners, ordered counter clockwise). That's what I did in the example that is attached, but... When I open the PDF in Adobe Reader, the highlighted part isn't a rectangle; it's some other strange shape. I've looked inside the PDF and I've added some comment to the annotation dictionary: << /C[1 1 0] # yellow /F 4 # print the annotation /Contents() # no content for the annotation /Subtype/Highlight # highlight (not underline or strikeout) /Rect[35 785 78 798] /QuadPoints[35 785 78 785 78 798 35 798] >> That looks OK to me, but maybe it's too early in the morning and maybe I'm missing something.
Another way to emphasize the text would be to draw the line rectangles and set the background color inside; or just draw lines that it looks like the text is underlined text.
That's another possibility. The main difference is that working with annotations (createMarkup) will make it easier for the end user to remove the highlight/underline/strikeout markup than adding the same to the content stream with PdfContentByte. So it depends on your requirement: - it has to be easy to remove the highlighting: use createMarkup (if we get it to work) - it should be difficult: use PdfContentByte and draw the rectangles -- This answer is provided by 1T3XT BVBA
markup.pdf
Description: Adobe PDF document
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfAnnotation;
import com.lowagie.text.pdf.PdfWriter;
public class MarkupExample {
public static void main ( String[] args ) throws IOException,
DocumentException
{
Document document = new Document () ;
PdfWriter writer = PdfWriter.getInstance ( document, new
FileOutputStream ( "markup.pdf" ) ) ;
document.open () ;
document.add(new Paragraph("markup"));
Rectangle rect = new Rectangle(35, 785, 78, 798);
float[] quad = { 35, 785, 78, 785, 78, 798, 35, 798 };
PdfAnnotation highlight = PdfAnnotation.createMarkup(writer, rect,
null, PdfAnnotation.MARKUP_HIGHLIGHT, quad);
highlight.setColor(Color.YELLOW);
highlight.setFlags(PdfAnnotation.FLAGS_PRINT);
writer.addAnnotation(highlight);
document.close () ;
}
}
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Do you like iText? Buy the iText book: http://www.1t3xt.com/docs/book.php Or leave a tip: https://tipit.to/itexttipjar
