How to add a map with a pointer in the PDF file?

Question. I am using Java and iText to create a PDF file. Is it possible to add a map with a pointer to let the user know where is the original point?
March 23rd 20 at 18:51
1 answer
March 23rd 20 at 18:53
What do you mean by "a map with a pointer to let the user know where is the original point"? If the PDF file has a map you can add annotation arrows. This is what you need?
Here are two examples.
Example 1: adding a custom form as additional content on top of maps
This option is illustrated in example AddPointer:
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 you know the coordinates, you can draw lines and curves, the red indicator like the picture below (the red indicator near Cambridge Innovation Center):
5cf4c9bc2298e260188495.png
Map with pointer

Example 2: add string annotations over the map
This option is illustrated in example AddPointerAnnotation:
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);

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

Le PdfArray = 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 abstract (it is part of the not real content, but the interactive layer is superimposed on top of the real content):
5cf4ca5a5edc9578161343.png
Map annotation

Layer is interactive: when the user clicks on the annotation an additional information:
5cf4ca951dde8997489097.png
Map is an open annotation

Find more questions by tags iTextPDF.NETJava