import Global from '../../_global.mdx';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# file convert pdf

Converts the specified file to PDF using Microsoft Graph

## Usage

```sh
m365 file convert pdf [options]
```

## Options

```md definition-list
`-s, --sourceFile <sourceFile>`
: Local path or full URL to the source file to be converted to PDF

`-t, --targetFile <targetFile>`
: Local path or full URL to where the generated PDF file should be saved
```

<Global />

## Remarks

To convert a local file to PDF, CLI will temporarily upload the file to a document library. If you're using app-only authentication, CLI will upload the file to the default document library in the root site collection on your tenant. If you're authenticated as a user, CLI will upload the file to the default document library in your OneDrive for Business. After the conversion, CLI will remove the uploaded file.

If you choose to store the converted file in a document library, CLI will store the converted PDF file temporarily in the temp folder on your computer. After the PDF file has been uploaded to the location you specified, CLI will remove the temporary file.

If the conversion process fails, CLI will attempt to clean up the temporary files (the source file uploaded to your tenant, if you're converting a local file to PDF, and the converted PDF file on your disk if you chose to upload the converted file to your tenant). If removing the temporary files fails, you will need to clean them up yourself. CLI will list the URL and/or path of the files to remove.

## Permissions

<Tabs>
  <TabItem value="Delegated">

  | Resource        | Permissions                     |
  |-----------------|---------------------------------|
  | Microsoft Graph | Files.ReadWrite, Sites.Read.All |

  </TabItem>
  <TabItem value="Application">

  | Resource        | Permissions                         |
  |-----------------|-------------------------------------|
  | Microsoft Graph | Files.ReadWrite.All, Sites.Read.All |

  </TabItem>
</Tabs>

## Examples

Converts local file to PDF and stores the converted file on the disk

```sh
m365 file convert pdf --sourceFile file.docx --targetFile file.pdf
```

Converts local file to PDF and uploads the converted file to a document library

```sh
m365 file convert pdf --sourceFile file.docx --targetFile "https://contoso.sharepoint.com/Shared Documents/file.pdf"
```

Converts file from a document library to PDF and saves the converted file to disk

```sh
m365 file convert pdf --sourceFile "https://contoso.sharepoint.com/Shared Documents/file.docx" --targetFile file.pdf
```

Converts file from a document library to PDF and saves the converted file to the same document library

```sh
m365 file convert pdf --sourceFile "https://contoso.sharepoint.com/Shared Documents/file.docx" --targetFile "https://contoso.sharepoint.com/Shared Documents/file.pdf"
```

## Response

The command won't return a response on success.
