I am using java and iText to create a pdf. Is it possible to add a map with a pointer on it so the user will know where the starting point is?

Posted on StackOverflow on Nov 6, 2014 by user2487493

What do you mean by "a map with a pointer so the user knows where the starting point is"? If you have a map in your PDF, you could add an annotation that looks like an arrow. Is that what you're looking for?

Since you didn't answer my counter-question added in comment, I'm providing two examples. If these are not what you're looking for, you really should clarify your question.

Example 1: add a custom shape as extra content on top of a map

This is demonstrated in the AddPointer example:

PdfCanvas canvas = new PdfCanvas(pdfDoc.getFirstPage());
canvas.setStrokeColor(Color.RED)
        .setLineWidth(3)
        .moveTo(220, 330)
        .lineTo(240, 370)
        .arc(200, 350, 240, 390, 0, (float) 180)
        .lineTo(220, 330)
        .closePathStroke()
        .setFillColor(Color.RED)
        .circle(220, 370, 10)
        .fill();

If we know the coordinates of the pointer, we can draw lines and curves that result in a the red pointer shown here (see the red pin near the Cambridge Innovation Center):

Map with a pin

Map with a pin

Example 2: add a line annotation on top of a map

This is demonstrated in the AddPointerAnnotation example:

Rectangle rect = new Rectangle(220, 350, 255, 245);
PdfLineAnnotation lineAnnotation = new PdfLineAnnotation(rect, new float[]{225, 355, 470, 590});
lineAnnotation.setTitle(new PdfString("You are here:"));
lineAnnotation.setContents("Cambridge Innovation Center");
lineAnnotation.setColor(Color.RED);
lineAnnotation.setFlag(PdfAnnotation.PRINT);

PdfDictionary borderStyle = new PdfDictionary();
borderStyle.put(PdfName.S, PdfName.S);
borderStyle.put(PdfName.W, new PdfNumber(5));
lineAnnotation.setBorderStyle(borderStyle);

PdfArray le = new PdfArray();
le.add(new PdfName("OpenArrow"));
le.add(new PdfName("None"));
lineAnnotation.put(new PdfName("LE"), le);
lineAnnotation.put(new PdfName("IT"), new PdfName("LineArrow"));

pdfDoc.getFirstPage().addAnnotation(lineAnnotation);

The result is an annotation (which isn't part of the real content, but part of an interactive layer on top of the real content):

Map with an annotation

Map with an annotation

It is interactive in the sense that extra info is shown when the user clicks the annotation:

Map with an annotation that has been opened

Map with an annotation that has been opened

Many other options are possible, but once again: your question wasn't entirely clear.

Click How to add a map with a pointer to a PDF? if you want to see how to answer this question in iText 5.