0.1.1 • Published 4 months ago

w-print v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

W-Print

Library that prints a section of HTML to the printer.

Install

Using npm

npm install w-print

or pnpm

pnpm add w-print

How to use?

Being framework-agnostic in JavaScript, you can use it with React, Vue.js, Angular, Vanilla.js, etc

Example using vue 3

import {printContent} from 'w-print'
const printFn = async () => {
  // Call to the printContent function with an object of parameters
  await printContent({
    id: 'printhis', // Identifier for the tag
    // Note: In this version, you can pass this function even if not used
    beforeOpenCallback() {
      // Callback function before opening the print
      // Even if not used, it needs to be provided
      // It can be left empty if not used
    },
    openCallback() {
      // Callback function when opening the print
      // You can provide logic here as needed
    },
    closeCallback() {
      // Callback function when closing the print
      // You can provide logic here as needed
    },
  });
};

<template>
<div>
   <p id="printhis">Hi, print this!!</p>
   <button @click="printFn">Print</button>
</div>

</template>

w-print API

ParameExplainTypeOptionalValueDefaultValue
idRange print ID, required valueString
standardDocument type (Print local range only)Stringhtml5/loose/stricthtml5
extraHead<head></head>Add DOM nodes in the node, and separate multiple nodes with , (Print local range only)String
extraCss<link> New CSS style sheet , and separate multiple nodes with ,(Print local range only)String-
popTitle<title></title> Content of label (Print local range only)String-
openCallbackCall the successful callback function of the printing toolFunctionReturns the instance of Vue called at that time-
closeCallbackClose the callback function of printing tool successFunctionReturns the instance of Vue called at that time-
beforeOpenCallbackCallback function before calling printing toolFunctionReturns the instance of Vue called at that time-
urlPrint the specified URL. (It is not allowed to set the ID at the same time)string--
asyncUrlReturn URL through 'resolve()'Function--
previewPreview toolBoolean-false
previewTitlePreview tool TitleString-preview imp
previewPrintBtnLabelThe name of the preview tool buttonString-imp
zIndexCSS of preview tool: z-indexString,Number-20002
previewBeforeOpenCallbackCallback function before starting preview toolFunctionReturns the instance of Vue-
previewOpenCallbackCallback function after fully opening preview toolFunctionReturns the instance of Vue-

original idea by kxlee

0.1.1

4 months ago

0.1.0

6 months ago