ritchiecarroll / Report.NET

Class library used to generate precise PDF documents
http://report.sourceforge.net/
GNU Lesser General Public License v2.1
81 stars 31 forks source link

How to return web response in MVC #6

Open surya5353 opened 6 years ago

surya5353 commented 6 years ago

Dear all,

Unable to return web response in MVC5. Here is my code.

`public ActionResult DownloadPdfDetailedAnalysis() {

        Report report = new Report(new PdfFormatter());
        FontDef fd = new FontDef(report, "Helvetica");
        FontProp fp = new FontPropMM(fd, 25);
        Page page = new Page(report);
        page.AddCenteredMM(80, new RepString(fp, "Hello World!"));
        return RT.ViewPDF(report, "HelloWorld.pdf")

}`

i want to return as pdf and open in new tab

DagerD commented 3 years ago

Hello, @surya5353 !

I Found out a working example for your question. First, I had to wrote my own "Creator" method image

And my controller looks like following:

    public ActionResult First()
    {
        var test = PDFWorker.CreatePDF();
        test.Save("F:/RiderProjects/rzn/ConfDataRZN/dxf/test.pdf");
        Response.Clear();
        Response.ContentType = "application/pdf";

        if (test.page_Cur == null) {
            test.CreatePDF();
        }

        test.formatter.Create(test, Response.OutputStream);
        Response.End();

        return null;
    }