|
Rank: Newbie Groups: Member
Joined: 7/31/2015 Posts: 6
|
So I have been trying to figure out this problem for a long time now, but now I require help :p I think that there is a problem using the RenderAsPDF attribute on an async MVC controller such as : [RenderAsPDF] [AllowAnonymous] public async Task<ActionResult> GenerateSummary(long distributorId, long quotationId) The problem is the following: It does not take into account my HtmlToPDF options defined as such: HtmlToPdf.Options.PageSize = new SizeF(8.5f, 11f); HtmlToPdf.Options.OutputArea = new RectangleF(0.5f, 0.5f, 7.5f, 10f); // And then I return my view with a view model. return this.View("~/Views/QuotationDocuments/Summary/QuotationSummary.cshtml", viewModel); However, the PDF is always rendered with 1 inch margins: http://grab.by/JgyCHas this ever happened to someone? Thanks, Jonathan
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, Thanks for posting in the forum. This appears to be a problem on our side. Can you create a small test project and send the test project to us? See here for more instructions on how to send the test project: http://www.essentialobjects.com/forum/test_project.aspxWe will look into it as soon as we receive it. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 7/31/2015 Posts: 6
|
Just sent the test project with additional informations on what to look for!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Thank you very much for the test project. We will look into it and get back to you as soon as possible.
|
|
Rank: Newbie Groups: Member
Joined: 7/31/2015 Posts: 6
|
Hi! Have you guys has the time to look at the issue?
Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, Please put the corresponding code inside AsycManager.Sync call:
Code: C#
AsyncManager.Sync(() =>
{
HtmlToPdf.Options.PageSize = new SizeF(8.5f, 11f);
HtmlToPdf.Options.OutputArea = new RectangleF(0.5f, 0.5f, 7.5f, 10f);
});
This will run the code inside the original HTTP context thread. Because HtmlToPdf.Options maintains a different value per thread, as long as you switch to the correct thread to set it, it will work for you. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 7/31/2015 Posts: 6
|
Hi, Thanks for your reply. I have tried the solution you mentionned but unfortunately it does not seem to be working. I have tried it in the test project I have sent you and I still get the 1 inch margins sometimes. Here is the modified code for the async method now:
Code: C#
[RenderAsPDF]
[AllowAnonymous]
public async Task<ActionResult> AsyncPdf()
{
// This method runs asynchronously.
await Task.Run(() => Allocate());
this.AsyncManager.Sync(() =>
{
HtmlToPdf.Options.PageSize = new SizeF(8.5f, 11f);
HtmlToPdf.Options.OutputArea = new RectangleF(0.5f, 0.5f, 7.5f, 10f);
});
return this.View("AsyncPDF");
}
Am i not applying your fix correctly? (Note that the code snippet due to the forum displays only Task has return type but in fact is Task<ActionResult>) Thanks.
|
|
Rank: Newbie Groups: Member
Joined: 7/31/2015 Posts: 6
|
Hi,
Any news for me?
Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, We tested the code here and it works fine. Another thing you can try is to set the PageSize and OutputArea inside BeforeConvertHandler. BeforeConvertHandler is a callback method that you can pass to the RenderAsPDF method: http://www.essentialobjects.com/doc/eo.pdf.mvc.mvctopdf.renderaspdf_overload_1.aspxYou can pass a callback method to the first argument and then set the HtmlToPdf.Options inside that callback method. This method is guaranteed to be called in the same thread as the converter. Note that this method is only added not long ago. So if you have an older version, you may not have this method. In that case please try to update to the latest build first. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 7/31/2015 Posts: 6
|
Ha...
Apparently the fix is not working on my dev machine, but it is working on our staging environment on Azure. I'm guessing .NET 4.6 or IIS Express caused the problem for some reason...
Anyways it's working now so thanks for the help!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Great. Thank you very much for the update. Please feel free to let us know if there is anything else.
|
|