Downloading Word files as PDF from SharePoint using Graph API loses sensitivity label

When it comes to downloading files from SharePoint Online using the Microsoft Graph SDK, there are a few things to keep in mind when it comes to sensitivity labels. In this blog post, we’ll explore why sensitivity labels may be lost when downloading files using the Graph SDK, and what you can do to retain these labels.

First, let’s take a look at the scenario described in the question:

“I have a word file in SharePoint Online document library, this file has Sensitivity label assigned to it. I am downloading this file using Graph SDK with query parameter ‘format=pdf’. The file is successfully downloaded and saved as pdf, however, the sensitivity labels are lost.”

In this scenario, the user is downloading a Word document from SharePoint Online using the Graph SDK, and specifying the format as PDF. However, when the file is downloaded, the sensitivity labels are lost. This can be frustrating, especially if the file contains confidential or sensitive information that needs to be protected.

So, why are the sensitivity labels lost when downloading files using the Graph SDK? The reason for this is that the PDF format does not natively support sensitivity labels. When the file is downloaded in PDF format, the sensitivity labels are not included in the download. This means that the labels are lost, and the file is saved without any protection.

However, there is a solution to this problem. If you need to retain sensitivity labels when downloading files using the Graph SDK, you can use a different format for the download, such as PDFA or ZIP. These formats do support sensitivity labels, so they will be included in the download.

To download a file using a different format, you can use the following query parameter:

‘format=pdf&output=pdfa’

This will force the Graph SDK to download the file in PDFA format instead of PDF. The ‘output’ parameter is used to specify the output format, and in this case, we are specifying PDFA as the output format.

Alternatively, you can also use the following query parameter to download the file in ZIP format:

‘format=pdf&output=zip’

This will force the Graph SDK to download the file in ZIP format instead of PDF. The ‘output’ parameter is used to specify the output format, and in this case, we are specifying ZIP as the output format.

So, what happens if you open the same file in a browser and click on “File –> Save as –> Download as PDF”? In this case, the sensitivity labels are retained because the file is downloaded in PDFA format, which supports sensitivity labels. The Graph SDK does not provide direct support for retaining sensitivity labels when downloading files, but by using a different output format, such as PDFA or ZIP, you can ensure that the labels are included in the download.

In conclusion, when downloading files from SharePoint Online using the Microsoft Graph SDK, it is important to keep in mind that the PDF format does not support sensitivity labels. To retain these labels, you can use a different output format, such as PDFA or ZIP. By doing so, you can ensure that your sensitive documents are protected and maintained their integrity.