I note: Before you look at this article, please look at the previous post.
Yesterday, I tested the application of Spire PDF in the WinForm program, which can be said to be easy to use (please ignore the efficiency issue and not test). However, the Internet is so developed today, the application of the web is the King Ah. So today I've been experiencing it in ASP. MVC4. Be prepared to see if there is any difference in use.
Development environment
- Microsoft Windows 7 with SP1 Ultimate Edition x86
- Microsoft Visialstudio with Update 4 Ultimate Edition
- Spire PDF for. NET Free Edition
- ASP. NET MVC 4
Program Run logic
Generating an analog data source
1 [ActionName ("Generate")]2 Public ActionResult Generatedynamicdatasource ()3{4 return View ( Dynamicdatasourcedispatcher.getdatasource ()); 5 }
DataSource
Performing an export
1 New pdfdocument (); 2 documentinstance.loadfromhtml ("http://localhost:1/mvc4/controller/action=Generate " false false true);
Spire PDF
Unusual first occurrence
According to yesterday's code, by this time the code is basically finished, leaving only the output stream written to HttpResponse, waiting for the download to be good. That's not the result.
Long-lost little yellow Pages! What the hell is this?
The literal meaning of the exception should be what active plug-ins or COM components are accessed in the Spire PDF.
No way, this can turn to the almighty Niang (why not Google?) The reason you know). Looked for a long time, finally in csdn a blog post saw a solution. is to specify the value of the ASPCompat property as true in the @page directive.
Exporthandler.aspx the helpless lift
Helpless, first try it, see if you can kill the Yellow pages.
The above code CTRLX+V to this page of the Page_Load, "F5" a bit, actually solved the above problem.
1 protected voidPage_Load (Objectsender, EventArgs e)2 {3Pdfdocument documentinstance =Newpdfdocument ();4Documentinstance.loadfromhtml (Httputility.urldecode ( This. request.querystring["Targetdatasourceuri"]),false,false,true);5 This. Response.ContentType ="application/pdf";6 This. Response.AddHeader ("content-disposition","attachment;filename=spire PDF for Aspnet.pdf");7Documentinstance.savetostream ( This. Response.outputstream, fileformat.pdf);8}
ExportHandler.aspx.cs
Suggestions
- Spire PDF for. NET also needs to be enhanced in terms of the compatibility of ASP. It may be that I have not learned more about this component, and there might be a better way to use it.
- The efficiency of execution can be a problem. At first, I tried to generate 10,000 pages of data, and when the PDF was generated, it ended up being reduced to 10 data.
Run effect
Code download
https://sprepdfsdk2.codeplex.com/
Finally, thank Yesi for the invitation, but also thank you for your team's work, look forward to Spire series to do better!
The use of Spire PDF for. NET in ASP----is not so "good", some frustration!