Hello Diane,
See the Annotation.java example in the 1.8 source code download. Re
PDGamma, you can keep the default (i.e. "new PDGamma()") which is 0 0 0
i.e. black.
You need the part that has "txtLink".
So you need this:
PDBorderStyleDictionary borderULine = new
PDBorderStyleDictionary();
borderULine.setStyle(PDBorderStyleDictionary.STYLE_UNDERLINE);
borderULine.setWidth(inch/72); // 1 point
PDAnnotationLink txtLink = new PDAnnotationLink();
txtLink.setBorderStyle(borderULine);
position = new PDRectangle();
position.setLowerLeftX(...);
position.setLowerLeftY(...);
position.setUpperRightX(...);
position.setUpperRightY(...);
txtLink.setRectangle(position);
// add an action
PDActionURI action = new PDActionURI();
action.setURI("http://www......");
txtLink.setAction(action);
annotations.add(txtLink);
Trick to get the coordinates: run the 2.0.11 PDFDebugger and open your
existing PDF file. Move the mouse at the rectangle positions (lower left
and upper right) and you'll see the positions at the status line.
The rectangle is the "hot" area, i.e. the one where the link would be
launched.
Note that the link annotation is just the underline and the "effect". To
output the text, you need to write into the content stream as usual.
Tilman
Am 04.10.2018 um 15:07 schrieb Haddy, Diane E:
Hello Tillman
We are using the 1.8.10.jar and I created the pdf from scratch. My pdf is
complete and at the last minute the end user requested the link close to top of
the page. Can I use the code sample I provided and tweak it? If I do use
the PDGamma class do I need to create a method to return a PDGamma object for
the color black? Any suggestions will be very helpful. Thank you too for the
explanation about coordinates.
Diane
-----Original Message-----
From: Tilman Hausherr <[email protected]>
Sent: Wednesday, October 03, 2018 11:09 PM
To: [email protected]
Subject: [External] Re: issue creating hyperlink in pdf
Hello Diane,
If you're just starting, then use 2.0.11 and not 1.8 from which this example is
coming. There get the 2.0.11 source download, there go to the example
subdirectory, and get AddAnnotations.java. Get it to run. If you get it
running, delete all that you don't need so that only one link annotation is
left.
If the annotation is to be black, then the color is
PDColor black = new PDColor(new float[] { 0, 0, 0 }, PDDeviceRGB.INSTANCE);
In RGB colorspace, the colors are red green blue and 0 0 0 is black and
1 1 1 is white. 1 0 0 is red. 1 1 0 is yellow.
In the gray colorspace, 0 is black and 1 is white.
The coordinates start at the bottom left. (unlike java imaging where it starts
at the top left).
An A4 Page is about 600 x 800. (this is not exact, it's probably more like 650
x 750)
Are you creating a PDF completely from scratch or do you need to modify an
existing PDF, i.e. just add the unline and the link destination?
Tilman
Am 03.10.2018 um 22:27 schrieb Haddy, Diane E:
Hello
I have a task to create a hyperlink on a pdf page. I googled and found some
code. I am not good with coordinates and do not know anything about pdfbox
PDGamma class and how to add the color black to the text. Can you please help
me?
CODE:
PDBorderStyleDictionary psd = new PDBorderStyleDictionary();
psd.setStyle(PDBorderStyleDictionary.STYLE_UNDERLINE);
PDAnnotationLink txtLink = new PDAnnotationLink();
txtLink.setBorderStyle(psd);
// txtLink.setColour(PDGamma colourBlack);
//add action
PDActionURI action = new PDActionURI();
action.setURI("http://mycode.here.com");
txtLink.setAction(action);
//populate the url using these coordinates
PDRectangle rec = new PDRectangle();
rec.setLowerLeftX(10);
rec.setLowerLeftY(20);
rec.setUpperRightX(100);
rec.setUpperRightY(10);
txtLink.setRectangle(rec);
page.getAnnotations().add(txtLink);
thank you,
Diane
Diane Haddy
Health Care Information Systems
Application Developer
________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the
Electronic Communications Privacy Act, 18 U.S.C. 2510-2521 and is intended only
for the use of the individual or entity to which it is addressed, and may
contain information that is privileged, confidential, and exempt from
disclosure under applicable law. If you are not the intended recipient, any
dissemination, distribution or copying of this communication is strictly
prohibited. If you have received this communication in error, please notify the
sender immediately and delete or destroy all copies of the original message and
attachments thereto. Email sent to or from UI Health Care may be retained as
required by law or regulation. Thank you.
________________________________
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the
Electronic Communications Privacy Act, 18 U.S.C. 2510-2521 and is intended only
for the use of the individual or entity to which it is addressed, and may
contain information that is privileged, confidential, and exempt from
disclosure under applicable law. If you are not the intended recipient, any
dissemination, distribution or copying of this communication is strictly
prohibited. If you have received this communication in error, please notify the
sender immediately and delete or destroy all copies of the original message and
attachments thereto. Email sent to or from UI Health Care may be retained as
required by law or regulation. Thank you.
________________________________
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]