|
Rank: Newbie Groups: Member
Joined: 5/28/2014 Posts: 9
|
I'm trying to use the MVCToPDF feature along with the HtmlToPdf.Options but I'm having some trouble. When I set HtmlToPdf.Options using the Pdf.ConvertUrl function the options take effect, but using MVCToPDF they do not. This is the controller action I'm using:
Code: C#
[RenderAsPDF(ResultAsDownload = true, SendToClient = true)]
public async Task<ActionResult> PDF(int id)
{
Item item= new Item();
ItemContext context = new ItemContext();
ItemService service = new ItemService(context);
item= await service.GetAsync(id);
item= await service.UpdateAsync(item, id);
HtmlToPdf.Options.PageSize = EO.Pdf.PdfPageSizes.A4;
HtmlToPdf.Options.OutputArea = new System.Drawing.RectangleF(0.25f, 0.25f, 8f, 10.5f);
MVCToPDF.ResultAsDownload = true;
MVCToPDF.ResultFileName = item.name + ".pdf";
MVCToPDF.RenderAsPDF();
return View("Print", item);
}
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, I believe you can set the options by overriding your Controller class' OnResultExecuted. For example:
Code: C#
protected override void OnResultExecuted(ResultExecutedContext filterContext)
{
//Set page size and output area
HtmlToPdf.Options.PageSize = EO.Pdf.PdfPageSizes.A4;
HtmlToPdf.Options.OutputArea = new System.Drawing.RectangleF(0.25f, 0.25f, 8f, 10.5f);
//Conversion is done on this step
base.OnResultExecuted(filterContext);
}
Please let us know if it works for you. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 5/28/2014 Posts: 9
|
That did the trick, thank you!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Great. Glad to hear that it works for you! Please feel free to let us know if there is anything else.
Thanks!
|
|