Creating print and PDF content with a headless CMS

Content teams need to create different types of content deliverables for different audiences. While it’s common to deliver online content for websites and mobile apps, in many cases and industries, you still need to provide a good old PDF. So how do you do it with a headless CMS?

Radka

Radka Uhlirova & Dave Klement

Published on Feb 22, 2023

Organizations with large-scale, complex content and project operations provide tons of content for various channels, including print. Marketing teams usually take care of product pages, online catalogs, brochures, and leaflets for new customers, partners, and resellers, while customer education and support teams prepare online documentation and PDF manuals for existing customers.

Responsibilities and deliverables of content teams at various organizations may differ, but they all have one thing in common—the need to have control over their content. Whether you’re working with public-facing or password-protected content, you need to deliver seamless and engaging experiences for your customers.

Work with modular content to increase efficiency

With the Kontent.ai headless CMS, teams can save time and resources by creating structured, modular content that is easy to reuse and repurpose, and manage it all in one place. 

When you make your content modular, you actually break it down into smaller, reusable units, which you can further combine to create various outputs. For example, you can use a product description in online product pages and catalogs, and then reuse the same piece of text in PDF leaflets. 

Say goodbye to copy-and-pasting and duplicating content in multiple locations! Instead, embrace the power of a content hub—a single source of truth for all your content. By bringing all your content into a central cloud-based repository, it’s much easier to stay organized and have control over creating content that is consistent, compliant, and on-brand.

Reach your audience on all devices and channels

Websites are still a main point of contact for communicating with customers. In recent years, it’s been becoming more and more common to provide content for mobile apps and chatbots. But what if, for various reasons, you still need to deliver content as a PDF? 

The EU requires that safety instructions be provided in a clear and accessible format, and many companies, like those in the manufacturing industry, meet this requirement by delivering their manuals as PDFs. Another reason why organizations need to publish documents as PDFs is to provide offline access to documentation and supplying partners and resellers with downloadable materials.

3 easy steps to export headless content to PDF 

Using a headless CMS, you can deliver content to any channel, even print. In the following three steps, we’ll look into how Kontent.ai’s Customer Education team handles exporting the content of Kontent.ai Learn, our own learning center running on Kontent.ai, to PDF.

There is a number of ways to convert Delivery API responses to PDF or other formats. You can leverage a third-party service, or you can run a conversion script on your own server.

We decided to go with the service option and chose Api2Pdf. The service consumes styled HTML pages served via a URL and returns PDF documents. Easy. But wait—styled HTML? The Delivery API returns JSON, not styled HTML, right? Yes. Let’s start from the beginning to see how we did it.

Step 1: Prepare JSON data for PDF

Kontent.ai’s Delivery API serves your content in JSON without visual information. To serve it to your customers, you need to add the visuals yourself. For websites, you assemble the content in HTML pages, style it with CSS and use Javascript for interactivity. 

But how do you do it for PDF documents? It’s very similar to webpages—HTML with CSS, just the CSS needs to be tailored to the fact that PDF documents aren’t responsive, comprise of pages, and so on.

As mentioned before, the Api2Pdf service consumes the URL of the article that you want to convert. What we do before we send the article to the service, though, is that we inject the article with special CSS that accounts for the aforementioned PDF specifics.

Step 2: Create the PDFs

Now that we have the visuals prepared for PDF, we can convert the content. For each article in our learning center, we’ve added a button that lets our visitors download the particular tutorial in PDF.

Kontent.ai Learn PDF Button

This button calls a function on our backend that sends the article’s URL to the Api2Pdf service. The service processes the content and responds via API with a one-time link to the resulting PDF.

The Kontent.ai Learn web app downloads the PDF to store it server-side for caching as well as to serve it to the customer who requested the PDF.

Step 3: Cache the PDFs

Caching is a well-known and used practice with websites, but it’s useful for this use case too. The goal here is to avoid calling the Api2Pdf service every time a visitor clicks the button to get an article in PDF.

The Kontent.ai Learn web app stores the PDF files as well as metadata about content that has already been converted. When someone requests a PDF version of a tutorial, we check whether we have it in the cache. If we do, we serve the cached PDF, if we don’t, we call the Api2Pdf service.

You may ask why we store metadata about the converted content. Why not just the PDF files? The answer is cache invalidation.

The metadata we store for each PDF file contains the codename of the corresponding content item. When there’s a content change in the learning center, Kontent.ai sends a webhook notification that contains codenames of affected content items. That makes it easy for us to decide which PDF files are affected and need to be deleted.

Publish your content anywhere

Kontent.ai delivers your content in JSON structured based on your content model. When you receive the JSON from the Delivery API, it doesn’t specify any visual aspects of your content. 

This gives you the freedom to do whatever you want with the content. You can push it to your mobile app, transform it to styled HTML and serve it as a website, or you can feed it to a tool that generates a nice PDF with your printable price sheets, brochures, or anything else.

But it doesn’t stop with websites, mobile apps, and PDFs. You can feed the structured content into any channel in any format you want—the options are limitless.

Subscribe to the Kontent.ai newsletter

Get the hottest updates while they’re fresh! For more industry insights, follow our LinkedIn profile.