Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

html to pdf nodejs

import fs from 'fs'
import path from 'path'
import ejs from 'ejs'
import htmlPdf from 'html-pdf'
;(async function () {
  const pdfTemplate = await ejs.renderFile(
    path.join(__dirname, './src/services/email/pdfInvoice.ejs'),
    {
      invoiceNumber: 201543502291,
      date: new Date().toLocaleDateString(),
      pickUpDatetime: new Date().toLocaleDateString(),
      returnDatetime: new Date().toLocaleDateString(),
      pickUpLocation: 'jakarta',
      returnLocation: 'jakarta',
      payments: [{ description: 'oke', durationPerHours: 20, rentPerHours: 10, amount: 2000 }],
      discount: 'RM ' + 1000,
      totalPayment: 'RM ' + 5000,
      fullName: 'john doe',
      phoneNumber: '+6287887242891'
    },
    {
      beautify: true,
      async: true
    }
  )

  htmlPdf
    .create(pdfTemplate, {
      format: 'A4',
      httpHeaders: { 'content-type': 'application/pdf' },
      quality: '100',
      orientation: 'portrait',
      type: 'pdf'
    })
    .toFile(path.join(__dirname, 'index.pdf'), (err, res) => {
      if (!err) {
        console.log(res.filename)
      }
    })
})()
Comment

html-pdf nodejs

npm install html2canvas jspdf

import html2canvas from 'html2canvas'
import jsPdf from 'jspdf'
 
function printPDF () {
    const domElement = document.getElementById('your-id')
    html2canvas(domElement, { onclone: (document) => {
      document.getElementById('print-button').style.visibility = 'hidden'
    }})
    .then((canvas) => {
        const img = canvas.toDataURL('image/png')
        const pdf = new jsPdf()
        pdf.addImage(imgData, 'JPEG', 0, 0, width, height)
        pdf.save('your-filename.pdf')
Comment

PREVIOUS NEXT
Code Example
Javascript :: json data example 
Javascript :: element remove class 
Javascript :: how to swap two elements in an array javascript 
Javascript :: TypeError: Object of type ndarray is not JSON serializable 
Javascript :: jquery get custom attribute 
Javascript :: javascript converting an array into a map 
Javascript :: js select keys from object 
Javascript :: js how to convert vh to pixel 
Javascript :: gsheet query select remove header 
Javascript :: inbuilt javascript functions for last word check 
Javascript :: what is xhr 
Javascript :: compare objects 
Javascript :: Download Node Module With NPM 
Javascript :: looping through local storage javascript 
Javascript :: Define the constructor property on the Dog prototype. 
Javascript :: how to do get request in axios 
Javascript :: how to use a regex expression in kibana query 
Javascript :: console log 
Javascript :: js entries 
Javascript :: how to replace all occurrences of a string in javascript 
Javascript :: button change slider value js 
Javascript :: handle onchange react 
Javascript :: unix timestamp js 
Javascript :: angular convert map values to array 
Javascript :: javascript convert input to lowercase 
Javascript :: validate form on submit 
Javascript :: jquery remove multiple class 
Javascript :: useformik 
Javascript :: javascript hello world 
Javascript :: jspdf 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =