
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
light-print
Advanced tools
🖨️ Lightweight HTML element printing for browsers.
🚀 View an online usage example.
npm i light-print
# or
yarn add light-print
# or
pnpm add light-print
CDN
<!-- After importing, `window.lightPrint` is globally available. -->
<script src="https://cdn.jsdelivr.net/npm/light-print@2"></script>
If the browser doesn't support Promise (e.g., Internet Explorer), a global polyfill is required.
Print container elements and their descendants.
After the browser displays the print dialog:
import lightPrint from 'light-print';
lightPrint('#id', {
// Modify different aspects of printed pages.
mediaPrintStyle: '@page { size: A4 portrait }',
}).then(() => {
// Executes when the print dialog closes.
});
<script setup>
import { useTemplateRef } from 'vue';
import lightPrint from 'light-print';
// Prior to Vue v3.5, we could declare a `ref` matching the name of the template’s ref attribute value.
const targetRef = useTemplateRef('target');
async function print() {
await lightPrint(targetRef.value);
}
</script>
<template>
<div ref="target">
<!-- some nodes -->
</div>
</template>
import { useRef } from 'react';
import lightPrint from 'light-print';
function MyComponent() {
const targetRef = useRef(null);
async function print() {
await lightPrint(targetRef.current);
}
return <div ref={targetRef}>{/* some nodes */}</div>;
}
The same approach works with other frameworks/libraries.
interface PrintOptions {
/** Document title */
documentTitle?: string;
/** Additional print styles */
mediaPrintStyle?: string;
/** Document zoom level */
zoom?: number | string;
}
function lightPrint(containerOrSelector: Element | string, options?: PrintOptions): Promise<void>;
Is this compatible with React/Vue/Angular?
Works with all frameworks! See our framework examples.
How to handle page breaks?
Use CSS page break properties, e.g.
.page-break {
page-break-after: always;
break-after: page;
}
How to implement headers/footers?
Configure via paged media in the mediaPrintStyle, or set page margins to zero and manually implement the DOM structure for headers/footers.
Why are some styles missing after printing?
Because those styles may be inherited from the parent; you need to restate them (e.g., background) directly on the print-element container.
@font-face within the mediaPrintStyle, for example:
const mediaPrintStyle = `
@font-face {
font-family: 'PrintFont';
src: url('print-font.woff2') format('woff2');
}
`;
FAQs
Lightweight HTML element printing for browsers.
The npm package light-print receives a total of 9 weekly downloads. As such, light-print popularity was classified as not popular.
We found that light-print demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.