Currently the code below exports and compacts the PDF one at a time and I need to export multiple PDF into a compressed file
public ActionResult PDFTodosMesAtual(ProcessamentoRegistros _processamento)
{
try
{
string _nomeArquivo = string.Empty;
//AQUI RETORNO UM LISTA DE DOCUMENTOS HTML QUE SERÁ CONVERTIDO EM PDF
IEnumerable<ProcessamentoRegistros> _todosHtmlMesAtual = _IRepositorio.ObterTodosHTMLMesAtual();
if (_todosHtmlMesAtual != null)
{
//TENTEI FAZE ALGO ASSIM, MAS SEM SUCESSO:
//foreach (var item in _todosHtmlMesAtual)
#region :: converte arquivo html para pdf ::
_nomeArquivo = "Documento_Fiscal_" + DateTime.Now.ToString().Replace(" ", "_").Replace("/", "_").Replace(":", "_") + ".zip";
MemoryStream file = null;
var pechkin = Factory.Create(new GlobalConfig());
var _pdf = pechkin.Convert(new ObjectConfig()
.SetLoadImages(true).SetZoomFactor(1)
.SetPrintBackground(true)
.SetScreenMediaType(true)
.SetCreateExternalLinks(true)
.SetIntelligentShrinking(true).SetCreateInternalLinks(true)
.SetAllowLocalContent(true), item.DocumentoHtml.ToString());
file = new MemoryStream();
file.Write(_pdf, 0, _pdf.Length);
byte[] arquivo = _pdf;
#endregion
#region :: compacta e faz o download do arquivo pdf ::
using (var compressedFileStream = new MemoryStream())
{
using (var zipArchive = new ZipArchive(compressedFileStream, ZipArchiveMode.Update, false))
{
var zipEntry = zipArchive.CreateEntry("documento.pdf");
using (var originalFileStream = new MemoryStream(file.ToArray()))
{
using (var zipEntryStream = zipEntry.Open())
{
originalFileStream.CopyTo(zipEntryStream);
}
}
}
return new FileContentResult(compressedFileStream.ToArray(), "application/zip") { FileDownloadName = _nomeArquivo };//return RedirectToAction("Index", "Documento");
}
#endregion
}
else
{
return RedirectToAction("Index", "Documento");
}
}
catch (Exception ex)
{
ViewBag.MsgErro = string.Format("Download não efetuado! " + ex.Message.ToString());
return RedirectToAction("Index", "Documento");
}
}
I started this post here insert the link description here with credits from Geroge Wurthmann