Welcome Guest Search | Active Topics | Sign In | Register

HtmlToPdf.ConvertUrl taking 30+ seconds Options
Kevin
Posted: Monday, September 15, 2014 9:02:36 AM
Rank: Member
Groups: Member

Joined: 8/27/2013
Posts: 11
Hi,

I've used [RenderAsPDF(AutoConvert = false)] a lot and that works great, I now have a different scenario where I need to create a PDF attachment and send it via email.

I have it all working with:
HtmlToPdf.ConvertUrl(pdfUrl, memoryStream, options); //options contain cookie credentials

The generated PDF is only 50KB so do you have any idea why it takes 30 + seconds to generate?

Thanks,
Kevin
eo_support
Posted: Monday, September 15, 2014 9:08:49 AM
Rank: Administration
Groups: Administration

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

This is usually due to ASP.NET session lock. Please see here for a detailed description of the problem:

http://www.essentialobjects.com/forum/postst8527_This-session-is-no-longer-valid-If-you-wish-to-reuse-the-session-later-please-consider-calling-GetCookies-to-retain-the-sessio.aspx

Generally, you should avoid calling ConvertUrl back to your own site. If you wish to send the page via email, you can follow the steps here:

http://www.essentialobjects.com/doc/4/web/mvc.aspx#save

The sample code calls PdfDocument.Save to save the file into a physical file. If you do not want a physical file, you can use a MemoryStream and save it to a MemoryStream instead. Then you can get a get byte array from the MemoryStream and pass that to your email module.

Thanks!

Kevin
Posted: Monday, September 22, 2014 9:58:45 AM
Rank: Member
Groups: Member

Joined: 8/27/2013
Posts: 11
Have you got an example of an action that calls another action that has the PDF attribute on it?

e.g.

public ActionResult MethodA()
{
var pdfStream = GeneratePdf();

//How do I get a memoryStream of the view GeneratedPdf?

return View();
}

[RenderAsPDF(AutoConvert = false, SendToClient = false)]
public ActionResult GeneratePdf()
{
return View();
}

Thanks,
Kevin
eo_support
Posted: Monday, September 22, 2014 10:55:19 AM
Rank: Administration
Groups: Administration

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

I am not sure if I understand your question correctly. If you wish to call one action directly as a function from another action, it shouldn't have anything to do with RenderAsPDF attribute.

Thanks!
Kevin
Posted: Wednesday, October 1, 2014 4:39:22 AM
Rank: Member
Groups: Member

Joined: 8/27/2013
Posts: 11
Hi,

In my example, OnResultExecuted is called twice but the result is empty for the the action GeneratePdf(). I only want an attachment PDF generated for GeneratedPdf() but it needs to be called via MethodA().

[RenderAsPDF(SendToClient = false)]
public ActionResult MethodA()
{
var pdfStream = GeneratePdf();

//How do I get a memoryStream of the view GeneratedPdf?

return View();
}

[RenderAsPDF(SendToClient = false)]
public ActionResult GeneratePdf()
{
return View();
}

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

EO.Pdf.HtmlToPdfResult result = MVCToPDF.Result;

if (result != null)
{
//this is null for GeneratePdf();
//I only get a result for MethodA(); when I open that PDF I get 'Object moved here' and the word 'here' is a URL to the page that I want a PDF generated of.
}
}
eo_support
Posted: Wednesday, October 1, 2014 10:45:37 AM
Rank: Administration
Groups: Administration

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

I am still not exactly sure what you are trying to do. You can try to isolate the problem into a test project and send the test project to us and we will be happy to take a look. Please see test project guideline here:

http://www.essentialobjects.com/forum/test_project.aspx

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.