1

Tenho uma aplicação feita em windows forms e reportviewer, o meu problema está na impressão:

preciso mandar imprimir direto na impressora sem ter que abrir a caixa de seleção para selecionar a impressora

Como fazer isso em c#?

    private void btnImprimir_Click(object sender, EventArgs e)
    {
        PrintReport();
    }

    public void PrintReport()
    {
        for (int i = 0; i < int.Parse(txtVolume.Text); i++)
        {
            this.EtqTransportePSTableAdapter.Fill_EtqPS(this.EtqTransportePSDataSet.EtqTransportePS, txtNota.Text);
            this.reportViewer1.PrintDialog();
        }
3
  • Seria interessante você postar parte do código que já fez, desta forma poderemos indicar com base nisso a melhor solução para seu problema. 12/01/2017 às 19:29
  • Verifique se esse post não lhe serve (se já não viu). pt.stackoverflow.com/questions/43561/… e por favor, edite sua pergunta acrescentando o código que colocou como comentário. 13/01/2017 às 12:13
  • Opa Ismael obrigado pela atenção, mas ja vi este post sim e não me ajudou ainda... 13/01/2017 às 12:48

2 Respostas 2

1

Bem vamos lá... no meu caso eu fiz imprimindo em um impressora matricial.. melhor maneira que encontrei foi usando String Bilder..

Codigo de impressão

private void PrencherArquivo(DataTable dt, NotaFiscal item, ClienteAG cliente)
{
    StringBuilder sb = new StringBuilder();
    sb.Append(((char)27).ToString()).Append("C").AppendLine(((char)18).ToString());
    sb.AppendLine("");
    sb.AppendLine("");
    sb.AppendLine("");
    sb.AppendLine("");
    for (int i = 1; i <= item.volqte; i++)
    {
        sb.AppendLine(cliente.nome);
        sb.AppendLine("");
        sb.AppendLine(cliente.logradouro + "-" + cliente.numeroendereco);
        sb.AppendLine(cliente.bairro + "-" + cliente.mun_ufd_sigla);
        sb.AppendLine("CEP:" + cliente.cep);
        sb.AppendLine("");
        sb.AppendLine("");
        sb.AppendLine(item.numero + "                  " + item.volpeso.ToString("N1"));
        sb.AppendLine("");
        sb.AppendLine("            VOLUME " + i + " DE " + item.volqte);
        if (item.volqte > i)
        {
            sb.AppendLine("");
            sb.AppendLine("");
            sb.AppendLine("");
            sb.AppendLine("");
            sb.AppendLine("");
            sb.AppendLine("");
            sb.AppendLine("");
            sb.AppendLine("");
        }
        else
        {
            sb.AppendLine("");
            sb.AppendLine("");
            sb.AppendLine("");
        }
    }
    sb.Append(((char)27).ToString()).AppendLine("@");
    RawPrinterHelper.SendStringToPrinter("EPSON LX-300+ /II", sb.ToString());
}

Codigo da impressão.

public static bool SendStringToPrinter(string szPrinterName, string szString)
{
    IntPtr pBytes;
    Int32 dwCount;
    // How many characters are in the string?
    dwCount = szString.Length;
    // Assume that the printer is expecting ANSI text, and then convert
    // the string to ANSI text.
    pBytes = Marshal.StringToCoTaskMemAnsi(szString);
    // Send the converted ANSI string to the printer.
    SendBytesToPrinter(szPrinterName, pBytes, dwCount);
    Marshal.FreeCoTaskMem(pBytes);
    return true;
}
0

Realiza a impressão automática local do arquivo.

public ActionResult ImprimeDocumento(string caminho)//Caminho onde está seu arquivo
    {
        if (!String.IsNullOrEmpty(caminho))
        {

            try
            {
                myPrinters.SetDefaultPrinter("Nome da sua impressora");

                Process process = new Process
                {
                    StartInfo = new ProcessStartInfo
                     {
                         CreateNoWindow = true,
                         Verb = "print",
                         FileName = caminho,
                     },
                };
                process.Start();
            }
            catch (Exception)
            {
                throw;
            }

        }
        return null;

    }

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .