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:



Text Parsing Engine (Line-Based Parser)

The core formatting system works using:


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



How it works:


Benefits:



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.