Dev.to WebDev ๐Ÿ›  Dev ๐Ÿ‘ 0 ๐Ÿ“– 1 min read

How to Convert LLM Markdown & Code Blocks into Styled PDFs

A quick, lightweight way to generate styled PDFs from Markdown, HTML, or raw JSON without serverless memory spikes. If you've ever built an app that handles LLM outputs or developer documentation, you know the struggle

A quick, lightweight way to generate styled PDFs from Markdown, HTML, or raw JSON without serverless memory spikes.

If you've ever built an app that handles LLM outputs or developer documentation, you know the struggle of exporting that content cleanly into a PDF.

In this tutorial, we'll walk through a lightweight way to offload your PDF generation pipeline using Loreit Engine via Node.js or fetch.

๐Ÿ› ๏ธ What We're Building

We'll take a string containing mixed Markdown, HTML, and code blocks (like Python or JavaScript snippets) and instantly output a styled, syntax-highlighted PDF stream.

Key Requirements:

  • An API Key (you can grab a free tier key on RapidAPI).
  • Node.js / Fetch runtime environment.

๐Ÿš€ Step 1: Set Up Your Payload

Loreit Engine accepts raw HTML strings, Markdown, or structured JSON payloads. Here is a sample JSON payload containing dynamic content and a code snippet:

{
  "rawText": "<h1>Generated Report</h1><p>Here is the Python function requested:</p><pre><code class=\"language-python\">def calculate_metrics(data):\n    return sum(data) / len(data)</code></pre>"
  "theme": "dark"
}

๐Ÿ’ป Step 2: Send the Request in JavaScript / Node.js

const options = {
  method: 'POST',
  headers: {
    'x-rapidapi-key': 'YOUR_RAPIDAPI_KEY_HERE',
    'x-rapidapi-host': 'loreit-llm-pdf-generator.p.rapidapi.com',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    html: "<h1>Weekly Report</h1><p>Processed via <b>Loreit Engine</b>.</p>"
  })
};

fetch('[https://loreit-llm-pdf-generator.p.rapidapi.com/api/v1/generate-pdf](https://loreit-llm-pdf-generator.p.rapidapi.com/api/v1/generate-pdf)', options)
  .then(response => response.blob())
  .then(blob => {
    console.log("PDF Stream received successfully!");
    // Handle or save the PDF stream in your application
  })
  .catch(err => console.error('Error rendering PDF:', err));

๐Ÿงช Interactive Testing via Postman

If you want to test the endpoint visually without writing code first, you can test it directly in your browser or Postman:

https://documenter.getpostman.com/view/56965602/2sBY4SLymt#intro

๐Ÿ“ฐ Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.