Skip to content

Commit

Permalink
Update readme to add example for latex compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhanmirza committed Jan 12, 2024
1 parent 49782f4 commit 7881d46
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Binary file added Doc/example-latex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SpringBooTex will run as an REST service by default on port 10800;
PDF's are generated by sending an HTTP POST request to the endpoint "/api/generate-pdf" with a JSON payload:
```
{
"templateType": "LATEX | HTML",
"templateType": "LATEX | HTML",
"templateSourceType": "BASE64",
"templateSource": "TEMPLATE_SOURCE",
"stringMap": { KEY_VALUE_MAP },
Expand All @@ -26,7 +26,58 @@ PDF's are generated by sending an HTTP POST request to the endpoint "/api/genera

#### Example: Generating a PDF from latex template

https://github.com/shuhanmirza/SpringBooTex/blob/9527c95cc7a7d11a53784f0b2071b6f9c7fcc679/Doc/example.tex#L1-L10
See our example LaTex template in [`Doc/example.tex`](https://github.com/shuhanmirza/SpringBooTex/blob/main/Doc/example.tex)

You can see that, the variables are written between two `%` s.
https://github.com/shuhanmirza/SpringBooTex/blob/49782f4cdd94a3e620f92739f7b37f381c3d77c0/Doc/example.tex#L12-21

And the pdf has to embed an image named `universe.jpg`
https://github.com/shuhanmirza/SpringBooTex/blob/49782f4cdd94a3e620f92739f7b37f381c3d77c0/Doc/example.tex#L37-38

Let's prepare the JSON payload,

Now, encode the latex template to base64 by running:
```bash
cat example.tex | base64
```
Which gives output:
```
XGRvY3VtZW50Y2xhc3NbYTRwYXBlciwxMXB0XXthcnRpY2xlfQpcdXNlcGFja2FnZXtncmFwaGljeH0KXHVzZXBhY2thZ2VbZW1wdHlde2Z1bGxwYWdlfQpcdXNlcGFja2FnZXtoeXBlcnJlZn0KXGh5cGVyc2V0dXB7CiAgICBjb2xvcmxpbmtzPX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nlMaXN0KFxpKSA6IFxDaXR5TGlzdChcaSkKICAgIH0KXGVuZHtpdGVtaXplfQoKXGVuZHtkb2N1bWVudH0K
```

The JSON payload should look like this,
```json
{
"templateType": "LATEX",
"templateSourceType": "BASE64",
"templateSource": "XGRvY3VtZW50Y2xhc3NbYTRwYXBlciwxMXB0XXthcnRpY2xlfQpcdXNlcGFja2FnZXtncmFwaGljeH0KXHVzZXBhY2thZ2VbZW1wdHlde2Z1bGxwYWdlfQpcdXNlcGFja2FnZXtoeXBlcnJlZn0KXGh5cGVyc2V0dXB7CiAgICBjb2xvcmxpbmtzPXRydWUsCiAgICB1cmxjb2xvcj1ibHVlLAogICAgYnJlYWtsaW5rcz10cnVlCn0KXHVzZXBhY2thZ2V7YXJyYXlqb2J9Clx1c2VwYWNrYWdle211bHRpZG99CgpcbmV3Y29tbWFuZHtcZm9vZH17JUZPT0QlfQpcbmV3Y29tbWFuZHtcY2l0eX17JUNJVFklfQoKXG5ld2FycmF5XENvdW50cnlMaXN0ClxuZXdhcnJheVxDaXR5TGlzdAoKXHJlYWRhcnJheXtDb3VudHJ5TGlzdH17JUNPVU5UUllfTElTVCV9ClxyZWFkYXJyYXl7Q2l0eUxpc3R9eyVDSVRZX0xJU1QlfQpcbmV3Y29tbWFuZHtcTGlzdFNpemV9eyVMSVNUX1NJWkUlfQoKClx0aXRsZXtTcHJpbmdCb29UZXggRXhhbXBsZX0KXGRhdGV7fQpcYmVnaW57ZG9jdW1lbnR9CgpcbWFrZXRpdGxlCgpcc2VjdGlvbntTaW5nbGUgVmFyaWFibGV9CgpJIGFtIGZyb20gXGNpdHkuIEkgbG92ZSBlYXRpbmcgXGZvb2QuCgpcc2VjdGlvbntJbWFnZX0KVGhpcyBpbWFnZSB3YXMgZG93bmxvYWRlZCBmcm9tIFxocmVme2h0dHBzOi8vdXBsb2FkLndpa2ltZWRpYS5vcmcvd2lraXBlZGlhL2NvbW1vbnMvdGh1bWIvMi8yZi9IdWJibGVfdWx0cmFfZGVlcF9maWVsZC5qcGcvMTAyNHB4LUh1YmJsZV91bHRyYV9kZWVwX2ZpZWxkLmpwZ317V2lraXBlZGlhfQoKXHZzcGFjZXsxY219ClxpbmNsdWRlZ3JhcGhpY3Nbc2NhbGU9MC4yXXt1bml2ZXJzZS5qcGd9Cgpcc2VjdGlvbntBcnJheX0KCkxpc3Qgb2YgQ291bnRyaWVzIGFuZCB0aGVpciBDYXBpdGFscwoKXGJlZ2lue2l0ZW1pemV9CiAgICBcbXVsdGlkb3tcaT0xKzF9e1xMaXN0U2l6ZX17CiAgICAgICAgXGl0ZW0gXENvdW50cnlMaXN0KFxpKSA6IFxDaXR5TGlzdChcaSkKICAgIH0KXGVuZHtpdGVtaXplfQoKXGVuZHtkb2N1bWVudH0K",
"stringMap": {
"FOOD": "Birun Vaat",
"CITY": "Sylhet",
"LIST_SIZE": "3"
},
"listMap" : {
"COUNTRY_LIST" : [
"Bangladesh",
"United States",
"United Kingdom"
],
"CITY_LIST" : [
"Dhaka",
"Washington DC",
"London"
]
},
"fileUrlMap": {
"universe.jpg": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Hubble_ultra_deep_field.jpg/1024px-Hubble_ultra_deep_field.jpg"
},
"responseType": "PDF"
}
```


And the generated PDF is
![example-latex.pdf](Doc/example-latex.png)


## Contributing
Expand Down

0 comments on commit 7881d46

Please sign in to comment.