AppStars

Knowby, 2022 to now

Knowby's PDF generator: turning guides and completed forms into print-ready documents.

Knowby's PDF generator turns a published guide, or a completed form session, into a branded PDF and emails it to whoever asked. It's a .NET job built on QuestPDF that runs on demand in a container. We designed, architected and developed the Knowby platform, from the mobile apps to the backend services, and PDF export is one of its jobs.

Owner
Knowby
Industry
Work instructions for manufacturing, logistics and utilities
Services
Backend services, document generation, cloud jobs
Platforms
.NET 10, C#, QuestPDF, HtmlAgilityPack, FFmpeg, Google Cloud Run Jobs, SendGrid
Our role
We designed, architected and developed the Knowby platform, from the mobile apps to the backend services, including the export job.

The challenge

Knowby guides are built to be used on a phone or tablet: video steps, rich text, documents and 3D models, forms to fill in. But plenty of work still runs on paper. Auditors want a printed copy. A site keeps a binder by the machine. A completed checklist has to be filed as a record. Customers needed a faithful, branded PDF of a guide, and of a form someone had filled in, without anyone rebuilding it in a word processor.

A PDF is a static thing, and a guide isn't. Videos can't play on paper. Links to stored files expire. Rich text written in a web editor uses HTML and CSS that a PDF library doesn't understand. A wide logo or a tall photo can break a page layout. And making a PDF with dozens of images is heavy work that shouldn't hold up the API a person is waiting on.

Our approach

We made export a background job, not an API call. When someone asks for a PDF, the Pro API checks they may see the guide or session, records a job, and returns straight away. The Jobs service runs the export as a containerised .NET console job on Google Cloud Run Jobs, which starts, does the work and stops, so we pay only while it runs. The job reports its state back (running, succeeded or failed, with a reason), and the PDF arrives by email as an attachment. This is the same job pattern Knowby uses for AI generation, transcoding and copying.

For the layout we chose QuestPDF, a code-first .NET library, over rendering HTML in a headless browser. A browser is heavy to ship and slow to start in a container. QuestPDF gives exact control of the layout in C#, runs fast, and can be unit-tested. The cost is that we had to translate the editor's HTML ourselves, which we decided was worth it.

What we built

Guides and completed forms

The same job exports two things. For a guide, it reads the latest published snapshot, so a PDF never shows an unpublished draft. For a session, it reads the completed form with every answer: short and long text, single and multiple choice, drop-downs, checkboxes and uploaded files. That turns a checklist done on a phone into a record you can file.

An HTML-to-PDF renderer of our own

Step text is written in a rich-text editor and stored as HTML. We built a small renderer that parses it with HtmlAgilityPack and maps each tag to a QuestPDF component: paragraphs, line breaks, lists, tables, images, links and block quotes. Knowby's editor has five callout styles (info, neutral, success, warning and error), and each prints in its own colour with its own symbol. The editor stores them as CSS variables, and older content carries raw colours, so the renderer recognises both.

Media that makes sense on paper

A video step prints as a still frame taken with FFmpeg, in the same 16:9 frame the video takes on screen, with the step text below. A document or 3D model step prints as a card with a format badge, the file name and a "View this document online" link. That link goes to the step itself, not to a signed file URL, because a signed URL would expire long before someone reads the printed copy.

Layouts that don't break

The document uses an A4-wide continuous page with a header, content and footer, the organisation's logo in the header and a "powered by Knowby" mark. Every image is held to a maximum height and scaled to fit its area, so a very wide logo or a very tall photo shrinks to fit instead of throwing a layout exception. We pinned each of those cases with a layout test: wide logos, tall cover images, tall step images, document steps and the colours of each callout type.

Architecture

Request, queue, render and deliver, without blocking the API.

  1. Pro APIChecks access to the guide or session and requests an export
  2. Jobs serviceRecords the job and starts a Cloud Run Job
  3. Export jobLoads the published snapshot or session, media and logo
  4. QuestPDFLays out HTML, images, video frames and form answers
  5. EmailSends the PDF as an attachment and marks the job done

The job writes to its own temporary folder and deletes it afterwards.

Results

Under the hood

Code-first PDF layout in .NET, run as a serverless job.

What we'd do now

Every document job belongs off the request path. Generating a PDF, a report or an export inside a web request works in a demo and fails in production, when one customer asks for a hundred-page guide. Queue it, run it in a short-lived container, report progress, and deliver it when it's ready.

Design for the medium. The interesting work in a PDF exporter isn't drawing text. It's deciding what each thing becomes on paper: a frame for a video, a durable link for a file, a coloured box for a warning. Treating print as its own medium, with its own rules, is what makes an export useful rather than merely complete.

Test the layout, not just the code. Layout failures come from real content: a logo that's ten times wider than it is tall, a portrait photo, a long URL. Each one we found became a test that renders the document. If we built it again we'd also add visual snapshot tests of whole pages, and tagged, accessible PDFs for screen readers, which regulated customers increasingly ask for.

Why it matters now

Most business software needs to produce documents: reports, certificates, completed inspections, invoices. We build that as part of a web and SaaS platform: background jobs, reliable layouts, and delivery by email or download. When the data lives in older systems, our integration work brings it in.

The PDF job sits beside the rest of the Knowby platform, and it exports the forms people complete from scheduled tasks.

Questions

What does Knowby's PDF generator produce?

A branded PDF of a published guide, or of a completed form session with all its answers, sent by email as an attachment.

Why QuestPDF instead of a headless browser?

QuestPDF is a code-first .NET library: fast to start in a container, precise to lay out, and easy to test. A headless browser is heavier to ship and slower to start.

How do videos and attached files appear in the PDF?

A video step prints as a still frame taken with FFmpeg. A document or 3D model step prints as a card with a link to that step online, because a signed file link would expire.

Can you add document generation to our platform?

Yes. We build PDF and report generation as background jobs, with layouts tested against real content and delivery by email, download or storage.

Related

The services behind this work, and more stories like it.

Services

Case studies

Bring us the hard problem.

A 45-minute discovery call with the engineer who'll build it.