The use of Spire PDF for. NET in ASP----is not so "good", some frustration!

Source: Internet
Author: User

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

    1. Microsoft Windows 7 with SP1 Ultimate Edition x86
    2. Microsoft Visialstudio with Update 4 Ultimate Edition
    3. Spire PDF for. NET Free Edition
    4. 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

    1. 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.
    2. 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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.