public void ExportBrief(IEnumerable <Card> deck)
        {
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
            Table           table   = builder.StartTable();

            foreach (Card c in deck)
            {
                builder.InsertCell();
                if (c.Question == null)
                {
                    builder.Write("");
                }
                else
                {
                    builder.Write(c.Question);
                }


                // Build the second cell
                builder.InsertCell();
                if (c.Answer == null)
                {
                    builder.Write("");
                }
                else
                {
                    builder.Write(c.Answer);
                }

                // Call the following method to end the row and start a new row.
                builder.EndRow();
            }


            table.SetBorders(LineStyle.None, 0, Color.White);;

            // Signal that we have finished building the table.
            builder.EndTable();


            MemoryStream dstStream = new MemoryStream();

            doc.Save(dstStream, SaveFormat.Docx);

            BlazorDownloadFileService.DownloadFile("out.docx", dstStream, "application/octet-stream");
        }
        public async Task OnClickDownloadViaHttpClientButton()
        {
            // Please imagine the situation that the downloading files API is protected by
            // token-based authorization (not cookie-based authorization).
            // In that case, the user can not download it from the href link of the anchor tag directly.
            // In this scenario, the application has to get a byte array of the file from
            // the API endpoint by HttpClient with token and make the byte array can be downloadable.
            var fileName = "/Users/themakers/Documents/PREDICAS/archivo1.PDF";//"/Users/themakers/Documents/PREDICAS/Nivel Biblico 1.pdf";

            using var call = FileClient.DownloadStream(new FileRequest { Path = fileName });
            // var bytes = await HttpClient.GetByteArrayAsync("pictures/1");
            try
            {
                var result = new StringBuilder();
                Console.WriteLine("Descargando archivo.");
                await foreach (var message in call.ResponseStream.ReadAllAsync())
                {
                    result.Append(Encoding.UTF8.GetString(message.Content.ToByteArray()));
                }
                // byte[] file = Encoding.ASCII.GetBytes(result.ToString());



                Console.WriteLine("iniciando descarga local archivo.");

                // int bufferSize =65536;// 32768; new MemoryStream(Convert.FromBase64String(Base64Nyan)), "application/octet-stream"))>Dowload Nyan From Stream</button>
                // string contentType = "application/octet-stream";
                await BlazorDownloadFileService.DownloadFile("nombrearchivo.pdf",
                                                             new MemoryStream(Convert.FromBase64String(result.ToString())), "application/pdf");

                //   await JSRuntime.SaveAs( fileName, Convert.FromBase64String(result.ToString()));
                Console.WriteLine("termina descarga ");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"DownloadFile Exception => Message {ex.Message} - InnerExceptionMessage {(ex.InnerException != null ? ex.InnerException.Message : "No InnerException")}");
            }
        }
Ejemplo n.º 3
0
 protected async Task GenerarClaves()
 {
     Byte[] ficheroZip = ServicioSeguridad.GenerarClavesRSA();
     await BlazorDownloadFileService.DownloadFile("claves_rsa.zip", Convert.ToBase64String(ficheroZip));
 }