Exemple #1
0
        public void XmlPasta()
        {
            var arquivos = Directory.EnumerateFiles("../../XmlTestes", "*.xml");

            foreach (var arquivo in arquivos)
            {
                try
                {
                    DanfeViewModel model = DanfeViewModel.CreateFromXmlFile(arquivo);
                    using (DanfeDocumento danfe = new DanfeDocumento(model))
                    {
                        danfe.Gerar();

                        using (MemoryStream ms = new MemoryStream())
                        {
                            danfe.Salvar(ms);
                        }
                    }
                }
                catch (Exception e)
                {
                    Debugger.Break();
                }
            }
        }
Exemple #2
0
        public static void GerarDanfe(String xmlPath, String logoPath)
        {
            try
            {
                DanfeViewModel model = DanfeViewModel.CreateFromXmlFile(xmlPath);
                DanfeDocumento danfe = new DanfeDocumento(model);

                if (!String.IsNullOrWhiteSpace(logoPath))
                {
                    danfe.AdicionarLogo(logoPath);
                }

                danfe.Gerar();

                String outFile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(xmlPath), model.ChaveAcesso + ".pdf");
                danfe.Salvar(outFile);

                var process = System.Diagnostics.Process.Start(outFile);

                if (process == null)
                {
                    MessageBox.Show(String.Format("Não foi possível abrir o DANFE gerado.\nEle foi gravado em: {0}", outFile), Strings.AppName, MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Erro ao gerar o DANFE", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public void DanfeRetratoKabum()
        {
            var model = (DanfeViewModel.CreateFromXmlFile(@"C:\Users\ricar\Downloads\32161205570714000825550010017054141078477682.xml"));

            model.Orientacao = Orientacao.Retrato;

            Danfe d = new Danfe(model);

            d.AdicionarPagina();
            d.AdicionarPagina();
            d.AdicionarPagina();
            d.PreencherNumeroFolhas();

            d.Salvar("DanfeRetrato.pdf");
        }