All Projects → hajareshyam → pdf-creator-node

hajareshyam / pdf-creator-node

Licence: MIT License
This package is used to generate HTML to PDF in Nodejs

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to pdf-creator-node

Ptext Release
pText is a library for reading, creating and manipulating PDF files in python.
Stars: ✭ 124 (+1.64%)
Mutual labels:  pdf-converter, pdf-generation
Laravel Pdf
A Simple package for easily generating PDF documents from HTML. This package is specially for laravel but you can use this without laravel.
Stars: ✭ 79 (-35.25%)
Mutual labels:  pdf-converter, pdf-generation
scryber.core
Scryber.Core is a dotnet 5 html to pdf engine written entirely in C# for creating beautiful flowing documents from html templates including css styles, object data binding and svg drawing.
Stars: ✭ 74 (-39.34%)
Mutual labels:  html-template, pdf-generation
Android-XML-to-PDF-Generator
This library is for convert XML to PDF very easily using Step Builders Pattern
Stars: ✭ 140 (+14.75%)
Mutual labels:  pdf-converter, pdf-generation
Html Pdf Service
LGPL V3. Java Spring Boot microservice with RESTful webconsole and service endpoints that convert HTML to PDF, optionally styling with CSS and templating with JSON using Flying Saucer, PDF Box and Jackson libraries. Available on Docker Hub.
Stars: ✭ 12 (-90.16%)
Mutual labels:  html-template, pdf-generation
Doctron
Docker-powered html convert to pdf(html2pdf), html to image(html2image like jpeg,png),which using chrome(golang) kernel, add watermarks to pdf, convert pdf to images etc.
Stars: ✭ 141 (+15.57%)
Mutual labels:  pdf-converter, pdf-generation
Pdfsave
Convert websites into readable PDFs
Stars: ✭ 46 (-62.3%)
Mutual labels:  pdf-converter, pdf-generation
Aws Lambda Libreoffice
85 MB LibreOffice to fit inside AWS Lambda compressed with Brotli
Stars: ✭ 145 (+18.85%)
Mutual labels:  pdf-converter, pdf-generation
pdftron-android-samples
PDFTron Android Samples
Stars: ✭ 30 (-75.41%)
Mutual labels:  pdf-converter, pdf-generation
chromic pdf
Convenient HTML to PDF/A rendering library for Elixir based on Chrome & Ghostscript
Stars: ✭ 196 (+60.66%)
Mutual labels:  pdf-converter, pdf-generation
JasperViewerFX
The JasperViewerFX is a free JavaFX library which aims to avoid use of JasperReport's swing viewer
Stars: ✭ 27 (-77.87%)
Mutual labels:  pdf-generation
Android-ConvertToPDF
How to convert a document to a PDF using iText and Aspose?
Stars: ✭ 17 (-86.07%)
Mutual labels:  pdf-generation
document-conversion-nodejs
DEPRECATED: Please use https://github.com/watson-developer-cloud/discovery-nodejs
Stars: ✭ 27 (-77.87%)
Mutual labels:  pdf-converter
Resume-Builder
Android App to help you create your résumé
Stars: ✭ 37 (-69.67%)
Mutual labels:  pdf-generation
aws-lambda-pdf-generator-puppeteer
PDF generator for AWS lambda with puppeteer
Stars: ✭ 52 (-57.38%)
Mutual labels:  pdf-generation
xrechnung-visualization
XSL transformators for web and pdf rendering of German CIUS XRechnung or EN16931-1:2017 [MIRROR OF GitLab]
Stars: ✭ 26 (-78.69%)
Mutual labels:  pdf-generation
AusweisBot
Telegram bot to generate self-authorizations for moving around during covid-19 pandemic in France
Stars: ✭ 13 (-89.34%)
Mutual labels:  pdf-generation
DrawPDF
Draw/Write pdf using Swift
Stars: ✭ 17 (-86.07%)
Mutual labels:  pdf-generation
mr-pdf
PDF generator of document website
Stars: ✭ 58 (-52.46%)
Mutual labels:  pdf-generation
MarkdownDoc
A Java tool/maven plugin/library to generate HMTL and PDF from markdown text intended for project documentation. Supports JSON based "stylesheet" for PDFs.
Stars: ✭ 21 (-82.79%)
Mutual labels:  pdf-generation

Follow these steps to convert HTML to PDF

  • Step 1 - install the pdf creator package using the following command

    $ npm i pdf-creator-node --save

    --save flag adds package name to package.json file.

  • Step 2 - 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");
  • Step 3 - 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>
  • Step 4 - 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",
            header: {
                height: "45mm",
                contents: '<div style="text-align: center;">Author: Shyam Hajare</div>'
            },
            footer: {
                height: "28mm",
                contents: {
                    first: 'Cover page',
                    2: 'Second page', // Any page number is working. 1-based index
                    default: '<span style="color: #444;">{{page}}</span>/<span>{{pages}}</span>', // fallback value
                    last: 'Last Page'
                }
            }
        };
  • Step 5 - Provide HTML, user data and PDF path for 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",
      type: "",
    };
    // By default a file is created but you could switch between Buffer and Streams by using "buffer" or "stream" respectively.
  • Step 6 - 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);
      });

If Conditional Checks

You can do conditional checks by calling helper block ifCond example

{{#ifCond inputData "===" toCheckValue}}
<!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: {{#ifCond this.age '===' '26'}}</li>
      <br />
      {{/ifCond}}
      {{/each}}
    </ul>
  </body>
</html>

Can check variables with different type ie string, integer, boolean, double

Other logical operators are-:

  • ==
     {{#ifCond inputData "==" toCheckValue}}
  • ===
     {{#ifCond inputData "===" toCheckValue}}
  • !=
     {{#ifCond inputData "!=" toCheckValue}}
  • !==
     {{#ifCond inputData "!==" toCheckValue}}
  • <
     {{#ifCond inputData "<" toCheckValue}}
  • <=
     {{#ifCond inputData "<=" toCheckValue}}
  • '>
     {{#ifCond inputData ">" toCheckValue}}
  • '>=
     {{#ifCond inputData ">=" toCheckValue}}
  • &&
     {{#ifCond inputData "&&" toCheckValue}}
  • ||
     {{#ifCond inputData "||" toCheckValue}}

##NOTE!! You can only match 2 variables

End

License

pdf-creator-node is MIT licensed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].