How to programmatically set highlights on a previewed file when using the "driveItem: preview" REST endpoint?

Daniel Díaz 20 Reputation points
2025-02-12T12:53:30.04+00:00

I'm using the driveItem: preview endpoint from the Microsoft Graph REST API https://learn.microsoft.com/en-us/graph/api/driveitem-preview?view=graph-rest-1.0 I'm embedding the getUrl field of the result in an iframe.

The file (a .docx file) is displayed correctly. But, in addition, I would like some of the text paragraphs in the file to appear highlighted. Is that possible?

At first sight, it doesn't seem to be possible. The preview endpoint request description doesn't seem to include any parameter that would allow for that. And the preview element itself seems to be a very "opaque" image that can't easily be targeted programmatically (for example using the CSS Custom Highlight API of modern browsers.)

Am I missing some possible solution that would allow me to highlight passages inside the previewed file?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,221 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 45,676 Reputation points
    2025-02-13T07:44:45.76+00:00

    Hi @Daniel Díaz

    You are correct that the driveItem: preview endpoint of the Microsoft Graph REST API does not currently support highlighting specific text paragraphs in the preview. The preview functionality is mainly used to generate a short-term embeddable URL to display the file content in an iframe, but it does not provide fine-grained control over the content, such as text highlighting.

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.