Share via

How best to generate a pdf from a generated word doc, as a back-end process using graphapi

SV 0 Reputation points
2025-10-15T22:57:17.9766667+00:00

We have Contract system where we generate a contract as a word doc and then we also want to generate a pdf from the word doc, without having to open the docx in Word.

What options we have using graph api

Microsoft 365 and Office | Word | For business | Other
0 comments No comments

2 answers

Sort by: Most helpful
  1. Piyush Rana 385 Reputation points
    2025-10-18T07:02:12.58+00:00

    You can easily generate a PDF from a Word document in the backend using Microsoft Graph API without opening Word manually. If your contract files are stored in OneDrive or SharePoint Online, Graph can do the conversion directly with a simple REST call.

    How it works

    • Upload or save the generated .docx file to OneDrive or SharePoint.
    • Use the Graph API endpoint:
    GET /drives/{drive-id}/items/{item-id}/content?format=pdf
    
    • This returns the PDF version of the Word file that you can either stream or download to your system.

    Sample Request

    GET https://graph.microsoft.com/v1.0/me/drive/root:/Contracts/Contract123.docx:/content?format=pdf
    Authorization: Bearer {access_token}
    

    This downloads the same document as a PDF file.

    Requirements

    • The document must be in OneDrive or SharePoint.
    • You need proper Graph API permissions like Files.Read or Files.ReadWrite.All.
    • Works best for automated, server-side conversions where you already handle document creation.

    Resources

    • Convert to other formats - Microsoft Graph v1.0 – Official docs endpoint reference.
    • How to convert Office documents to PDF with Microsoft Graph – Step-by-step guide using Graph and Azure Functions.
    • Graph API – Community example for SharePoint-hosted files.

    If you prefer automation, you can even wrap this Graph call in an Azure Function to trigger automatically after generating the Word document.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. Anonymous
    2025-10-16T02:28:52.6333333+00:00

    Dear @SV,

    Welcome to Microsoft Q&A Forum! 

    Thank you for your inquiry regarding converting Word documents to PDF without manually opening them in Microsoft Word. Therefore, I have tried my best to research and found the supported option based on Microsoft’s official document: 

    You can try using Microsoft Graph API (Cloud-Based). If your Word documents are stored in OneDrive or SharePoint Online, you can use the Microsoft Graph API to convert them directly to PDF. Here are several benefits of it: 

    • You do not need to open Word manually. 
    • It is fully automated via REST API. 
    • It is ideal for cloud-based contract systems. 
    • Supports .docx, .doc, .pptx, .xlsx, .rtf, and more. 

    However, it has some limitations that you should know: 

    • Only works with files stored in OneDrive or SharePoint Online. 
    • Requires Microsoft 365 licensing and Graph API permissions (Files.Read, Sites.Read.All, etc.). 

    I have examples API call: 

    GET /drive/items/{item-id}/content?format={format}
    GET /drive/root:/{path and filename}:/content?format={format}
    

    This endpoint returns the PDF version of the document directly. 

    You can consult in this link for more details: Convert to other formats - Microsoft Graph v1.0 | Microsoft Learn 

    Additionally, I would like to clarify the local file conversion (outside Microsoft 365 or SharePoint): 

    If your Word documents are stored locally and not in OneDrive or SharePoint, Microsoft Graph API does not support direct conversion. In such cases, I have found this idea during my research, you may consider using Power Automate to automate local conversion. You can consult more in here: Doc To PDF - Connectors | Microsoft Learn 

    I hope this information can help you and please kindly correct me if I misunderstand your concern. Wish you a pleasant day! 


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

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 

    Was this answer helpful?

    1 person found this answer helpful.

Your answer

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