-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow conversion of docx files to pdf using a new convert endpoint
- Loading branch information
1 parent
ec30ac6
commit 01a8bd5
Showing
6 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/adfinis/document-merge-service) | ||
[![License: GPL-3.0-or-later](https://img.shields.io/github/license/adfinis/document-merge-service)](https://spdx.org/licenses/GPL-3.0-or-later.html) | ||
|
||
A document template merge service providing an API to manage templates and merge them with given data. | ||
A document template merge service providing an API to manage templates and merge them with given data. It can also be used to convert Docx files to PDF. | ||
|
||
## Installation | ||
|
||
|
@@ -53,6 +53,13 @@ After uploading successfully, you can merge a template with the following call: | |
curl -H "Content-Type: application/json" --data '{"data": {"test": "Test Input"}}' http://localhost:8000/api/v1/template/test-template/merge/ > output.docx | ||
``` | ||
|
||
### Converting a template | ||
To convert a standalone Docx file the following call can be used: | ||
|
||
```bash | ||
curl -X POST --form [email protected] --form target_format="pdf" http://localhost:8000/api/v1/convert > example.pdf | ||
``` | ||
|
||
|
||
## Further reading | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
from django.urls import reverse | ||
from rest_framework import status | ||
|
||
from document_merge_service.api.data import django_file | ||
|
||
|
||
# @pytest.mark.parametrize("template__description", ["test description"]) | ||
@pytest.mark.parametrize( | ||
"target_format,response_content_type", | ||
[ | ||
("pdf", "application/pdf"), | ||
], | ||
) | ||
def test_convert(db, client, template, target_format, response_content_type): | ||
url = reverse("convert") | ||
file_to_convert = django_file("docx-template-syntax.docx") | ||
|
||
data = {"file": file_to_convert.file, "target_format": target_format} | ||
response = client.post(url, data=data, format="multipart") | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
assert response.headers.get("Content-Type") == response_content_type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters