Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
json to pdf in javasript without any libraries

Is there any method that may be able to convert JSON data to pdf with using only pure Javascript , without using any libraries or packages

There is a requirement to create a single html page (done with help of webpack) for offline work . so I need to download some json as pdf and should not not use any libraries.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I unfairly said in comments

no, until you write your own text/pdf parser. possible but not likely within my remaining lifetime,

So your challenge is to see (fast as you can) if you can use your Javascript coding skills to convert from raw:-

   {
        "text": {
            "text": "Hello World!",
            "points": 48 ,
            "x": 36 ,
            "y": 684
        }
    }

into this, and adapt it for other json objects, so perhaps add a page definition above to show text is on page 1 with a media box so as to relate the xy values to that page. Generally write the page structure first then the resources such as fonts then the text mapped to font and position.

%PDF-1.0
%µ¶

1 0 obj
<</Type/Catalog/Pages 2 0 R>>
endobj

2 0 obj
<</Kids[3 0 R]/Count 1/Type/Pages/MediaBox[0 0 595 792]>>
endobj

3 0 obj
<</Type/Page/Parent 2 0 R/Contents 4 0 R/Resources<<>>>>
endobj

4 0 obj
<</Length 58>>
stream
q
BT
/ 96 Tf
1 0 0 1 36 684 Tm
(Hello World!) Tj
ET
Q

endstream
endobj

xref
0 5
0000000000 65536 f 
0000000016 00000 n 
0000000062 00000 n 
0000000136 00000 n 
0000000209 00000 n 

trailer
<</Size 5/Root 1 0 R>>
startxref
316
%%EOF

Note there is no font so this example is just step one, the next step is much harder and that is how to include the font description, so for a hint see https://stackoverflow.com/a/70748286/10802527

HOWEVER if you write JS you are writing a 3rd party library yourself and by far the simplest is use a single line command So I have a one line txt2pdf cmd that will take argument "Hello World!" and echo it into this format then display as pdf on screen:-

{"pages":{"1":{"content":{"text":[{"value":"############","anchor":"center","font":{"name":"Helvetica","size":12}}]}}}} 

echo {"pages":{"1":{"content":{"text":[{"value":"%~1","anchor":"center","font":{"name":"Helvetica","size":12}}]}}}}>hello.json && pdfcpu create hello.json hello.pdf && hello.pdf

enter image description here

So contrary to using raw JS I suggest there is already an exceptionally very good Apache-2.0 license 3 MB cross platform API/CLI library that converts Json to PDF. So above one liner uses amazing tiny powerful https://pdfcpu.io/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!