Overview

Generating invoices on‑the‑fly is a common requirement for billing systems, e‑commerce platforms, and SaaS applications.
With GroupDocs.Assembly Cloud you can create professional invoices completely in the cloud without installing any office software on your servers.

Key benefits

  • Template flexibility – Design invoice layouts in a native editor like Microsoft Word, LibreOffice Writer, etc.
  • Dynamic data binding – Populate templates with JSON or XML data, using simple placeholders or advanced LINQ expressions for calculations, loops, and conditional sections.
  • Multiple output formats – Generate the final invoice as DOCX for further editing or as PDF for read‑only distribution.
  • Secure storage – Access templates and documents stored in GroupDocs Cloud via authentication tokens.
  • Lightweight environment – All processing runs on GroupDocs Cloud, freeing your infrastructure from third-party libraries or high CPU or memory requirements.

In the following sections we’ll walk through the whole process – from preparing a template and data source to generating an invoice with the .NET SDK using C# and with plain cURL commands.


Prepare Invoice Template

Design the invoice layout using your favourite desktop editor (Microsoft Word, LibreOffice Writer, etc.).
Insert placeholder tags that match the JSON fields you will provide later, for example:

TemplateJSON Path
<<[Invoice.Number]>>invoice.number
<<[Customer.Name]>>customer.name

And table rendering template definition will look like following:

DescriptionQuantityUnit PriceCost
<<foreach [in Items]>>
<<[Description]>>

<<[Quantity]>>

$<<[UnitPrice]:"N2">>
$<<[Quantity*UnitPrice]:"N2">>
<</foreach>>

For your convenience feel free to download a template example shown below:

invoice template example

Or build your own template to upload it to GroupDocs Cloud storage (next section).


Upload Template to Cloud Storage

Major steps for C# code

  1. Create a Configuration object with your App SID and App Key.
  2. Initialize the AssemblyApi client.
  3. Upload the local template file to a path in cloud storage (e.g. templates/invoice-template.docx).
// 1️⃣ Initialize the Cloud API configuration
var config = new Configuration
{
    AppSid = "YOUR_APP_SID",      // replace with your App SID
    AppKey = "YOUR_APP_KEY"       // replace with your App Key
};
var assemblyApi = new AssemblyApi(config);

// 2️⃣ Define the cloud path where the template will be stored
string cloudTemplatePath = "templates/invoice-template.docx";

// 3️⃣ Open the local template file (prepare this file beforehand)
using (var templateStream = File.OpenRead("resources/invoice-template.docx"))
{
    // 4️⃣ Build the upload request – the API expects a stream + target path
    var uploadRequest = new UploadFileRequest(templateStream, cloudTemplatePath);

    // 5️⃣ Execute the upload; the template is now available in Cloud storage
    assemblyApi.UploadFile(uploadRequest);
}

Tip: You can also upload the file using a simple cURL command (see the Generate Invoice with cURL section) if you prefer a command‑line approach.


Create Data Source

Build a JSON with the invoice data

Below is the sample JSON that matches the placeholders used in the template.
Save it as invoice-data.json in the resources folder or embed it directly in your code.

{
  "invoice": {
    "number": "INV-2024-001",
    "issueDate": "2024-01-15T00:00:00"
  },
  "customer": {
    "name": "John Smith",
    "company": "Acme Corporation",
    "email": "john.smith@example.com",
    "address": "123 Main Street",
    "city": "New York",
    "state": "NY",
    "zipCode": "10001",
    "country": "USA"
  },
  "items": [
    {
      "description": "Web Development Services",
      "quantity": 40,
      "unitPrice": 150.00
    },
    {
      "description": "UI/UX Design",
      "quantity": 20,
      "unitPrice": 120.00
    },
    {
      "description": "Consulting Services",
      "quantity": 10,
      "unitPrice": 200.00
    }
  ],
  "taxRate": 10.0
}

Using the JSON file in code

// Load the JSON data from a file – this string will be passed to the API
string jsonData = File.ReadAllText("resources/invoice-data.json");

Note: The same JSON can be sent inline in the request body when using cURL; the file approach is convenient for larger data sets.


Generate Invoice with .NET SDK

Major steps for C# code

  1. Upload the template (already covered).
  2. Read the JSON data source.
  3. Configure AssembleOptions – specify output format (docx or pdf) and link the template.
  4. Call AssembleDocument to generate the invoice.
  5. Save the resulting file locally or to another cloud location.
using GroupDocs.Assembly.Cloud.Sdk;
using GroupDocs.Assembly.Cloud.Sdk.Model;
using GroupDocs.Assembly.Cloud.Sdk.Model.Requests;
using System.IO;

// 1️⃣ Initialize the Assembly API (same config as upload step)
var config = new Configuration { AppSid = "YOUR_APP_SID", AppKey = "YOUR_APP_KEY" };
var assemblyApi = new AssemblyApi(config);

// 2️⃣ Load JSON data (see previous section)
string jsonData = File.ReadAllText("resources/invoice-data.json");

// 3️⃣ Prepare assembly options
var assembleOptions = new AssembleOptions
{
    // Choose the format you need – "docx" for editable, "pdf" for final PDF
    SaveFormat = "pdf",

    // Pass the whole JSON string – the API parses it automatically
    ReportData = jsonData,

    // Reference the template that we uploaded earlier
    TemplateFileInfo = new TemplateFileInfo
    {
        FilePath = "templates/invoice-template.docx"   // cloud path
    }
};

// 4️⃣ Build the request object
var assembleRequest = new AssembleDocumentRequest(assembleOptions);

// 5️⃣ Execute the request – the response contains the generated file stream
var assembledDocument = assemblyApi.AssembleDocument(assembleRequest);

// 6️⃣ Persist the result locally
using (var outputStream = File.Create("output/invoice-output.pdf"))
{
    // Copy the API stream to a file on disk
    assembledDocument.CopyTo(outputStream);
}

Result: invoice-output.pdf (or .docx if you changed SaveFormat) contains the fully populated invoice ready for sending to the customer.


Generate Invoice with cURL

If you prefer not to install any SDK and build the solution in code, the entire process can be done with plain HTTP calls.

1️⃣ Obtain an access token

curl.exe -X POST "https://api.groupdocs.cloud/connect/token" \
  -d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET" \
  -H "Content-Type: application/x-www-form-urlencoded"

The response contains access_token – copy its value for the next steps.

2️⃣ Upload the template via cURL

curl.exe -X PUT "https://api.groupdocs.cloud/v1.0/assembly/storage/file/templates/invoice-template.docx" \
  -H "Authorization: Bearer ACCESS_TOKEN" \
  -F "File=@resources/invoice-template.docx" 

If the template is already stored (as described in the upload‑via‑SDK step), you can skip this call.

3️⃣ Assemble the invoice

Create a JSON file called invoice-data.json in resources folder as shown in [Create JSON Data Source {#json-data}] section above.

And now call the AssembleDocument endpoint.

When working with large invoice datasets, the most efficient approach is to use an intermediate variable to read the invoice data and then pass it to the API request. The following example demonstrates this approach:

REPORT_DATA_ESCAPED=$(python -c "import json,sys; print(json.dumps(open('resources/invoice-data.json','r',encoding='utf-8').read()))")
	  
curl.exe -v "https://api.groupdocs.cloud/v1.0/assembly/assemble" \
  -X POST \
  -H "Authorization: Bearer ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  --data-binary @- <<EOF
{
  "TemplateFileInfo": {
    "FilePath": "/templates/invoice-template.docx"
  },
  "SaveFormat": "pdf",
  "OutputPath": "/output/invoice-generated.pdf",
  "ReportData": $REPORT_DATA_ESCAPED
}
EOF

The command builds the invoice and stores it in GroupDocs Cloud storage in a file /output/invoice-generated.pdf

4️⃣ Download the generated invoice

To download the invoice just call following command:

curl.exe \
  "https://api.groupdocs.cloud/v1.0/assembly/storage/file/Output/invoice-generated.pdf" \
  -H "Authorization: Bearer ACCESS_TOKEN" \
  -H "Accept: application/octet-stream" \
  -o invoice-generated.pdf

Result: You now have a ready‑to‑send invoice without writing any C# code.


Conclusion

In this article we showed how GroupDocs.Assembly Cloud makes invoice generation effortless:

  • Lightweight cloud processing – no third-party heavy tools on your servers.
  • Template design freedom – create template docs in Word/LibreOffice and store them in cloud storage.
  • Dynamic data binding – feed JSON (or XML) directly, with support for LINQ, calculations, loops, and conditionals.
  • Different output formats – choose DOCX for further editing or PDF for immutable distribution.
  • Simple integration – use the .NET SDK or several cURL calls, illustrated with full code samples.

Start automating your billing workflows today by uploading a template and invoking the assemble endpoint!


See also


Frequently Asked Questions (FAQs)

  • Can I use LibreOffice Writer instead of Microsoft Word for my template?
    Yes. The API works with any DOCX file, regardless of the editor used to create it.

  • Is it possible to perform calculations (e.g., totals, taxes) inside the template?
    Absolutely. You can use LINQ expressions or simple arithmetic in placeholders, e.g., <<[item.quantity * item.unitPrice]>>.

  • What is the maximum size of a template or data file I can upload?
    The service supports files up to 500 MB; typical invoice templates are far below this limit.

  • Do I need to pre‑create the target folder in cloud storage before uploading?
    No. The upload endpoint creates the folder hierarchy automatically if it does not exist.

  • Do I get a free trial?
    Yes, 150 free API calls per month are available.