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 🙏

© 2025 – Pkg Stats / Ryan Hefner

printer-pdf-electron-node

v1.4.4

Published

node bindings for printer pdf node and electron

Readme

printer-pdf-electron-node

Uma biblioteca Node.js para impressão de arquivos PDF com suporte avançado a configurações de impressão. Funciona com Node.js e Electron.

Características

  • 🖨️ Impressão direta de PDFs para qualquer impressora do sistema
  • 📏 Suporte a diferentes tamanhos de papel (A4, Letter, Legal, A3, Custom)
  • 📑 Impressão de páginas específicas ou intervalos
  • 🔄 Ajuste automático do conteúdo à página
  • 📐 Configuração precisa de margens
  • 🎯 Controle de DPI para qualidade de impressão
  • 📚 Impressão de múltiplas cópias
  • 💪 Suporte completo a TypeScript

Requisitos

  • Node.js >= 18.20.6
  • Electron >= 20.0.0
  • Windows ou Linux
  • Para Windows: Visual Studio Build Tools
  • Para Linux: CUPS development headers (sudo apt-get install libcups2-dev)

Instalação

npm install printer-pdf-electron-node

Para desenvolvimento:

git clone https://github.com/Alexssmusica/printer-pdf-electron-node.git
cd printer-pdf-electron-node
npm install
npm run rebuild

Uso

JavaScript

const { printPDF } = require('printer-pdf-electron-node');

// Exemplo básico
async function imprimirDocumento() {
    try {
        await printPDF({
            filePath: 'caminho/do/documento.pdf',
            printerName: 'Nome da Impressora'
        });
        console.log('Documento enviado para impressão');
    } catch (error) {
        console.error('Erro ao imprimir:', error);
    }
}

// Exemplo com todas as opções
async function imprimirDocumentoAvancado() {
    try {
        await printPDF({
            // Parâmetros obrigatórios
            filePath: 'caminho/do/documento.pdf',
            printerName: 'Nome da Impressora',
            
            // Parâmetros opcionais
            pageList: [[1, 3], [5, 7]], // Imprime páginas 1-3 e 5-7
            paperSize: 'A4',            // 'A4' | 'LETTER' | 'LEGAL' | 'A3' | 'CUSTOM'
            margins: {
                top: 0.5,    // margens em polegadas
                right: 0.5,
                bottom: 0.5,
                left: 0.5
            },
            fitToPage: true,  // ajusta o conteúdo à página
            width: 0,         // largura personalizada (usado apenas com paperSize: 'CUSTOM')
            height: 0,        // altura personalizada (usado apenas com paperSize: 'CUSTOM')
            dpi: 300,        // resolução de impressão
            copies: 1        // número de cópias
        });
        console.log('Documento enviado para impressão');
    } catch (error) {
        console.error('Erro ao imprimir:', error);
    }
}

TypeScript

import { printPDF, PrintPDFOptions, PaperSize, Margins } from 'printer-pdf-electron-node';

// Definindo as margens
const margins: Margins = {
    top: 0.5,
    right: 0.5,
    bottom: 0.5,
    left: 0.5
};

// Configurando todas as opções
const options: PrintPDFOptions = {
    filePath: 'caminho/do/documento.pdf',
    printerName: 'Nome da Impressora',
    pageList: [[1, 3], [5, 7]],
    paperSize: 'A4',
    margins,
    fitToPage: true,
    dpi: 300,
    copies: 1
};

async function imprimirDocumento() {
    try {
        const resultado = await printPDF(options);
        console.log(resultado); // 'Print job created successfully'
    } catch (error) {
        console.error('Erro ao imprimir:', error);
    }
}

API

printPDF(options: PrintPDFOptions): Promise<string>

Opções

| Parâmetro | Tipo | Obrigatório | Padrão | Descrição | |--------------|---------------------------|-------------|---------|----------------------------------------------| | filePath | string | Sim | - | Caminho do arquivo PDF | | printerName | string | Sim | - | Nome da impressora | | pageList | Array<[number, number]> | Não | [] | Lista de intervalos de páginas para imprimir | | paperSize | PaperSize | Não | 'A4' | Tamanho do papel | | margins | Margins | Não | {0,0,0,0}| Margens em polegadas | | fitToPage | boolean | Não | true | Ajustar conteúdo à página | | width | number | Não | 0 | Largura personalizada (em pontos) | | height | number | Não | 0 | Altura personalizada (em pontos) | | dpi | number | Não | 300 | Resolução de impressão | | copies | number | Não | 1 | Número de cópias |

Tipos

type PaperSize = 'A4' | 'LETTER' | 'LEGAL' | 'A3' | 'CUSTOM';

interface Margins {
    top?: number;    // em polegadas
    right?: number;  // em polegadas
    bottom?: number; // em polegadas
    left?: number;   // em polegadas
}

Notas

  • As margens são especificadas em polegadas (1 polegada = 25.4mm)
  • Para tamanhos de papel personalizados (paperSize: 'CUSTOM'), width e height são especificados em pontos (1 ponto = 1/72 polegada)
  • O DPI padrão é 300, que oferece um bom equilíbrio entre qualidade e performance
  • A opção fitToPage garante que o conteúdo se ajuste à área imprimível da página

Licença

Apache-2.0