Exemple #1
0
        public void Cecred_GerarBoletoCarteira01() {

            DateTime vencimento = new DateTime(2016, 03, 11);

            var cedente = new Cedente("00.000.000/0000-00", "Empresa Teste", "0109", "265071", "1");
            cedente.Convenio = 0110041;
            cedente.Endereco = new Endereco() {
                Bairro = "BAIRRO CEDENTE",
                CEP = "88309-600",
                Cidade = "CIDADE CEDENTE",
                Complemento = "CASA",
                Email = "*****@*****.**",
                End = "Teste CEDENTE",
                Logradouro = "Rua",
                Numero = "999",
                UF = "SC"
            };
            cedente.Codigo = cedente.Convenio.ToString();

            cedente.Carteira = "01";
            string nossoNumero = "000000127"; // Tamanho nosso numero 9

            var sacado = new Sacado("000.000.000-00", "Sacado Teste");
            sacado.Endereco = new Endereco() {
                Bairro = "BAIRRO SACADO",
                CEP = "88309-600",
                Cidade = "CIDADE SACADO",
                Complemento = "CASA",
                Email = "*****@*****.**",
                End = "Teste SACADO",
                Logradouro = "Rua",
                Numero = "999",
                UF = "SC"
            };

            BoletoNet.Boleto boleto = new BoletoNet.Boleto(vencimento, 10.99m, cedente.Carteira, nossoNumero, cedente);
            boleto.NumeroDocumento = "ABC123";
            boleto.Sacado = sacado;
            BoletoNet.BoletoBancario boletoBancario = new BoletoBancario();
            boletoBancario.CodigoBanco = 85;    // CECRED
            boletoBancario.Boleto = boleto;

            try {
                boletoBancario.Boleto.Valida();
                var htmlString = boletoBancario.MontaHtml();

                //string _arquivo = string.Empty;
                //_arquivo = string.Format(@"C:\temp\boleto_{0}.html", boletoBancario.Boleto.NumeroDocumento);

                //using (System.IO.FileStream f = new System.IO.FileStream(_arquivo, System.IO.FileMode.Create)) {
                //    System.IO.StreamWriter w = new System.IO.StreamWriter(f, System.Text.Encoding.UTF8);
                //    w.Write(htmlString);
                //}

                Assert.IsTrue(!string.IsNullOrEmpty(htmlString));
            } catch {

            }

        }
        private void MostraBoleto(BoletoBancario bb)
        {
            var html = new StringBuilder();

            html.Append(bb.MontaHtml());

            var html_st = html.ToString();

            //var boletoPathHTML = Path.Combine(Path.GetTempPath(), "Boleto.html");
            var pastaDeDestino = Server.MapPath(Util.URL_IMAGEM_CABECALHO_BOLETO);
            Compartilhados.Util.CrieDiretorio(pastaDeDestino);

            var boletoPathHTML = Server.MapPath(Util.URL_IMAGEM_CABECALHO_BOLETO + "Boleto.html");

            var f = new FileStream(boletoPathHTML, FileMode.Create);

            using (var w = new StreamWriter(f, Encoding.Default))
            {
                w.Write(html_st);
                w.Close();
                f.Close();
                //System.Diagnostics.Process.Start(boletoPathHTML); Exibe o boleto na página
            }

            //var boletoPathPDF = Path.Combine(Path.GetTempPath(), "Boleto.pdf");
            var boletoPathPDF = Server.MapPath(Util.URL_IMAGEM_CABECALHO_BOLETO + "Boleto.pdf");
            var imagePath = GerarImagem(boletoPathHTML);
            var doc2 = new Document(PageSize.A4, 46, 0, 40, 0);

            PdfWriter.GetInstance(doc2, new FileStream(boletoPathPDF, FileMode.Create));
            doc2.Open();

            var gif = iTextSharp.text.Image.GetInstance(imagePath);
            gif.ScaleAbsolute(494.0F, 785.0F);
            doc2.Add(gif);
            doc2.Close();

            //System.Diagnostics.Process.Start(@"C:\Windows\Temp\Boleto.pdf");
            AbraPdf(boletoPathPDF);
        }