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.
expensive, straight to the printer I never sent, because I develop in web, but I have a function that saves in pdf
– Pablo Tondolo de Vargas
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.
– Priscilla
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
– Pablo Tondolo de Vargas