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 🙏

© 2026 – Pkg Stats / Ryan Hefner

web-print-service

v1.0.11

Published

Print a website service

Readme

Hướng Dẫn Sử Dụng Print Service

Note: The user guide in English is located at the bottom of the document

Tác giả: Truongpv ([email protected])
Hỗ trợ dự án: Nếu bạn thấy dịch vụ hữu ích, hãy ủng hộ để giúp dự án phát triển:
Pham Van Truong - 229016999 - Ngân hàng A CHAU (ACB)

Dịch vụ Print Service là một API REST giúp người dùng chuyển đổi nội dung HTML hoặc URL thành tài liệu PDF và gửi chúng đến máy in. Dịch vụ này có thể được sử dụng để giúp các ứng dụng web gửi đồng thời lệnh in đến nhiều máy in. Hướng dẫn dưới đây đề cập đến các tính năng chính và cách sử dụng API này.

1. Cài đặt

1.1. Yêu cầu hệ thống

  • Node.js: Phiên bản v16 hoặc mới hơn.
  • Hệ điều hành: Windows, macOS, hoặc Linux.

1.2. Cài đặt package

npm install -g web-print-service

1.3. Cài đặt PM2 để quản lý dịch vụ

PM2 là một công cụ quản lý các tiến trình Node.js, tự động khởi động lại khi gặp lỗi và đảm bảo dịch vụ bắt đầu khi hệ thống khởi động lại.

Cài đặt PM2:

npm install -g pm2

2. Khởi tạo dịch vụ:

  1. Khởi động dịch vụ với lệnh sau:
pm2 start printservice --name "PrintService" -- start [port]
  1. Lưu cấu hình PM2 để bật tự động khởi động lại:
pm2 save
pm2 startup

Mặc định, dịch vụ sẽ chạy tại http://localhost:8081.


3. API Đầu Vào

3.1. GET /web-print

In nội dung từ URL được cung cấp qua query.

Tham số:

  • url (bắt buộc): URL của trang web.
  • printer (tuỳ chọn): Tên máy in.
  • landscape (tuỳ chọn): Định dạng ngang (1 hoặc 0). Mặc định là 0.
  • page_size (tuỳ chọn): Khổ giấy (A4, A3, letter,...).

Cách gọi:

curl --location 'http://localhost:8081/web-print?url=https://example.com&printer=MyPrinter&page_size=A4'

3.2. POST /html-print

In nội dung HTML được cung cấp qua body request.

Body (JSON):

  • html_content (bắt buộc): Nội dung HTML.

Tham số Query (tuỳ chọn):

  • printer (tuỳ chọn): Tên máy in.
  • landscape (tuỳ chọn): Định dạng ngang (1 hoặc 0).
  • page_size (tuỳ chọn): Khổ giấy.

Cách gọi:

curl --location 'http://localhost:8081/html-print' \
--header 'Content-Type: application/json' \
--data '{
    "html_content": "<div>Test Print</div>"
}'

4. Quản lý Máy In

4.1. Lệnh GET /printers

Kiểm tra danh sách máy in.

Cách gọi:

curl --location 'http://localhost:8081/printers'

Kết quả trả về là danh sách tên máy in và trạng thái của chúng.


5. Bảo trì và Dọn dẹp

Dịch vụ tự động xóa các file PDF đã lớn hơn 7 ngày trong thư mục /reports bằng cron.

  • Cron được thiết lập chạy vào 0h hàng ngày.

6. Quản lý Vấn Đề

6.1. Lỗi đọc/ghi file

Kiểm tra quyền truy cập của thư mục /reports.

6.2. Lỗi máy in offline

Kiểm tra trạng thái của máy in trong danh sách truy vấn từ /printers.


Print Service User Guide

Author: Truongpv ([email protected])
Donate: Pham Van Truong - 229016999 - A CHAU Bank (ACB)

Print Service is a REST API that allows users to convert HTML content or URLs into PDF documents and send them to a printer. This service can be used to enable web applications to send print commands to multiple printers simultaneously. The guide below covers the main features and how to use this API.

1. Installation

1.1. System Requirements

  • Node.js: Version v16 or later.
  • Operating System: Windows, macOS, or Linux.

1.2. Install the package

npm install -g web-print-service

1.3. Install PM2 to manage the service

PM2 is a tool for managing Node.js processes, restarting on errors, and ensuring the service starts after system reboots.

Install PM2:

npm install -g pm2

2. Starting the Service

  1. Start the service with the following command:
pm2 start printservice --name "PrintService" -- start [port]
  1. Save the PM2 configuration to enable auto-start on reboot:
pm2 save
pm2 startup

By default, the service will run at http://localhost:8081.


3. Input APIs

3.1. GET /web-print

Print content from a URL provided via query parameters.

Parameters:

  • url (required): The URL of the webpage.
  • printer (optional): The printer name.
  • landscape (optional): Landscape orientation (1 or 0). Default is 0.
  • page_size (optional): Paper size (A4, A3, letter, etc.).

Example Call:

curl --location 'http://localhost:8081/web-print?url=https://example.com&printer=MyPrinter&page_size=A4'

3.2. POST /html-print

Print HTML content provided in the request body.

Body (JSON):

  • html_content (required): The HTML content.

Query Parameters (optional):

  • printer: The printer name.
  • landscape: Landscape orientation (1 or 0).
  • page_size: Paper size.

Example Call:

curl --location 'http://localhost:8081/html-print' \
--header 'Content-Type: application/json' \
--data '{
    "html_content": "<div>Test Print</div>"
}'

4. Printer Management

4.1. GET /printers Command

Check the list of printers.

Example Call:

curl --location 'http://localhost:8081/printers'

The result will return the list of printer names and their statuses.


5. Maintenance and Cleanup

The service automatically deletes PDF files older than 7 days in the /reports directory using a cron job.

  • The cron job is set to run at midnight daily.

6. Issue Management

6.1. File Read/Write Errors

Check the access permissions for the /reports directory.

6.2. Printer Offline Errors

Check the printer status in the list queried from /printers.