1.0.4 • Published 1 year ago

html-convertor v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

HtmlConvertor

This library provides an easy way to convert HTML elements into PDF or tables into XLSX files. With just a few lines of code, you can transform your HTML content into a downloadable PDF or XLSX file.

Usage

Include it as a script in your HTML

You can include the library as a script in your HTML file, like this:

<header>
  <!--take care of your file path-->
  <script src="./exceljs.min.js" ></script>
  <script src="./FileSaver.min.js" ></script>
  <script src="./html2pdf.bundle.min.js" ></script>
  <script src="./table2excel.core.js" ></script>
</header>

<script type="module">
  import { toPdf, tableToExcel } from "./htmlConverter.js";
</script>

HTML to PDF

You can use the toPdf() function to convert any HTML element into a PDF file. The function takes two parameters:

toPdf(selector, filename);
  • selector: Required. A string that specifies the HTML element you want to convert. This can be any valid CSS selector, such as #myElement or .myClass.
  • filename: Optional. A string that specifies the name of the downloaded file, without the file extension.

Here's an example of how to use the toPdf() function:

toPdf('#content', 'myFile');

This will convert the HTML element with the ID content into a PDF file named myFile.pdf.

Table to XLSX

You can use the tableToExcel() function to convert a table element into an XLSX file. The function takes two parameters:

tableToExcel(selector, filename);
  • selector: Required. A string that specifies the table element you want to convert. This can be any valid CSS selector, such as #myTable or .myTableClass.
  • filename: Optional. A string that specifies the name of the downloaded file, without the file extension. Here's an example of how to use the tableToExcel() function:
tableToExcel('#myTable', 'myFile');

This will convert the table element with the ID myTable into an XLSX file named myFile.xlsx.

Note that the tableToExcel() function only works with table elements.

Dependencies

https://github.com/JackGit/table2excel.js

https://github.com/eKoopmans/html2pdf.js

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago