score:8
Installation:
npm install pdfkit
Example:
var PDFDocument = require('pdfkit');
doc = new PDFDocument;
doc.pipe(fs.createWriteStream('output.pdf'));
doc.font('fonts/PalatinoBold.ttf').fontSize(25).text(100, 100);
score:8
You can use pdf-creator-node package to create PDF
Following are the steps to create PDF in Node Application
- Installation install the pdf creator package by the following command
npm i pdf-creator-node
- Add required packages and read HTML template
//Required package
var pdf = require("pdf-creator-node")
var fs = require('fs')
// Read HTML Template
var html = fs.readFileSync('template.html', 'utf8')
- Create your HTML Template
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Hello world!</title>
</head>
<body>
<h1>User List</h1>
<ul>
{{#each users}}
<li>Name: {{this.name}}</li>
<li>Age: {{this.age}}</li>
<br>
{{/each}}
</ul>
</body>
</html>
- Provide Format and Orientation as per your need
"height": "10.5in", // allowed units: mm, cm, in, px
"width": "8in", // allowed units: mm, cm, in, px
or -
"format": "Letter", // allowed units: A3, A4, A5, Legal, Letter, Tabloid "orientation": "portrait", // portrait or landscape
var options = { format: "A3", orientation: "portrait", border: "10mm" };
- Provide HTML, User data and pdf path for the output
var users = [
{
name:"Shyam",
age:"26"
},
{
name:"Navjot",
age:"26"
},
{
name:"Vitthal",
age:"26"
}
]
var document = {
html: html,
data: {
users: users
},
path: "./output.pdf"
};
- After setting all parameters just pass document and options to pdf.create method.
pdf.create(document, options)
.then(res => {
console.log(res)
})
.catch(error => {
console.error(error)
});
Source: stackoverflow.com
Related Query
- How to create pdf file in node js
- How to pass a array from node to .js file (pugJs)
- How to run Chart.js samples using source code
- How to embed php code in min.js file
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- How to create two x-axes label using chart.js
- How to create rounded bars for Bar Chart.js v2?
- How to create datasets dynamically for chart.js Line chart?
- How to create stacked bar chart using react-chartjs-2?
- How to create a gradient fill line chart in latest Chart JS version (3.3.2)?
- How can I create a time series line graph in chart.js?
- How to create single value Doughnut or Pie chart using Chart.js?
- how to create multiple chart on one component vue
- How to create custom legend in ChartJS
- Chartjs: How to create padding between ticks and scale label
- How to create dynamic charts with Django and Chart.js?
- How to Create a Custom Logarithmic Axis in Chart.js
- How to add ChartJS code in Html2Pdf to view image
- How do I keep chart.js charts in one JS file, and not get errors when the ID from the JS file don't exist on one specific html page?
- How can I create custom tooltips for each data point in a graph?
- How to create a gantt chart using Chart.js and populate dates?
- How to create a simple Gauge with ChartJS v3?
- How to create chartjs chart with data from database C#
- How to create a stacked graph using ChartJS
- How can i create a background of moving graphs like chartsjs?
- How to Create Chart.JS Bar Graph with Min, Max & Average
- How to create a linechart with Chart.JS (not filled)
- How to create a rounded rectangle using ChartJS
- How to create a chart that uses strings for both the X and Y axes?
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
More Query from same tag
- Chartjs 2 - Stacked bar with marker on top
- Implementing hover callback in Chart.js
- chart.js filltext object moved when tooltip is generated because of legend not displaying
- Chart.js - Line Chart format data to Lacs/Crores
- HTML5 chart stacked bars with repeated colors
- chart.js charts wouldn't show or hide with Angular directives ng-show and ng-hide
- Cant pass variable for some reason? PHP
- ChartJs is not working in angular 4 with no errors
- y-axis values are way to high
- Setting specific color per label in chart.js
- how do I change the textsize in of doughnut in react-chartjs-2?
- Make arbitrary line dashed
- Display legend of grouped data (different colors) in chart
- Chart.js How to sum the values in a pie chart and display them in the header
- Chart disappearing on dataset update
- How to create a Doughnut chart in django admin interface using foreign key field data?
- Label Color same as backgroundColor - ChartJS
- Chart.js: hide dataset line but keep ticks on y-axis?
- Chartjs - Set start and end value into a Bar Chart
- How to make dynamic chart with the next view? What libraries allows to customise exactly this like in my design?
- ChartJS: subsequent charts hide previous charts
- Using chart.js inside node.js
- Line chart plotting multiple points for duplicate data on x and y axis using chart.js
- ChartJS Doughnut Charts Gradient Fill
- Chart.js data/label scale
- Chartjs tooltip anchor point position on bar charts
- Vue chartjs is not rendering from API
- ChartJS - Gradient color overlap
- chart.js won't display the chart in IE
- Angular Chart color does not change