Install Rotativa menggunakan NuGet
Pilih yang dibuat oleh Giorgio Bozio.
Contoh:
[code language=”csharp”]
[HttpPost]
public ActionResult Download(ManufacturerDownloadFormStub model)
{
List<int> subcategoryId = model.GetSubcategoryIdArray();
DisplayFormatHelper dfh = new DisplayFormatHelper();
return new Rotativa.ActionAsPdf("ManufacturerPdf", new { subcategoryId = model.SubcategoryIdString })
{
FileName = "AML (" + DateTime.Now.ToString(dfh.FullDateFormat) + ").pdf",
PageOrientation = Rotativa.Options.Orientation.Portrait,
PageSize = Rotativa.Options.Size.A4,
CustomSwitches = string.Format("–footer-right \"[page] / [toPage]\" "
+ "–footer-font-size \"8\" "
+ "–footer-spacing \"3\" ")
};
}
public ViewResult ManufacturerPdf(string subcategoryId)
{
ManufacturerDownloadFormStub downloadForm = new ManufacturerDownloadFormStub { SubcategoryIdString = subcategoryId };
List<vendor_subcategory> dbItem = null;
List<int> subcategoryIdArray = downloadForm.GetSubcategoryIdArray();
if (subcategoryIdArray != null && subcategoryIdArray.Count() > 0)
dbItem = RepoLicensor.FindVendorSubcategory(subcategoryIdArray);
ManufacturerPdfModel model = new ManufacturerPdfModel();
model.Parse(dbItem);
return View(model);
}
[/code]
Parameter yang dikirim ke ManufacturerPdf amannya berupa string. Sempat dicoba mengirimkan List<int> tidak terbaca.
