Skip to content

WebNinjaDeveloper.com

Programming Tutorials




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

PDFMake.js Tutorial to Add Page Numbers With Border at Footer inside PDF Document in Browser Using JS

Posted on January 17, 2023

 

 

SOURCE CODE

 

 

index.html

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!doctype html>
<html lang='en'>
 
<head>
    <meta charset='utf-8'>
    <title>my example</title>
    <!-- pdfmake files: -->
    <script src='https://cdn.jsdelivr.net/npm/pdfmake@latest/build/pdfmake.min.js'></script>
    <script src='https://cdn.jsdelivr.net/npm/pdfmake@latest/build/vfs_fonts.min.js'></script>
    <!-- html-to-pdfmake file: -->
    <script src="https://cdn.jsdelivr.net/npm/html-to-pdfmake/browser.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
 
<body>
 
</body>
<script>
 
 
    var dd = {
        pageMargins: [40, 40, 40, 100],
        footer: function (currentPage, pageCount) {
            return {
                table: {
                    body: [
                        [
                            { text: "Page " + currentPage.toString() + ' of ' + pageCount, alignment: 'right', style: 'normalText', margin: [0, 20, 50, 0] }
                        ],
                    ]
                },
                layout: 'Borders'
            };
        },
        content: [
            { text: 'Text bcbcvb', pageBreak: 'after' },
            { text: 'Text fgdfg', pageBreak: 'after' },
            { text: 'Text fgdfgdfg', pageBreak: 'after' },
        ]
    }
    pdfMake.createPdf(dd).download();
 
 
 
    // playground requires you to assign document definition to a variable called dd
 
</script>
</body>
 
</html>

 

 

As you can see we have included the cdn of the pdfmake.js and then inside the javascript we are adding the page numbers inside the pdf document at the bottom of the pdf document. We have also added the border to the page numbers as shown below

 

 

 

 

Recent Posts

  • 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
  • Android Java Project to Download Youtube Video Thumbnail From URL & Save it inside SD Card
  • Android Java Project to Embed Google Maps & Add Markers Using Maps SDK
  • Android Java Project to Download Random Image From Unsplash Using OkHttp & Picasso Library & Display it
  • 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