Create a clickable icon (hyperlink on iconor image)

Hi ,

I want to create pdf file from a word file. In that i am adding some content along with I have to add a icon which is clickable and open a link. it will be lengthy and it should hide. content should be like

(paperclip icon) Attachment file name

here paperclip icon should be clickable with link. i have tried code below but icon is coming(not in proper place) and not clickable while opening in chrome (it automatically open in chrome whiling licking the download file)

public static void attachmentAsLink(DocumentBuilder builder, Resource resource, String attachmentTitle, PDFAttachmentsProtoDataVO attachmentsProtoDataVO, AsposePrintOptionVo printOptionVo, boolean firstAttachment) {
        try {
//            builder.getFont().setColor(Color.blue);
            builder.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
            if (firstAttachment) {
                builder.writeln();
                builder.getFont().setBold(true);
//            builder.getFont().setUnderline(Underline.SINGLE);
                builder.writeln("Below are the links to Attachment/s -");
                builder.getFont().setBold(false);
            }
            if (printOptionVo.getRequestFrom().equals(HttpRequestOrigin.ANNOTATION)) {
                addAttachmentAsHyperLink(builder, resource, attachmentTitle, printOptionVo.getUser());
            } else {
                addingAttachmentIconForTrackingLinkLocation(builder, resource, attachmentTitle, attachmentsProtoDataVO);
            }
        } catch (Exception e) {
            logger.error("error while adding attachment hyperlink for attachment title: {} and the resource path: {}",
                    CRLFCustomCleanser.replaceCRLF(attachmentTitle),
                    CRLFCustomCleanser.replaceCRLF(resource.getPath()),
                    e);

        }
    }

can you please hemp me generate proper code for open the link both in adobe reader and chrome browser and current the position.
NOTE: attachment will be more that one and it will be printed each line and each will have a different link with paper clip icon

Thank you
Geethu P

@Gptrnt

Based on limited evidence (treat as hypothesis), here is a cautious take:
Summary of what is happening:

  • I could not confirm a documented solution for this scenario yet.

Why it matters:

  • Nothing in the current knowledge base matches this scenario, so proposing specific settings would be guesswork.
  • To avoid misleading guidance, I prefer to pause instead of speculating.

Next steps: please share a minimal repro (HTML/PDF snippet, SDK and version). I’ll check against the latest docs and release notes.

Assumptions / confirmations needed: SDK + version, file types, minimal sample, and exact error/output.

@Gptrnt You can use the following code to insert image with a clickable link:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
        
// Insert image and assign a link to it.
Shape s = builder.insertImage("C:\\Temp\\test.png");
s.setHRef("https://metrics.aspose.com/");
        
doc.save("C:\\Temp\\out.pdf");

Hi,

SESL_Board Meeting_agenda (90).pdf (81.9 KB)

i am trying with below code and getting the output like paper clip is overlapping with attchment name.

private static void addAttachmentAsHyperLink(
            DocumentBuilder builder,Resource resource,
            String attachmentTitle,
            User user) throws Exception {

                String secureUrl = AppConfiguration.getDefaultPropertyAsString(BASE_URL_KEY) + "cimplyfive/apis/secure-file?token="
                + user.getLinkToken() + "&path=" + resource.getPath();

        builder.startBookmark(attachmentTitle);

        builder.write(" ");
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setUnderline(Underline.SINGLE);

        // ---- Create image shape (paperclip icon) ----
        Shape imageShape = new Shape(builder.getDocument(), ShapeType.IMAGE);
        imageShape.getImageData().setImage(PAPER_CLIP_ICON_PATH);
        imageShape.setWidth(14);
        imageShape.setHeight(14);
        imageShape.setTarget("_blank");
        imageShape.setHRef(secureUrl);
        builder.insertNode(imageShape);
        builder.insertHyperlink(attachmentTitle, secureUrl, false);

        // Optional space + title text
        builder.endBookmark(attachmentTitle);
    }

if you try open the file in chorme browser it not clickable ( i have even adding the attchment title as hyperlink, it also now clickable

@Gptrnt

Summary
The paper‑clip icon is created as a floating Shape. A floating shape does not take part in the paragraph layout, therefore it can overlap the following text and the hyperlink (HRef) attached to the shape is not activated in the generated PDF. Insert the image as an inline shape and then add the hyperlink.

Why it happens

  • new Shape(builder.getDocument(), ShapeType.IMAGE) creates a floating image.
  • A floating shape is positioned independently of the surrounding runs, so it can cover the text that follows.
  • When the shape overlaps the text, many PDF viewers ignore the HRef that is set on the shape, so the icon is not clickable.

Fix

private static void addAttachmentAsHyperLink(
        DocumentBuilder builder, Resource resource,
        String attachmentTitle, User user) throws Exception {

    String secureUrl = AppConfiguration.getDefaultPropertyAsString(BASE_URL_KEY) +
            "cimplyfive/apis/secure-file?token=" + user.getLinkToken() +
            "&path=" + resource.getPath();

    // Insert the paper‑clip icon as an inline image
    Shape icon = builder.insertImage(PAPER_CLIP_ICON_PATH);
    icon.setWidth(14);
    icon.setHeight(14);
    icon.setWrapType(WrapType.INLINE);   // make it inline
    icon.setHRef(secureUrl);             // hyperlink on the icon
    icon.setTarget("_blank");

    // Space between the icon and the title (optional)
    builder.write(" ");

    // Insert the attachment title as a separate hyperlink (optional)
    builder.getFont().setColor(Color.BLUE);
    builder.getFont().setUnderline(Underline.SINGLE);
    builder.insertHyperlink(attachmentTitle, secureUrl, false);
}

Steps to verify

  1. Generate the document (PDF, DOCX, etc.) with the code above.
  2. Open the file in a PDF viewer that supports external links (e.g., Adobe Reader, Edge, Chrome).
  3. Click the paper‑clip icon – it should open the URL defined in secureUrl.

If the icon is still not clickable, provide a minimal reproducible sample (source code that creates the PDF and the resulting file) for further analysis.

:warning: Please validate this behaviour with your exact SDK version and a minimal repro, as support can vary by release.

@Gptrnt You can try changing shape text wrapping to inline:

imageShape.setWrapType(WrapType.INLINE);