Skip to content

Commit

Permalink
added README and fixed charset bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuth committed Mar 14, 2020
1 parent 7827dc4 commit 686357d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# ipp-printjob-kotlin

A minimal ipp client implementation for jvm written in kotlin.


### Build

In order to build the software you need an installed JDK.

./gradlew

When the build has finished you can find `printjob.jar` in `build/libs`

### Distribution

If you don't want to build the software [binary releases](https://github.com/gmuth/ipp-printjob-kotlin/releases) are provided.

### Usage

The tool takes two arguments: *printer-uri* and *file-name*. \
The url scheme `ipp://` is not supported - use `http://` instead. \
If you don't know the printer uri try `ippfind`.

java -jar printjob.jar http://colorjet:631/ipp/printer A4-blank.pdf

send ipp request to http://colorjet:631/ipp/printer
ipp response status: 0000
group 01
attributes-charset (47) = utf-8
attributes-natural-language (48) = en
group 02
job-uri (45) = ipp://colorjet:631/jobs/352
job-id (21) = 352
job-state (23) = 3
job-state-reasons (44) = none
group 03

### Document Format

The operation attributes group does not include a value for `document-format`.
This should be equivalent to `application/octet-stream` indicating the printer has to auto sense the document format.
You have to make sure the printer supports the document format you send - PDF is usually a good option.
1 change: 1 addition & 0 deletions demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!printjob.jar
2 changes: 1 addition & 1 deletion demo/go
Original file line number Diff line number Diff line change
@@ -1 +1 @@
java -jar ../build/libs/printjob.jar http://localhost:8632/printers/laser A4-blank.pdf
java -jar printjob.jar http://localhost:8632/printers/laser A4-blank.pdf
Binary file added demo/printjob.jar
Binary file not shown.
16 changes: 8 additions & 8 deletions src/main/kotlin/ipp/printjob.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ipp

// --------------------
// Author: Gerhard Muth
// Date : 14.3.2020
// --------------------

import java.io.*
import java.net.HttpURLConnection
import java.net.URI
Expand All @@ -30,13 +30,13 @@ fun printJob(uri: URI, documentInputStream: InputStream) {
write(value.toByteArray(charset))
}
writeShort(0x0200) // ipp version
writeShort(0x0002) // OPERATION Print-Job
writeShort(0x0002) // print job operation
writeInt(0x002A) // request id
writeByte(0x01) // GROUP operation-attributes-tag
writeAttribute(0x47, "attributes-charset", "$charset") // ATTR charset attributes-charset utf-8
writeAttribute(0x48, "attributes-natural-language", "en") // ATTR language attributes-natural-language en
writeAttribute(0x45, "printer-uri", "$uri") // ATTR uri printer-uri $uri
writeByte(0x03) // GROUP end-tag
writeByte(0x01) // operation group tag
writeAttribute(0x47, "attributes-charset", charset.name().toLowerCase())
writeAttribute(0x48, "attributes-natural-language", "en")
writeAttribute(0x45, "printer-uri", "$uri")
writeByte(0x03) // end tag
close()
byteArrayOutputStream.close()
byteArrayOutputStream.toByteArray()
Expand All @@ -46,7 +46,7 @@ fun printJob(uri: URI, documentInputStream: InputStream) {
println("send ipp request to $uri")
val ippResponse = with(uri.toURL().openConnection() as HttpURLConnection) {
val ippContentType = "application/ipp"
setConnectTimeout(3)
setConnectTimeout(3000)
setDoOutput(true)
setRequestProperty("Content-Type", ippContentType)
val ippRequestInputStream = ippRequest.inputStream()
Expand Down

0 comments on commit 686357d

Please sign in to comment.