A Node.js module that makes Virtual IPP Printer
npm install virtual-printer
``typescript
import { Printer, HandledJob, FastifyRequest } from 'virtual-printer';
const printer = new Printer({ //default options
serverUrl: new URL('http://0.0.0.0:3000'),
printerUriSupported: new URL('ipp://0.0.0.0:3000'),
name: 'Printer',
description: 'IPP Printer created by NodeJS',
location: '0.0.0.0',
moreInfo: new URL('ipp://0.0.0.0:3000'),
format: ['application/pdf'],
bonjour: true,
})
printer.on('server-opened', (error) => {
console.error(error);
});
printer.on('data', (handledJob: HandledJob, data: Buffer, request: FastifyRequest) => {
console.log(handledJob, request.url);
writeFileSync(resolve('output/', handledJob.createdAt + '.ps'), data);
});
`
#### new Printer(PrinterOptions)
The Printer object can be initialized with an object containing:
- serverUrl: URL|stringserverUrl
- For fastify listing host and port.
- If is string, listen on socket.bonjour: boolean
- true
- will publish printer server to bonjour network using @homebridge/ciao.name: string
- Printer
- Name of the printer. (default: )printer-name (name(127))
- rfc8011#5.4.4: printerUriSupported: URL
- printer-uri-supported (1setOf uri)
- URL for requesting print job for client.
- rfc8011#5.4.1: description: string
- printer-info (text(127))
- rfc8011#5.4.6: location: string
- printer-location (text(127))
- rfc8011#5.4.5: moreInfo: string
- printer-more-info (uri)
- rfc8011#5.4.7: format: string[]
- document-format-default
- Formats in string array must be taken from IANA MIME types.
- First string in string array will set to . document-format-default (mimeMediaType)
- rfc8011 #5.4.21: document-format-supported (1setOf mimeMediaType)
- rfc8011 #5.4.22:
All attributes need to follow rules by RFC 8011 and IANA MIME types.
#### Event: data
Emitted when server received new print job.
The handledJob: HandledJob is an instance of [HandleJob]().data: Buffer is data part parsed from request. request: FastifyRequest
A instance of request.body will Buffer and including data and request body.
`typescript
import { HandledJob, FastifyRequest } from 'virtual-printer';
printer.on('data', (handledJob: HandledJob, data: Buffer, request: FastifyRequest) => {
console.log(handledJob, request.url);
// const rawRequest = request.data;
writeFileSync(resolve('output/', handledJob.createdAt + '.ps'), data);
});
`
#### Event: server-opened
Emitted when server started. The error: Error is from fastify server.
`typescript`
printer.on('server-opened', (error?: Error | null) => {
console.error(error);
});
#### Event: bonjour-published
Emitted when server published to bonjour network.
`typescript`
printer.on('bonjour-published', () => {
console.log('Server published to bonjour');
});
#### Event: bonjour-name-change
Emitted when server name changed which published to bonjour network. The name: string is new name that published to bonjour network.
`typescript`
printer.on('bonjour-name-change', (name: string) => {
console.log('Bonjour name changed', name);
});
#### Event: bonjour-hostname-change
Emitted when local hostname changed. The hostname: string is new name from your local.
`typescript`
printer.on('bonjour-name-change', (hostname: string) => {
console.log('Bonjour hostname changed', hostname);
});
#### handleJobs: HandleJob[]
The jobs that printer received.
#### startedAt: Date
#### server: FastifyInstance
The fastify instance that server listening.
#### printerOption: PrinterOptions
Printer options when you constructed with default values.
#### job-id: number
The id of the job.
#### job-state: number
The state of the job. Always 9. (rfc8011#5.3.7 completed)
#### job-name: string
The name of the job from request. If name cannot parse, it will be new Date().toISOString().
#### job-originating-user-name: string
The username of the job from request. If username cannot parse, it will be anonymous.
#### createdAt: Date`
The creation date of the job.
MIT