A microservice that converts docx
files to pdf
files and stores the converted file as a derived-file
in the database. This microservice uses Microsoft's Graph API to convert the DOCX files by uploading the DOCX files to OneDrive and afterwards downloading them as a PDF. Because of this, an Azure application is required to run this service.
Add the following snippet to your docker-compose.yml
file to include the DOCX conversion service in your project.
docx-conversion:
image: kanselarij/docx-conversion-service
volumes:
- ./data/files:/share
Add rules to the dispatcher.ex
to dispatch requests to the DOCX conversion service.
match "/files/:id/convert" do
Proxy.forward conn, [], "http://docx-conversion/files/" <> id <> "/convert"
end
The following environment variables are required for this service to work:
TENANT_ID
[string]: The tenant ID of the Azure Active Directory where the application existsCLIENT_ID
[string]: The client ID of the Azure applicationCLIENT_SECRET
[string]: The client secret of the Azure applicationSITE_ID
[string]: The id of the Sharepoint site that will be used The following environment variables can be optionally configured:MU_APPLICATION_FILE_STORAGE_PATH
[string]: The path where you want to store the converted PDF files. It will but a subpath from/share/
(defaultconverted-docx
)FILE_RESOURCE_BASE_URI
[string]: The base of the URI for new file resources (defaulthttp://themis.vlaanderen.be/id/bestand/
)FILE_JSONAPI_TYPE
[string]: The JSON:API type of file resources which is used when generating a JSON:API response (defaultfiles
)
Request the conversion of the DOCX file to PDF.
On successful conversion of the provided file, with the following body containing the ID of the newly created converted file:
{
"data": [
{
"attributes": {
"uri": "http://themis.vlaanderen.be/id/bestand/$ID"
},
"id": "$ID",
"type": "files"
}
]
}
For development on this service, it's useful to know about the Microsoft Graph API. The following should help with that:
- Microsoft Graph API Reference
- Uploading a file using an upload session
- Download a file in another format
- Delete a file
Your Azure application requires the following application permissions:
Sites.Selected
If you don't have access to an existing Azure application, Microsoft has a Developer Program that gives you access to a free Azure Active Directory and an Office administrator account, so that you can create the necessary application and user. For a detailed explanation check this tutorial.