Print Reportviewer report directly, without preview

Asked

Viewed 3,455 times

2

I need to send a report directly to the printer, without preview or PDF generation.

The problem is that the application is Web Forms and all the solutions I’ve found so far provide support only for Windows Forms, that is, the application ends up searching for the printer installed on the application server instead of the client’s browser printer.

Follow code from Report Viewer:

reportViewer.ProcessingMode = ProcessingMode.Remote;
reportViewer.ServerReport.ReportServerCredentials = new ReportCredentials(_user, _password, _domain);
reportViewer.ServerReport.ReportServerUrl = new Uri(_reportUrl);
reportViewer.ShowParameterPrompts = true;
reportViewer.ServerReport.ReportPath = "/Report";
reportViewer.ServerReport.SetParameters(ConfigureParameters());
reportViewer.ServerReport.Refresh();

Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;

var file = reportViewer.ServerReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);

If someone knows any way to turn the PDF generated by Report Viewer into a print, it would also be very useful.

  • expensive, straight to the printer I never sent, because I develop in web, but I have a function that saves in pdf

  • My function is also already saved in PDF. The problem is that the application cannot download the pdf, as it is the mandatory printing of this report. I’ll find a way to send this pdf directly to the printer.

  • try to take a look at this link, if I’m not mistaken I’ve done something like http://www.codeproject.com/Tips/598424/How-to-Silently-Print-PDFs-using-Adobe-Reader-and

1 answer

1


So I use the following code to generate the PDF

       LocalReport relatorio = new LocalReport();
        relatorio.EnableExternalImages = true;

        relatorio.ReportPath = HttpContext.Current.Server.MapPath("~/Admin/Financeiro/NotaFiscalEletronica/Danfe/NotaFiscalEletronicaDanfeReport.rdlc");


        ReportParameter codigoBarrasParameter = new ReportParameter();
        codigoBarrasParameter.Name = "CodigoBarras";
        string codeBarArquivo = String.Format(@"file://{0}\{1}-codBarras.png", this.CaminhoXML, chaveAcesso);
        codigoBarrasParameter.Values.Add(codeBarArquivo);
        relatorio.SetParameters(codigoBarrasParameter);

        DanfeReports nfeReport = new DanfeReports();

        relatorio.DataSources.Add(new ReportDataSource("IdeDataSet", nfeReport.NotaFiscalEletronicaIdentificacao(chaveAcesso)));
        relatorio.DataSources.Add(new ReportDataSource("EmiDataSet", nfeReport.NotaFiscalEletronicaEmitente(chaveAcesso)));
        relatorio.DataSources.Add(new ReportDataSource("DestDataSet", nfeReport.NotaFiscalEletronicaDestinatario(chaveAcesso)));
        relatorio.DataSources.Add(new ReportDataSource("ValTotDataSet", nfeReport.NotaFiscalEletronicaValoresTotais(chaveAcesso)));
        relatorio.DataSources.Add(new ReportDataSource("TranspDataSet", nfeReport.NotaFiscalEletronicaInformacoesTransporte(chaveAcesso)));
        relatorio.DataSources.Add(new ReportDataSource("ProdSevDataSet", nfeReport.NotaFiscalEletronicaProdutoServico(chaveAcesso)));
        relatorio.DataSources.Add(new ReportDataSource("InfAdicDataSet", nfeReport.NotaFiscalEletronicaInformacoesAdicionais(chaveAcesso)));

        string reportType = "PDF";
        string mimeType;
        string encoding;
        string fileNameExtension;

        Warning[] warnings;
        string[] streams;
        byte[] bytes;

        //Renderiza o relatório em bytes
        bytes = relatorio.Render(
            reportType,
            null,
            out mimeType,
            out encoding,
            out fileNameExtension,
            out streams,
            out warnings);

        MemoryStream memoryStream = new MemoryStream(bytes);
        memoryStream.Seek(0, SeekOrigin.Begin);

        string arquivo = String.Format("{0}.pdf", chaveAcesso);

        SaveMemoryStream(this.CaminhoXML, arquivo, memoryStream);`

        public bool SaveMemoryStream(string caminho, string nomeArquivo, MemoryStream memoryStream)
    {
        if (!Directory.Exists(caminho))
            Directory.CreateDirectory(caminho);

        FileStream file = new FileStream(caminho + @"\" + nomeArquivo, FileMode.Create, System.IO.FileAccess.Write);
        byte[] bytes2 = new byte[memoryStream.Length];
        memoryStream.Read(bytes2, 0, (int)memoryStream.Length);
        file.Write(bytes2, 0, bytes2.Length);
        file.Close();
        memoryStream.Close();


        return true;
    }`

I believe it’s just you taking the PDF and sending the command to the printer.

  • What he wants to know is how to "send the command to the printer".

Browser other questions tagged

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