This service provides DOCX to PDF conversion using Microsoft Graph API and OneDrive. It's built with Go and packaged as a Docker container for easy deployment.
- Convert DOCX documents to PDF format
- Utilizes Microsoft OneDrive for file processing
- RESTful API endpoints
- Docker support for easy deployment
- Environment-based configuration
- Docker installed on your system
- Microsoft Azure account
- Registered application in Azure AD with appropriate permissions
-
Go to Azure Portal
-
Navigate to Azure Active Directory
-
Register a new application:
- Select "New Registration"
- Name your application
- Select supported account types
- Click Register
-
Once registered, note down:
- Application (client) ID
- Directory (tenant) ID
- Create a new client secret and save its value
-
Configure API permissions in Azure Portal:
- Go to your app registration
- Select "API permissions"
- Click "Add a permission"
- Choose "Microsoft Graph"
- Select "Application permissions"
- Add the following permissions:
- Files.ReadWrite.All
- Sites.ReadWrite.All
- User.Read.All
- Click "Grant admin consent" for these permissions
Note: These permissions are required for the application to work with files and convert documents on behalf of users.
- Clone the repository:
git clone https://github.com/aaparin/msgraph-converter.git
cd msgraph-converter
- Copy the environment file:
cp .env.demo .env
- Update the .env file with your Azure credentials:
AZURE_CLIENT_ID=your_client_id
AZURE_CLIENT_SECRET=your_client_secret
AZURE_TENANT_ID=your_tenant_id
UPLOAD_DIRECTORY=Documents
SERVICE_PORT=8181
- Build the Docker image:
docker build -t msgraph-converter .
- Run the container:
docker run -p 8181:8181 --env-file .env msgraph-converter
Alternatively, you can run on a different port:
docker run -p 9000:8181 --env-file .env -e SERVICE_PORT=8181 msgraph-converter
GET http://localhost:8181/drives
Response example:
{
"drives": [
"b!36******"
]
}
You can select the desired drive and update it in your .env file.
POST http://localhost:8181/convert
Content-Type: multipart/form-data
Parameters:
file
: DOCX file to convert (required)
Response:
- PDF file in the response body
Example using curl:
curl -X POST -F "[email protected]" http://localhost:8181/convert --output result.pdf
The API returns appropriate HTTP status codes and error messages:
- 400: Bad Request (invalid input)
- 401: Unauthorized (invalid credentials)
- 500: Internal Server Error (processing error)
- Ensure your .env file is not committed to version control
- The service should be deployed behind a reverse proxy in production
- Use HTTPS in production environments
- Regular updates of dependencies are recommended
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.