I am working on a report which requires multiple PDF files to download in one zip file and as well as create a new PDF file and save that new created file on server as well. I am using DotNetZip
and Rotativa
for zip and pdf files.
Currently i have this in my Controller
:
[HttpGet]
public ActionResult GetReport()
{
var test2 = new ActionAsPdf("ContractorReportNew");
var zip = new ZipFile();
zip.AddFile("MyFile.zip", "Orders");
string zipName = string.Format("Contractor Report{0}.zip", DateTime.Now.ToString("dd-MMM-yyyy-HH:mm:ss"));
using (MemoryStream memoryStream = new MemoryStream())
{
zip.Save(memoryStream);
return File(memoryStream.ToArray(), "application/zip", zipName);
}
}
And
[HttpGet]
public ActionResult ContractorReportNew()
{
//Data from DB
var test = new ViewAsPdf("Contractor_report")
{
MinimumFontSize = 14,
PageOrientation = Rotativa.Options.Orientation.Landscape,
PageSize = Rotativa.Options.Size.A4,
};
var abc = test.BuildFile(this.ControllerContext);
System.IO.File.WriteAllBytes(path, abc);
MemoryStream ms = new MemoryStream(abc);
return new FileStreamResult(ms, "application/pdf");
}
How can i achieve what i need?
Any help would be much appreciated.
I managed to get it work by using this example.
Now i have this in my code:
@Html.ActionLink("Test Me", "Contractor_report", "Admin", new { @contractor_id = 1 }, new { @onclick = "TestFunction()" })
and then:
function TestFunction() {
window.open('@Url.Action("ContractorReportNew", "Admin")')
}