Print Report Reporter directly, without preview

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 only support Windows Forms, that is, the application ends up searching for the printer installed on the application server, client browser printer.

Follow Report Designer code:

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 some way to turn the PDF generated by the Report Viewer into an impression, it would also be very useful.

    
asked by anonymous 10.12.2014 / 17:36

1 answer

1

So, I use the following code to generate 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 think it's just you getting the PDF and sending the command to the printer.

    
11.12.2014 / 12:23