Client-Side Markdown Parsing and Dynamic PDF Generation System

Written by Joeboukhalil | Published 2026/03/06
Tech Story Tags: javascript | text | writing | code | tool | text-to-pdf | study-notes-generator | beginner-web-project

TLDRLearn how to build a simple AI-assisted text-to-PDF converter using HTML, CSS, JavaScript, and jsPDF in the browser.via the TL;DR App

Introduction

Some people like to write and keep the writing for later times to view or share.

And this is why I came up with this idea. Why not make a text-to-PDF converter with the help of AI?

And here I am going to explain its benefits, what it's used for, and the code used.



Technical information

Architecture overview

This software is built using:

  • HTML: interface structure
  • CSS: UI styling and layout
  • Vanilla JavaScript: Logic & text parsing
  • jsPDF Library: PDF document generation



Text Parsing Engine (Line-Based Parser)

The core formatting system works using:


let lines = text.split("\n");



How it works:

  • The inputted test is split into lines.
  • Each line is analyzed using:
  • startsWith() for headings
  • Regular expressions for numbered lists


Benefits:

  • Doesn't need installation; runs in the browser.
  • You can make it into a single HTML, CSS, and JavaScript file. (Easy to share or upload).
  • Real pdf formatting (headings, lists, spacing).
  • Beginner-friendly code structure. Not so complex and easy.



What it can be used for:

Creating research drafts and structured articles. As a draft or later to publish.

Great for studying. Generating printable study notes.

Writing blog posts before publishing.




Code:

JS PDF library (required for PDF download)

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>



Text to input area

<textarea id="inputText"></textarea>

Markdown Conversion Function
function convertMarkdown(text){
    let lines = text.split("\n");
    let html = "";
    ...
    return html;
}



Preview Generator

function generatePreview(){
    let text=document.getElementById("inputText").value;
    document.getElementById("previewArea").innerHTML=convertMarkdown(text);
}



PDF Generator Function (Core Engine)

async function downloadPDF(){
    const { jsPDF } = window.jspdf;
    let doc = new jsPDF();
    ...
    doc.save("article.pdf");
}


Heres a demo to see it yourself. See it in action.

Conclusion

It could be used for many purposes and benefits people if used correctly.


And with the help of AI, it became more easily possible to make more and more projects.



Written by Joeboukhalil | I'm an independent creator passionate about building useful tools, simulations, and theories that make complex ideas more accessible. I explore the intersection of technology, education, and human experience—often with the help of AI like ChatGPT.
Published by HackerNoon on 2026/03/06