https://github.com/carboneio/carbone-sdk-go
Golang SDK to generate documents (PDF DOCX ODT XLSX ODS XML ...) with the Carbone Cloud API
https://github.com/carboneio/carbone-sdk-go
document-conversion docx go golang libreoffice multilingual pdf pdf-generation report-generator sdk template-engine
Last synced: about 1 month ago
JSON representation
Golang SDK to generate documents (PDF DOCX ODT XLSX ODS XML ...) with the Carbone Cloud API
- Host: GitHub
- URL: https://github.com/carboneio/carbone-sdk-go
- Owner: carboneio
- License: apache-2.0
- Created: 2020-05-18T15:27:46.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-09-14T09:22:41.000Z (over 2 years ago)
- Last Synced: 2025-11-22T14:52:47.279Z (3 months ago)
- Topics: document-conversion, docx, go, golang, libreoffice, multilingual, pdf, pdf-generation, report-generator, sdk, template-engine
- Language: Go
- Homepage: https://carbone.io
- Size: 103 KB
- Stars: 9
- Watchers: 5
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Carbone Cloud API Go SDK

[](./API-REFERENCE.md)
The golang SDK to request the Carbone Cloud API easily.
> Carbone is a document generator (PDF, DOCX, XLSX, ODT, PPTX, ODS, XML, CSV...) using templates and JSON data.
[Learn more about the Carbone ecosystem](https://carbone.io/documentation.html).
### 🔖 [API REFERENCE](./API-REFERENCE.md)
## Install
```sh
go install github.com/carboneio/carbone-sdk-go@latest
```
## Usage
You can copy and run the code bellow to try.
```go
package main
import (
"io/ioutil"
"log"
"github.com/carboneio/carbone-sdk-go/carbone"
)
func main() {
// SDK constructor
// The access token can be passed as an argument to NewCarboneSDK
// Or by the environment variable "CARBONE_TOKEN", use the command "export CARBONE_TOKEN=secret-token"
csdk, err := carbone.NewCarboneSDK("secret-token")
if err != nil {
log.Fatal(err)
}
// The template ID
templateID := "template"
// Data injected into the template to generate the report with Carbone
jsonData := `{"data":{"id":42,"date":1492012745,"company":{"name":"myCompany","address":"here","city":"Notfar","postalCode":123456},"customer":{"name":"myCustomer","address":"there","city":"Faraway","postalCode":654321},"products":[{"name":"product 1","priceUnit":0.1,"quantity":10,"priceTotal":1}],"total":140},"convertTo":"pdf"}`
// Render and return the report as []byte
reportBuffer, err := csdk.Render(templateID, jsonData)
if err != nil {
log.Fatal(err)
}
// Create the file
err = ioutil.WriteFile("Invoice.pdf", reportBuffer, 0644)
if err != nil {
log.Fatal(err)
}
}
```
## Documentation
- [API REFERENCE](./API-REFERENCE.md)
## Run tests
First, Go to the `carbone` package directory.
```bash
$ cd carbone
```
To run all the tests (-v for verbose output):
```bash
$ go test -v
```
To run only one test:
```bash
$ go test -v -run NameOfTheTest
```
If you need to test the generation of templateId, you can use the nodejs `main.js` to test the sha256 generation.
```bash
$ node ./tests/main.js
```
## 👤 Author
- [**@steevepay**](https://github.com/steevepay)
## 🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/carboneio/carbone-sdk-go/issues).
## Show your support
Give a ⭐️ if this project helped you!