Skip to content

Conversation

@ClemersonAssuncao
Copy link
Owner

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • Test update

Testing

Platforms Tested

  • Windows
  • Linux
  • macOS

Test Results

# Paste test results here
npm test

Checklist

  • My code follows the project's code style
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Breaking Changes

Additional Notes

BREAKING CHANGES:
- Migrated from WritePrinter (winspool) to pure GDI32 rendering
- Integrated Google PDFium for high-quality PDF rendering
- Replaced string/number parameters with type-safe enums
- Removed Unix/Linux/macOS support (Windows-only)
- PDFium DLL now included in npm package

Performance:
- 44% faster overall printing (9.8s → 5.5s for 4-page document)
- 72% faster per-page rendering (~1.15s → ~0.32s per page)
- Default 300 DPI rendering with configurable quality levels

New Features:
- PrintQuality enum (LOW, MEDIUM, HIGH, ULTRA)
- PaperSize enum with 95 standard paper sizes
- DuplexMode, PageOrientation, ColorMode, PaperTray enums
- Service-based architecture (PdfRenderService, DevModeConfigService)
- Singleton PDFium instance with reference counting
- Page caching for multiple copies

Architecture:
- Separated GDI32, Winspool, Kernel32, PDFium APIs
- Clean Architecture with specialized services
- Type-safe domain types and enums
- Windows-only focus

Documentation:
- Complete README rewrite
- New CONTRIBUTING.md guide
- Updated CHANGELOG with migration guide
- Updated examples with enums
- Changed all 'node-pdf-printer' references to 'windows-pdf-printer-native'
- Updated examples to use type-safe enums instead of deprecated constants
- Fixed imports and method calls (listPrinters -> getAvailablePrinters)
- Updated GitHub repository URLs
- Removed placeholder email from support section
Copilot AI review requested due to automatic review settings December 1, 2025 17:04
@ClemersonAssuncao ClemersonAssuncao merged commit 95471ad into main Dec 1, 2025
2 of 9 checks passed

const pdfPath = './test-document.pdf';
// Check if test PDF exists
const fs = await import('fs');

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable fs.

Copilot Autofix

AI 2 months ago

To fix this issue, we need to remove the unused variable import statement on line 28 (const fs = await import('fs');). No changes to functionality will result, as fs is re-imported in the scope where it is actually needed (example 3, line 78). Edit examples/advanced-print.ts by deleting line 28 and adjusting surrounding whitespace if necessary. No other changes are required or suggested.

Suggested changeset 1
examples/advanced-print.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/examples/advanced-print.ts b/examples/advanced-print.ts
--- a/examples/advanced-print.ts
+++ b/examples/advanced-print.ts
@@ -25,7 +25,6 @@
   console.log(`Using printer: ${printer.getPrinterName()}\n`);
   
   // Check if test PDF exists
-  const fs = await import('fs');
   const pdfPath = './examples/test-document.pdf';
   
   // Advanced printing with all options
EOF
@@ -25,7 +25,6 @@
console.log(`Using printer: ${printer.getPrinterName()}\n`);

// Check if test PDF exists
const fs = await import('fs');
const pdfPath = './examples/test-document.pdf';

// Advanced printing with all options
Copilot is powered by AI and may make mistakes. Always verify output.
@@ -0,0 +1,107 @@
// DEVMODE Configuration Service
import type { PrintOptions } from '../../../core/types';
import { DuplexMode, PageOrientation, ColorMode } from '../../../core/types';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused imports ColorMode, DuplexMode, PageOrientation.

Copilot Autofix

AI 2 months ago

The best way to fix this problem is to remove the unused imports—specifically DuplexMode, PageOrientation, and ColorMode—from the import statement on line 3 of src/adapters/windows/services/devmode-config.service.ts. This improves code clarity and maintainability. Only the PrintOptions type on line 2 is actually used. No other edits are required.

Suggested changeset 1
src/adapters/windows/services/devmode-config.service.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/adapters/windows/services/devmode-config.service.ts b/src/adapters/windows/services/devmode-config.service.ts
--- a/src/adapters/windows/services/devmode-config.service.ts
+++ b/src/adapters/windows/services/devmode-config.service.ts
@@ -1,6 +1,6 @@
 // DEVMODE Configuration Service
 import type { PrintOptions } from '../../../core/types';
-import { DuplexMode, PageOrientation, ColorMode } from '../../../core/types';
+
 import {
   OpenPrinterW,
   ClosePrinter,
EOF
@@ -1,6 +1,6 @@
// DEVMODE Configuration Service
import type { PrintOptions } from '../../../core/types';
import { DuplexMode, PageOrientation, ColorMode } from '../../../core/types';

import {
OpenPrinterW,
ClosePrinter,
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +4 to +17
import {
OpenPrinterW,
ClosePrinter,
DocumentPropertiesW,
PRINTER_ACCESS_USE,
PRINTER_DEFAULTS,
DM_IN_BUFFER,
DM_OUT_BUFFER,
DM_ORIENTATION,
DM_PAPERSIZE,
DM_DUPLEX,
DM_COLOR,
DM_DEFAULTSOURCE
} from '../api';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import PRINTER_DEFAULTS.

Copilot Autofix

AI 2 months ago

To fix the problem, we need to remove the unused import PRINTER_DEFAULTS from the destructured import statement on line 4. This means editing the import statement on lines 4–17 so that PRINTER_DEFAULTS is no longer listed among the imported symbols. No other changes are necessary, since no other references to PRINTER_DEFAULTS exist in the provided file.

Suggested changeset 1
src/adapters/windows/services/devmode-config.service.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/adapters/windows/services/devmode-config.service.ts b/src/adapters/windows/services/devmode-config.service.ts
--- a/src/adapters/windows/services/devmode-config.service.ts
+++ b/src/adapters/windows/services/devmode-config.service.ts
@@ -6,7 +6,6 @@
   ClosePrinter,
   DocumentPropertiesW,
   PRINTER_ACCESS_USE,
-  PRINTER_DEFAULTS,
   DM_IN_BUFFER,
   DM_OUT_BUFFER,
   DM_ORIENTATION,
EOF
@@ -6,7 +6,6 @@
ClosePrinter,
DocumentPropertiesW,
PRINTER_ACCESS_USE,
PRINTER_DEFAULTS,
DM_IN_BUFFER,
DM_OUT_BUFFER,
DM_ORIENTATION,
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +2 to +7
import {
OpenPrinterW,
ClosePrinter,
PRINTER_ACCESS_USE,
PRINTER_DEFAULTS
} from '../api';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import PRINTER_DEFAULTS.

Copilot Autofix

AI 2 months ago

The best way to fix the problem is to remove the unused import, PRINTER_DEFAULTS, from the import statement on line 2. The rest of the code does not reference this symbol, and its removal will enhance code clarity and avoid unnecessary imports. This requires editing the import statement in src/adapters/windows/services/printer-connection.service.ts to delete PRINTER_DEFAULTS from the import list.


Suggested changeset 1
src/adapters/windows/services/printer-connection.service.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/adapters/windows/services/printer-connection.service.ts b/src/adapters/windows/services/printer-connection.service.ts
--- a/src/adapters/windows/services/printer-connection.service.ts
+++ b/src/adapters/windows/services/printer-connection.service.ts
@@ -2,8 +2,7 @@
 import {
   OpenPrinterW,
   ClosePrinter,
-  PRINTER_ACCESS_USE,
-  PRINTER_DEFAULTS
+  PRINTER_ACCESS_USE
 } from '../api';
 
 export class PrinterConnectionService {
EOF
@@ -2,8 +2,7 @@
import {
OpenPrinterW,
ClosePrinter,
PRINTER_ACCESS_USE,
PRINTER_DEFAULTS
PRINTER_ACCESS_USE
} from '../api';

export class PrinterConnectionService {
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR transforms the library from a cross-platform printing solution into a Windows-only, high-performance PDF printing library using GDI32 and PDFium. The change represents a complete architectural shift from WritePrinter-based printing to direct GDI rendering with PDFium, achieving 44% performance improvements while introducing type-safe enums for all print options.

Key Changes:

  • Migrated from winspool WritePrinter to GDI32 + PDFium rendering engine
  • Introduced type-safe enums (PrintQuality, PaperSize, DuplexMode, PageOrientation, ColorMode, PaperTray)
  • Removed all Unix/Linux/macOS support code and dependencies
  • Included PDFium DLL directly in npm package (no manual setup required)
  • Reorganized API bindings into separate modules (gdi32, winspool, kernel32, pdfium)
  • Added specialized services (PdfRenderService, DevModeConfigService, PrinterConnectionService)

Reviewed changes

Copilot reviewed 39 out of 41 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/windows-print-api.test.ts Updated API import path from winspool.api to graphics-device-interface.api
tests/unix-printer.test.ts Deleted - Removed Unix printer tests (Windows-only focus)
tests/printer-manager.test.ts Deleted - Consolidated into Windows-specific tests
tests/pdf-printer.test.ts Deleted - Consolidated into Windows-specific tests
tests/README.md Updated documentation to reflect Windows-only approach and new GDI+PDFium architecture
src/unix-printer.ts Deleted - Removed Unix printer implementation
src/services/platform-detector.service.ts Deleted - No longer needed (Windows-only)
src/printer-manager.ts Deleted - Moved to adapter pattern
src/pdf-printer.ts Deleted - Replaced with new GDI32-based implementation
src/index.ts Removed cross-platform exports, added enum exports, updated documentation
src/factories/printer.factory.ts Simplified to Windows-only implementation
src/core/types/index.ts Added comprehensive enum definitions for type-safe printing
src/adapters/windows/windows-printer.adapter.ts Complete rewrite using GDI32 + PDFium rendering
src/adapters/windows/windows-printer-manager.adapter.ts Simplified using new service layer
src/adapters/windows/services/printer-connection.service.ts New - Centralized printer handle management
src/adapters/windows/services/pdf-render.service.ts New - PDFium rendering with caching and performance optimization
src/adapters/windows/services/devmode-config.service.ts New - DEVMODE configuration service
src/adapters/windows/api/winspool.api.ts Refactored to focus on printer management only
src/adapters/windows/api/pdfium.api.ts New - PDFium API bindings
src/adapters/windows/api/kernel32.api.ts New - Kernel32 API bindings
src/adapters/windows/api/index.ts New - Barrel export for all Windows APIs
src/adapters/windows/api/gdi32.api.ts New - GDI32 API bindings for graphics operations
src/adapters/unix/unix-printer.adapter.ts Deleted - Removed Unix adapter
src/adapters/unix/unix-printer-manager.adapter.ts Deleted - Removed Unix printer manager
package.json Updated version to 2.0.0, removed Unix examples, restricted to Windows
examples/unix-print.ts Deleted - Removed Unix example
examples/test-performance.ts New - Performance testing example
examples/test-devmode.ts Deleted - Removed old DEVMODE testing
examples/simple-print.ts Added Portuguese comments and timing measurements
examples/duplex-print.ts Deleted - Consolidated into advanced example
examples/clean-architecture.ts Deleted - No longer relevant
examples/advanced-print.ts Complete rewrite using new enum-based API
docs/TESTING-DEVMODE.md Deleted - Documentation removed
docs/GET-PRINTJOB-VS-DEVMODE.md Deleted - Documentation removed
docs/CLEAN-ARCHITECTURE.md Deleted - Documentation removed
README.md Complete rewrite focusing on Windows + GDI + PDFium architecture
CONTRIBUTING.md Updated for Windows-only development workflow
CHANGELOG.md Added comprehensive v2.0.0 release notes
.github/workflows/release.yml Updated package name and removed non-Windows compatibility notes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// Import winApi once at module level to avoid re-importing in each test suite
let winApi: typeof import('../src/adapters/windows/api/winspool.api');
let winApi: typeof import('../src/adapters/windows/api/graphics-device-interface.api');
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import path references 'graphics-device-interface.api' which doesn't exist in the new structure. Based on the API reorganization shown in other files, this should be '../src/adapters/windows/api' or '../src/adapters/windows/api/index' to use the barrel export.

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +8
// Inicia o timer
console.time('Tempo total');
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Portuguese comments ('Inicia o timer', 'Tempo de impressão', 'Finaliza o timer total') are mixed with English code and comments. For consistency and maintainability in an open-source project, all comments should be in English.

Copilot uses AI. Check for mistakes.
defaultPaperSize: number | string;
availablePaperSizes: (number | string)[];
availablePaperSources: number[];
defaultPaperSize: PaperSize | number | string;
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The defaultPaperSize field in PrinterCapabilities allows string type, but the new PaperSize enum only contains numeric values. This inconsistency could lead to confusion. Consider removing string from the type union since the migration is moving away from string-based paper sizes.

Suggested change
defaultPaperSize: PaperSize | number | string;
defaultPaperSize: PaperSize | number;

Copilot uses AI. Check for mistakes.
Comment on lines +273 to +276
if (this.cacheEnabled) {
const cacheKey = `${pageIndex}_${options.width}_${options.height}`;
this.pageCache.set(cacheKey, renderedPage);
if (process.env.DEBUG) console.log(`[DEBUG] Page ${pageIndex} cached with key: ${cacheKey}`);
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The page cache stores rendered bitmaps but never has a maximum size limit. For PDFs with many pages, this could lead to unbounded memory growth. Consider implementing a cache size limit with an LRU eviction policy.

Copilot uses AI. Check for mistakes.
"version": "1.0.2",
"description": "A Node.js library for printing PDF documents on Windows using native DLLs",
"version": "2.0.0",
"description": "High-performance Windows PDF printing library using GDI32 and PDFium",
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package name in the diff shows 'windows-pdf-printer-native' but the CHANGELOG and other documentation reference migrating from 'node-pdf-printer'. Ensure the npm package name is correctly set and consistent across all documentation.

Suggested change
"description": "High-performance Windows PDF printing library using GDI32 and PDFium",
"description": "High-performance Windows PDF printing library using GDI32 and PDFium. Migrated from 'node-pdf-printer'.",

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants