Updated October 2026. The original version of this post walked through a minimal “Hello world” function and then tacked on notes about the GitHub project that grew out of it. I’ve rewritten it to describe the current version only. The step-by-step setup now lives in the project’s README.
The problem
The ScroogeXHTML home page needed a live demo: upload an RTF file, see the converted HTML right away. The conversion itself is just a few lines of Java:
ScroogeXHTML converter = new ScroogeXHTML(); converter.setAddOuterHTML(true); String html = converter.convert(rtfInputStream);
Getting those lines onto the web was the real question. A Tomcat or Jakarta EE server would mean an internet-facing machine to provision, patch and pay for, all for a page that sees a modest amount of traffic. So I went serverless: a Google Cloud Run function (2nd gen Cloud Functions) that only runs, and only costs money, when somebody actually converts a document. AWS Lambda or Azure Functions would do the job just as well if you already live there.
How it works
The function is a single Java 21 class implementing the Functions Framework’s HttpFunction interface:
- The browser POSTs the RTF file as
multipart/form-data. - The function checks the request, reads the upload with a hard 1 MB cap and runs ScroogeXHTML on it.
- The response is a complete, self-contained HTML document, which the demo page shows in an iframe.
Along the way it takes care of the things you’d want from a public endpoint:
- Rich output: tables, footnotes, hyperlinks, bookmarks, paragraph borders and indents are converted.
- No external images: embedded pictures (up to 256 KB each) become Base64
data:URIs, so the HTML stands on its own. - Guard rails: uploads over 1 MB are rejected, every response carries a restrictive Content-Security-Policy, and only requests from www.scroogexhtml.com pass the CORS check.
- Bounded cost: the deployment is capped at three instances, so a burst of traffic can’t scale the bill along with it.
Try it
- Live demo: pick an RTF file on www.scroogexhtml.com and hit Convert.
- Source code: github.com/michaelJustin/cloud-function-rtf-to-html (MPL 2.0).
The README covers everything you need to run your own copy: requirements, building with Maven, testing locally with mvn function:run, the HTTP API with its status codes, and the gcloud functions deploy command. Note that ScroogeXHTML isn’t on Maven Central; see scroogexhtml.com for the library itself and its conversion options.
Related
More posts on RTF to HTML conversion with ScroogeXHTML.