-
Notifications
You must be signed in to change notification settings - Fork 1
Clean code #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean code #8
Conversation
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
|
|
||
| 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
Show autofix suggestion
Hide autofix suggestion
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.
| @@ -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 |
| @@ -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
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R3
| @@ -1,6 +1,6 @@ | ||
| // DEVMODE Configuration Service | ||
| import type { PrintOptions } from '../../../core/types'; | ||
| import { DuplexMode, PageOrientation, ColorMode } from '../../../core/types'; | ||
|
|
||
| import { | ||
| OpenPrinterW, | ||
| ClosePrinter, |
| 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
Show autofix suggestion
Hide autofix suggestion
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.
| @@ -6,7 +6,6 @@ | ||
| ClosePrinter, | ||
| DocumentPropertiesW, | ||
| PRINTER_ACCESS_USE, | ||
| PRINTER_DEFAULTS, | ||
| DM_IN_BUFFER, | ||
| DM_OUT_BUFFER, | ||
| DM_ORIENTATION, |
| import { | ||
| OpenPrinterW, | ||
| ClosePrinter, | ||
| PRINTER_ACCESS_USE, | ||
| PRINTER_DEFAULTS | ||
| } from '../api'; |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R5
| @@ -2,8 +2,7 @@ | ||
| import { | ||
| OpenPrinterW, | ||
| ClosePrinter, | ||
| PRINTER_ACCESS_USE, | ||
| PRINTER_DEFAULTS | ||
| PRINTER_ACCESS_USE | ||
| } from '../api'; | ||
|
|
||
| export class PrinterConnectionService { |
There was a problem hiding this 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'); |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
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.
| // Inicia o timer | ||
| console.time('Tempo total'); |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
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.
| defaultPaperSize: number | string; | ||
| availablePaperSizes: (number | string)[]; | ||
| availablePaperSources: number[]; | ||
| defaultPaperSize: PaperSize | number | string; |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
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.
| defaultPaperSize: PaperSize | number | string; | |
| defaultPaperSize: PaperSize | number; |
| 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}`); |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
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.
| "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", |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
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.
| "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'.", |
Description
Type of Change
Testing
Platforms Tested
Test Results
Checklist
Breaking Changes
Additional Notes