I had a similar specification, and I understood it with an additional print view.
There you can get additional data from the controller and enable a special CSS style. When using bootstrap, consider that the resolution used for PDF printing is very small, so you need to use the col-xs-* classes.
In my case, Print-View was called by ResultPrint.cshtml, and in the controller I had this function:
public ActionResult GeneratePDF(int id) { InputPrintModel model = db.InputPrintModel.Find(id); if (model == null) { return HttpNotFound(); } try { return new ViewAsPdf("ResultPrint", model); } catch (Exception ex) {
which was called in my Result.cshtml as follows:
@Html.ActionLink("Generate PDF", "GeneratePDF", new { id = Model.Id })
EDIT
When you look at this answer fooobar.com/questions/380758 / ... , you can see that you can use .cshtml files in your user settings (I have not tested this code)
public ActionResult ViewPDF() { string cusomtSwitches = string.Format("--print-media-type --allow {0} --footer-html {0} --footer-spacing -10", Url.Action("Footer", "Document", new { area = ""}, "https")); return new ViewAsPdf("MyPDF.cshtml", model) { FileName = "MyPDF.pdf", CustomSwitches = customSwitches }; } [AllowAnonymous] public ActionResult Footer() {
source share