Welcome Guest Search | Active Topics | Sign In | Register

MVCToPDF OutputArea Options
Cypress North
Posted: Wednesday, May 28, 2014 6:14:20 PM
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);
        }
eo_support
Posted: Wednesday, May 28, 2014 11:54:39 PM
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!
Cypress North
Posted: Thursday, May 29, 2014 9:27:15 AM
Rank: Newbie
Groups: Member

Joined: 5/28/2014
Posts: 9
That did the trick, thank you!
eo_support
Posted: Thursday, May 29, 2014 9:55:21 AM
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!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.