Read-only mirror of https://github.com/swiss/fch-documentservice-client — Bundeskanzlei. Issues & pull requests at the source.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
schamo 739b403e47
chore: update changelog #BKDO-3319 (#12)
Co-authored-by: Schädeli Andreas BIT <andreas.schaedeli@bit.admin.ch>
2026-06-12 10:57:19 +02:00
.github feat: initial publication on GitHub 2026-03-11 16:00:48 +01:00
src chore(code-analysis): enable CA2000 warnings, update dependencies (#11) 2026-06-12 10:31:39 +02:00
.editorconfig feat: initial publication on GitHub 2026-03-11 16:00:48 +01:00
.gitignore feat: initial publication on GitHub 2026-03-11 16:00:48 +01:00
CHANGELOG.md chore: update changelog #BKDO-3319 (#12) 2026-06-12 10:57:19 +02:00
CONTRIBUTING.md feat: initial publication on GitHub 2026-03-11 16:00:48 +01:00
LICENSE feat: initial publication on GitHub 2026-03-11 16:00:48 +01:00
README.md Revert "feat(l10n): add documentCulture for template operations (#9)" (#10) 2026-05-27 11:20:24 +02:00
SECURITY.md feat: initial publication on GitHub 2026-03-11 16:00:48 +01:00
THIRD_PARTY_LICENSES.md chore(code-analysis): enable CA2000 warnings, update dependencies (#11) 2026-06-12 10:31:39 +02:00

Introduction

This library simplyfies the usage of the DocumentService which is run by the federal chancellery.

usage

DI Injection

First, register the service in you DI container.

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDocumentService(builder.Configuration);

Health Check

Add a health check for the document service.

builder.Services
       .AddHealthChecks()
       .AddDocumentService();

Configuration

In your appsettings, add the following.

{
    "DocumentService": {
	    "Url": "ds_service_url",
		"TokenUrl": "http://might_be_your_key_cloak/realms/bk-micro-services/protocol/openid-connect/token",
		"ClientId": "your_client_id",
		"ClientSecret": "your_client_secret",
		"RequestTimeoutMs": your_timeout
	}
}

Excel Generation

Generate an Excel sheet like this.

		var spreadsheet = new Spreadsheet
        {
            HeaderCells = [...]
            BodyCells = [...],
            TableOptions = new TableOptions
            {
                CreateTable = true,
                ShowTotalsRow = true
            }
        };

        var resultStream = await _documentService.CreateExcel(spreadsheet);

Template Generation

Generate a document based on an Aspose LINQ Syntax Template.

//generate a Word document
var resultingWordDoc = await _documentService.CreateWordFromTemplate($"pathToYourTemplate.docx", dataObject, "yourDataObjectRootElementName");

//generate a PDF
var resultingPdf = await _documentService.CreateWordFromTemplate($"pathToYourTemplate.docx", dataObject, "yourDataObjectRootElementName");

Note that your dataObject can be any object (it will be serialized to JSON and should match the placeholders in your word template).

Word to HTML Conversion

You can convert a Word document to HTML as follows.

var result = await _documentService.ConvertWordToHtml("your_word_file_path");

Extract Parts of a Document

You can extract parts of a Word document as follows.

var result = await _documentService.ExtractContentFromWord("your_word_file_path", new WordExtractOptions { .. });

The WordExtractOptions allow to configure the following.


|Property | Description | |StartAfterParagraphText | Start the extraction after this text has occured (paragraph "starts with"). | |StopBeforeParagraphText | Stop the extraction before this text has occured (paragraph "starts with)". | |ExactStart | Start the extraction after this text has occured (paragraph must match exaclty). | |ExactEnd | Stop the extraction before this text has occured (paragraph must match exactly). | |WordExtractFormat | Extract result as HTML or PDF | |LineBreaks | Allow soft linebreaks in the search pattern | |RemoveClasses | Removes all CSS classes from the resulting HTML | |RemoveStyles | Removes all styles from the resulting HTML | |RemoveImages | Removes images from the result | |RemoveEmptyAnchors | Removes all <a> tags with no href | |RemoveSpans | Removes all <span> but keeps their content | |ReplaceItalicWithEmphasis | Replaces <i> with <em> in the result HTML | |ReplaceBoldWithStrong | Replaces <b> with <strong> in the result HTML |

Contribution

See: https://github.com/swiss/fch-documentservice-client/blob/main/CONTRIBUTING.md

Security

See: https://github.com/swiss/fch-documentservice-client/blob/main/SECURITY.md

Development Workflow

To publish a new version of the NuGet package, proceed as follows.

  • apply and push your changes
  • define and describe the new version in CHANGELOG.md
  • push the corresponding label with git tag vx.x.x and git push origin vx.x.x
  • go to GitHub -> Actions -> 'Build and Publish to NuGet.org' and trigger a run while specifying the correct GIT label