Answer the question
In order to leave comments, you need to log in
How to add a map with an index to a PDF file?
Question. I am using Java and iText to create a PDF. Is it possible to add a map with a pointer so that the user knows where the original point is?
Answer the question
In order to leave comments, you need to log in
What do you mean by "a map with a pointer so the user knows where the starting point is"? If the PDF contains a map, you can add an arrow annotation. Do you need exactly this?
I will give two examples.
This option 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();
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);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question