Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

jsPDF Tutorial to Display & Print Date & Time in PDF Documents Using Javascript

Posted on December 17, 2022

 

 

Welcome folks today in this blog post we will be displaying and printing the date and time in pdf documents using jspdf library in javascript. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to make an index.html file and copy paste the cdn of jspdf as shown below

 

 

index.html

 

 

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

 

 

And now we will be writing the javascript code to display the current date and time in the pdf document using jspdf text()method. First of all we will be getting the date and time using the Date() constructor and then we will be adding that string inside the pdf document.

 

 

JavaScript
1
2
3
4
5
6
7
8
9
10
11
  var doc = new jsPDF()
 
  doc.text("hello world",10,10)
 
  let date = new Date()
 
  let dateString = "Today date & time is " + date
 
  doc.text(dateString,5,50)
 
  doc.save("output.pdf")

 

 

 

 

Recent Posts

  • Android Java Project to Download Multiple Images From URL With Progressbar & Save it inside Gallery
  • Android Java Project to Capture Image From Camera & Save it inside Gallery
  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme