Logo
My Account |  Site Map | Contact Us  
Welcome Guest Search | Active Topics | Sign In | Register

HtmlToPdf in MVC creates an empty pdf or just hangs and times out Options
WMP
Posted: Friday, September 6, 2019 7:58:14 AM
Rank: Advanced Member
Groups: Member

Joined: 7/6/2011
Posts: 30
I am trying to create and download a simple pdf using MVC but am having problems.

With Htmltopdf.converturl it just times out or loads comaniestopdf as an empty page

Quote:

[HttpPost]
public void CompaniesToPdf()
{
//no result, times out.
string url = "http://www.google.com";
PdfDocument doc = new PdfDocument();
HtmlToPdf.Options.NoScript = true;
HtmlToPdf.ConvertUrl(url, doc);
}


With HtmlToPdf.ConvertHtml it creates and downloads a pdf but it is completely empty.

Quote:
[HttpPost]
[RenderAsPDF]
public void CompaniesToPdf()
{
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertHtml("test", doc);
}


Can you please help me sort out the syntax?
eo_support
Posted: Tuesday, September 10, 2019 4:35:40 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 21,568
Hi,

I am not sure if I understand your intention correctly ---- your action method needs to return an ActionResult object, typically through View() method. MVCToPDF works by intercepting the result returned by your action method and then convert that result to PDF, which otherwise would be sent to the browser directly. So it won't work if your method returns void, and it wouldn't make sense for you to call HtmlToPdf.ConvertUrl/ConvertHtml in your action method either.

Thanks!
WMP
Posted: Thursday, September 12, 2019 12:52:42 PM
Rank: Advanced Member
Groups: Member

Joined: 7/6/2011
Posts: 30
Thanks for this. So does that mean I can't use HtmlToPdf.ConvertUrl(url, doc) in an MVC project?
eo_support
Posted: Thursday, September 12, 2019 4:38:58 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 21,568
Of course you can. But that would not have anything to do with ASP.NET MVC and any of it's built-in logic.


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.