Printing windows Forms with direct reportviewer on printer

Asked

Viewed 908 times

1

I have an application made in windows forms and reportviewer, my problem is in printing:

I need to print right to the printer without having to open the check box to select the printer

How to do this in 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();
        }
  • It would be interesting to post part of the code you have already done, so we can indicate based on this the best solution to your problem.

  • Make sure this post doesn’t suit you (if you haven’t seen it already). http://answall.com/questions/43561/imprimir-relat%C3%B3rio-do-reportviewer-diretamente-sem-pr%C3%A9-visualiza%C3%A7%C3%A3o and please edit your question by adding the code you posted as a comment.

  • Opa Ismael thanks for the attention, but I’ve seen this post yes and it hasn’t helped me yet...

2 answers

1


Well come on... in my case I did printing on a matrix printer.. best way I found was using String Bilder..

Print code

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());
}

Print code.

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

Performs local automatic file printing.

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;

    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.