npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

docx-ts

v0.1.6

Published

Convert HTML documents to docx format with header and footer.

Downloads

55

Readme

docx-ts

NPM version

- [FIRST VERSION] - Be indulgent and curious!

Convert HTML document to docx format with header and footer.

Installing

npm install docx-ts

Usage

Support Browser environment, including nextjs/vue/react/angular.

Example:

Here's an example of how to use the :

Simple without header or footer :

import { asBlob } from "html-docx-ts";
import { saveAs } from "file-saver"; //save the file

const exportDocx = () => {
  //You can add style to element you want, the body manages it completely.
  const htmlSource = `
  <div>
    <h1> H1 in the docx html </h1>
    <p> Test docx html </p>
  </div>
  `;
  const options = { orientation: "portrait", margins: {} };

  asBlob({
    htmlSource: htmlSource,
    options: options
  }).then((blob) => {
    saveAs(blob as Blob, "Name of the docx");
  })

};

Exemple with header or footer :

import { asBlob } from "html-docx-ts";
import { saveAs } from "file-saver"; //save the file

const exportDocx = () => {
  //You can add style to element you want, the body manages it completely.
  const htmlSource = `
  <div>
    <h1> H1 in the docx html </h1>
    <p> Test docx html </p>
  </div>
  `;

  const options = { orientation: "portrait", margins: {} };

  //For the header and footer, you need to start with a <p> tag. The parser will have an easier time knowing how to parse
  const  headerSource: {
    leftSideSource: "<p>LeftSide</p>",
    centerSource: "<p>CenterSide</p>",
    rightSideSource: "<p><img src='base64 src' alt='image alt' /></p>",
  };

  const footerSource: {
    leftSideSource: "<p>Page</p>",
    centerSource: "<p>{PAGE_NUM}</p>",
    rightSideSource: "<p>{PAGE_NUM}/{TOTAL_PAGES}</p>",
  };

  asBlob({
    htmlSource: htmlSource,
    options: options,
    headerSource : headerSource,
    footerSource: footerSource,
  }).then((blob) => {
    saveAs(blob as Blob, "docName");
  })

};

How to have page numbering : : The library takes page numbering into account. For simple numbering, you can use {PAGE_NUM}, otherwise you can write {PAGE_NUM}/{TOTAL_PAGES} to get the numbering with the total of pages.

Collaboration

Don't hesitate to collaborate on the project! I created it for my end-of-study internship, and I'm glad the lib can help. So don't hesitate to be curious!

Peace ✌️

License

MIT

Thanks to

html-docx-js html-docx-ts