Welcome Guest Search | Active Topics | Sign In | Register

Setting page orientation when using RenderAsPDF attribute with MVC Options
H
Posted: Thursday, September 12, 2013 11:38:40 AM
Rank: Member
Groups: Member

Joined: 9/12/2013
Posts: 11
Hi, I have an MVC3 project and the current versions of EO.PDF.dll (5.0.34.2), EO.Pdf.Mvc.dll (5.0.34.2) and EO.PDF.Mvc3.dll (5.0.34.2) added as references.

I'm using the [RenderAsPDF] attribute on one of the methods in my controller but the PDF is created in 'portrait' orientation (i.e. the width is less than the height) and I don't know how to manipulate this. I tried doing this:

protected override void OnResultExecuted(ResultExecutedContext filterContext)
{
base.OnResultExecuted(filterContext);

HtmlToPdfResult result = MVCToPDF.Result;
if (result != null)
{
result.PdfDocument.Pages[0].Size.Height = PdfPageSizes.A4.Width;
result.PdfDocument.Pages[0].Size.Width = PdfPageSizes.A4.Height;
result.PdfDocument.Save(string.Format("c:\\mydownloads\\{0}", MVCToPDF.ResultFileName));
}

}


but the page size properties are unaffected by my attempt to change them.

Is there a way to do this?

Thanks!
eo_support
Posted: Thursday, September 12, 2013 11:53:49 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

Please try to do this and see if it works:

Code: C#
HtmlToPdf.Options.PageSize = 
    new SizeF(PdfPageSizes.A4.Height, PdfPageSize.A4.Width);


Inside your action method (where you apply RenderAsPDF attribute).

Thanks!
H
Posted: Friday, September 13, 2013 5:07:11 AM
Rank: Member
Groups: Member

Joined: 9/12/2013
Posts: 11
Thanks - that's exactly what I needed :)
eo_support
Posted: Friday, September 13, 2013 8:59:20 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Glad that it works for you. Please feel free to let us know if you have any more questions.

Thanks!
H
Posted: Friday, September 13, 2013 9:11:28 AM
Rank: Member
Groups: Member

Joined: 9/12/2013
Posts: 11
eo_support wrote:
Please feel free to let us know if you have any more questions.


OK :) In the same context as above, can I create text in the 'header' and 'footer' spaces of a PDF created in this way? e.g. Page 1 of 3, Customer Order Report, things like that? I don't need images or any formatting.

Thanks!
eo_support
Posted: Friday, September 13, 2013 9:31:59 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

You would just call ConvertHtml again inside your action class's OnResultExecuted. That's when you can do "post process" with your files. You would do something like this:

Code: C#
//Set the output area
HtmlToPdf.Options.OutputArea = .....

//Render some HTML to the first page
HtmlToPdf.ConvertHtml("header", MVCToPDF.Result.PdfDocument.Pages[0]);


This would allow you to add anything anywhere on an existing page.

Thanks!
H
Posted: Monday, September 16, 2013 5:17:56 AM
Rank: Member
Groups: Member

Joined: 9/12/2013
Posts: 11
eo_support wrote:
Hi,

You would just call ConvertHtml again inside your action class's OnResultExecuted. That's when you can do "post process" with your files. You would do something like this:

Code: C#
//Set the output area
HtmlToPdf.Options.OutputArea = .....

//Render some HTML to the first page
HtmlToPdf.ConvertHtml("header", MVCToPDF.Result.PdfDocument.Pages[0]);


This would allow you to add anything anywhere on an existing page.

Thanks!


Thank you for the speedy response - top class customer service! :)
eo_support
Posted: Monday, September 16, 2013 8:38:41 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Glad to hear that. You are very welcome!


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.