3

ファイル(PDF、ドキュメントなど)をプリンター(hp Laser-jet 4250dtn)に送信するためにJavaでlprクライアントを作成しています。クライアントとサーバーの両方でUNIXが実行されています。

プリンターはサーバー上にあります(これがlprを使用している理由です)すべてが順調で、実際にソケットを開いて、制御ファイル(RFC 1179に準拠)を送信し、ファイル自体を送信しています。

ファイルはプリンタの「キュー」に到達しています。

私の問題は、プリンターからファイルを印刷したいときに、ファイルが間違って表示され、まったく理解できないことです(テキストが表示されないのは奇妙な記号だけです)。

私の質問は、プリンターが私を理解できるようにするために、私が与えるまたは作成する(ファイルをpostscriptに変更する??)ファイルタイプの叫びです。それとも私は何か間違ったことをしていますか?

ここにコードを添付して、ファイルパスからファイルを開いている行を確認して強調表示できるようにします。

Socket socketLpr = getSocket(hostName);
    socketLpr.setSoTimeout(30000);
    OutputStream sOut = socketLpr.getOutputStream();
    InputStream sIn = socketLpr.getInputStream();

    //Open printer
    s = "\002" + printerName + "\n";
    sOut.write(s.getBytes());
    sOut.flush();
    acknowledge(sIn, "lpr Failed to open printer");

    //Send control file     
    controlFile += "H" + hostName + "\n";
    controlFile += "P" + userName + "\n";
    controlFile += ((printRaw) ? "o":"p") +"dfA" + strJobNumber + hostName + "\n";
    controlFile += "UdfA" + strJobNumber + hostName + "\n";
    controlFile += "N" + documentName + "\n";

    s = "\002" + (controlFile.length()) + " cfA" + strJobNumber + hostName + "\n";
    sOut.write(s.getBytes());

    acknowledge(sIn, "lpr Failed to send control header");

    buffer = controlFile.getBytes();
    sOut.write(buffer);
    buffer[0] = 0;
    sOut.write(buffer, 0, 1);
    sOut.flush();

    acknowledge(sIn, "jLpr Failed to send control file");

    //Send print file       
    **f = new File(fileName);** // <- here is when im oppening the file(pdf,word,etc)
    if (!(f.exists() && f.isFile() && f.canRead())) {
        throw new IOException("jLpr Error opening print file");
    }
    s = "\003" + (f.length()) + " dfA" + strJobNumber + hostName + "\n";
    sOut.write(s.getBytes());
    sOut.flush();
    acknowledge(sIn, "jLpr Failed to send print file command");

    FileInputStream fs = new FileInputStream(f);

    int readCounter;
    do {
        readCounter = fs.read(buffer);
        if (readCounter>0) {
            sOut.write(buffer, 0, readCounter);
        }
    } while (readCounter>0);
    buffer[0] = 0;
    sOut.write(buffer,0,1);
    sOut.flush();
    acknowledge(sIn, "jLpr Failed to send print file");

    socketLpr.close();
}
4

0 に答える 0