2

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?

Clarification (from a meanwhile deleted answer by the OP which should have been an edit of the question)

my problem is can i add at iText google map from web and not as an image

mkl
  • 90,588
  • 15
  • 125
  • 265
  • Please clarify. 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? – Bruno Lowagie Nov 05 '14 at 08:34
  • *can i add at iText google map from web and not as an image* - How else? Please don't only say what you **don't** want but instead what you **do** want. – mkl Nov 06 '14 at 09:21

1 Answers1

1

Since you didn't answer my counter-question added in comment, I'm providing you 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:

PdfContentByte canvas = writer.getDirectContent();
canvas.setColorStroke(BaseColor.RED);
canvas.setLineWidth(3);
canvas.moveTo(220, 330);
canvas.lineTo(240, 370);
canvas.arc(200, 350, 240, 390, 0, (float) 180);
canvas.lineTo(220, 330);
canvas.closePathStroke();
canvas.setColorFill(BaseColor.RED);
canvas.circle(220, 370, 10);
canvas.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):

enter image description here

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

This is demonstrated in the AddPointerAnnotation example:

Rectangle rect = new Rectangle(220, 350, 475, 595);
PdfAnnotation annotation = PdfAnnotation.createLine(writer, rect, "Cambridge Innovation Center", 225, 355, 470, 590);
PdfArray le = new PdfArray();
le.add(new PdfName("OpenArrow"));
le.add(new PdfName("None"));
annotation.setTitle("You are here:");
annotation.setColor(BaseColor.RED);
annotation.setFlags(PdfAnnotation.FLAGS_PRINT);
annotation.setBorderStyle(
    new PdfBorderDictionary(5, PdfBorderDictionary.STYLE_SOLID));
annotation.put(new PdfName("LE"), le);
annotation.put(new PdfName("IT"), new PdfName("LineArrow"));
writer.addAnnotation(annotation);

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):

enter image description here

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

enter image description here

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

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165