Spire PDF for. NET in ASP. NET, spireasp.net
Note: Before reading this article, take a look at the previous article.
Yesterday, I tested the application of Spire PDF in the WinForm program. It can be said that it is easy to use (ignore the efficiency problem and do not perform the test ). However, when the Internet is so developed, the application of WEB is king. Therefore, today I try ASP. NET MVC4 again. Prepare to see if there are any differences in use.
Development Environment
Program running logic
Generate a simulated data source
1 [ActionName ("Generate")] 2 public ActionResult GenerateDynamicDataSource () 3 {4 return View (DynamicDataSourceDispatcher. GetDataSource (); 5}DataSource
Export
1 jsondocument documentInstance = new jsondocument (); 2 documentInstance. LoadFromHTML ("http: // localhost: 1/mvc4/controller/action = Generate", false, false, true );Spire PDF
Initial exception
According to the Code of yesterday, the code is basically over now, with only the output stream written to HttpResponse waiting for download. The results are not the same.
Long-lost Yellow Pages! What is this?
The literal meaning of the exception is what Active plug-in or COM component is accessed in Spire PDF.
No way, this can help the omnipotent du Niang (why not Google? The reason you know ). After checking for a long time, I finally saw a solution in a CSDN blog. In the @ Page command, specify the value of the AspCompat attribute to true.
ExportHandler. aspx
Helpless. Try it first to see if the yellow pages can be wiped out.
Put the code CtrlX + V above into the Page_Load on this page, "F5", actually solved the above problem.
1 protected void Page_Load (object sender, EventArgs e) 2 {3 your document documentInstance = new your document (); 4 documentInstance. loadFromHTML (HttpUtility. urlDecode (this. request. queryString ["targetperformanceuri"]), false, false, true); 5 this. response. contentType = "application/pdf"; 6 this. response. addHeader ("Content-Disposition", "attachment; filename = Spire PDF for aspnetmask"); 7 documentInstance. saveToStream (this. response. outputStream, FileFormat. PDF); 8}ExportHandler. aspx. cs
Suggestions
Running Effect
Code download
Https://sprepdfsdk2.codeplex.com/
Finally, thank you for your invitation to Yesi and the work of your team. We look forward to doing better in the Spire series!