Problema - Applet de impressão no cliente

0 respostas
A

Bom dia pessoal.

Estou com uma duvida sobre impressão na LPT1 no cliente.
Bom, ena empresa que trabalho temos um sistema em VB6 pra emissão de conhecimento de transporte. Devido a diversidade de formulários de impressão por causa da legislação em cada estado, temos em um banco de dados MSSql, algumas tabelas que guardam os parametros de impressão, como: Nome da Fonte: “Draft 15CPI”, codigo do parametro, nome da impressora. Temos também uma tabela que guarda a linha e colua referente a cada parametro pra cada formulario. Essa tabela que é o meu problema. Eu já consegui um codigo pra fazer a impressão na LPT1, porem não sei em qual formato (px,vbtwips) que esse codigo imprime. A minha tabela ta em VbTwips, ja tentei converter pra pixel so que nao sai a mesma coisa. Gostaria de saber se alguem pode me ajudar. segue a baixo o meu codigo:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Impressao;

import gnu.io.CommPortIdentifier;
//import gnu.io.SerialPort;
//import gnu.io.SerialPortEvent;
//import gnu.io.SerialPortEventListener;
import gnu.io.ParallelPort;
import gnu.io.ParallelPortEvent;
import gnu.io.ParallelPortEventListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 *
 * @author adriano.forster
 */
public class SerialComLeitura implements Runnable, ParallelPortEventListener {
    public String Dadoslidos; 
    public int nodeBytes; 
    private int baudrate; 
    private int timeout;     
    //private CommPortIdentifier cp;
    private ParallelPort porta; 
    private OutputStream saida;
    private InputStream entrada; 
    private Thread threadLeitura;
    private boolean IDPortaOK;
    private boolean PortaOK;
    private boolean Leitura;
    private boolean Escrita;
    private String Porta;
    protected String peso;

    public void setPeso(String peso){
        this.peso = peso;
        
    }

    public String getPeso(){
        return peso;
    }

    public SerialComLeitura( String p , int b , int t ){
        this.Porta = p;
        this.baudrate = b;
        this.timeout = t;
    }

    public void HabilitarEscrita(){
        Escrita = true;
        Leitura = false;
    }

    public void HabilitarLeitura(){
        Escrita = false;
        Leitura = true;
    }

    public void ObterIdDaPorta(){
       /* try {
            cp = CommPortIdentifier.getPortIdentifier(Porta);
            if ( cp == null ) {
                System.out.println("Erro na porta");
                IDPortaOK = false;
                System.exit(1);
            }
            IDPortaOK = true;
        } catch (Exception e) {
            System.out.println("Erro obtendo ID da porta: " + e);
            IDPortaOK = false;
            System.exit(1);
        }   */ 
    }
    
    public void AbrirPorta(){
        try {
            porta.setMode(porta.LPT_MODE_ANY);// = ParallelPort;//cp.open("SerialComLeitura", timeout);
            
            PortaOK = true;
            //configurar parâmetros
            //porta..setParallelPortParams(baudrate,porta.DATABITS_8,porta.STOPBITS_1,porta.PARITY_NONE);
            porta.setMode(ParallelPort.LPT_MODE_ANY);//SerialPort.FLOWCONTROL_NONE);
        }catch(Exception e){
            PortaOK = false;
            System.out.println("Erro abrindo comunicação: " + e);
            System.exit(1);
        }
    }
    
    public void LerDados(){
        if (Escrita == false){
            try {
                entrada = porta.getInputStream();
            } catch (Exception e) {
                System.out.println("Erro de stream: " + e);
                System.exit(1);
            }
            try {
                porta.addEventListener(this);
            } catch (Exception e) {
                System.out.println("Erro de listener: " + e);
                System.exit(1);
            }
            porta.notifyOnBuffer(true);
            try {
                threadLeitura = new Thread(this);
                threadLeitura.start();
               run();
            } catch (Exception e) {
                System.out.println("Erro de Thred: " + e);
            }
        }
    }
    
    
    public void EnviarUmaString(String msg){

        if (Escrita==true) {
            try {
                saida = porta.getOutputStream();
                System.out.println("FLUXO OK!");
            } catch (Exception e) {
                System.out.println("Erro.STATUS: " + e );
            }
            try {
                System.out.println("Enviando um byte para " + Porta );
                System.out.println("Enviando : " + msg );
                saida.write(msg.getBytes());
                Thread.sleep(100);
                saida.flush();
            } catch (Exception e) {
                System.out.println("Houve um erro durante o envio. ");
                System.out.println("STATUS: " + e );
                System.exit(1);
            }
        } else {
            System.exit(1);
        }
    }


    public void run(){
        try {
            Thread.sleep(5);
        } catch (Exception e) {
            System.out.println("Erro de Thred: " + e);
        }
    }

    /*public void ParallelEvent(ParallelPortEvent ev){        
        StringBuffer bufferLeitura = new StringBuffer();
        int novoDado = 0;
        switch (ev.getEventType()) {            
            case ParallelPortEvent.PAR_EV_ERROR:
            break;
            case ParallelPortEvent.PAR_EV_BUFFER:
                //Novo algoritmo de leitura.
                while(novoDado != -1){
                    try{
                        novoDado = entrada.read();
                        if(novoDado == -1){
                            break;
                        }
                        if('\r' == (char)novoDado){
                            bufferLeitura.append('\n');
                        }else{
                            bufferLeitura.append((char)novoDado);
                        }
                    }catch(IOException ioe){
                        System.out.println("Erro de leitura serial: " + ioe);
                    }
                }
                setPeso(new String(bufferLeitura));
                System.out.println(getPeso());
            break;
        }
    }*/
    
    public void FecharCom(){
            try {
                porta.close();
            } catch (Exception e) {
                System.out.println("Erro fechando porta: " + e);
                System.exit(0);
            }
    }
    
    public String obterPorta(){
        return Porta;
    }
    
    public int obterBaudrate(){
        return baudrate;
    }

    public void parallelEvent(ParallelPortEvent ev) {
         StringBuffer bufferLeitura = new StringBuffer();
        int novoDado = 0;
        switch (ev.getEventType()) {            
            case ParallelPortEvent.PAR_EV_ERROR:
            break;
            case ParallelPortEvent.PAR_EV_BUFFER:
                //Novo algoritmo de leitura.
                while(novoDado != -1){
                    try{
                        novoDado = entrada.read();
                        if(novoDado == -1){
                            break;
                        }
                        if('\r' == (char)novoDado){
                            bufferLeitura.append('\n');
                        }else{
                            bufferLeitura.append((char)novoDado);
                        }
                    }catch(IOException ioe){
                        System.out.println("Erro de leitura serial: " + ioe);
                    }
                }
                setPeso(new String(bufferLeitura));
                System.out.println(getPeso());
            break;
        }
    }

}
Criado 11 de janeiro de 2010
Respostas 0
Participantes 1