Search code examples
c#javascriptasp.net-mvc-3pdf-generationacrobat-sdk

Injecting JavaScript to PDF from MVC 3 controller


In my ASP.NET MVC3(Razor) application am struggling with the print utility. I want to auto print a PDF file which is converted from rdlc.

I converted the rdlc to pdf using the following code:

        LocalReport localReport = new LocalReport();

        localReport.ReportPath = @"Reports/OP/Rdlc/ClinicInvoiceReceipt.rdlc";

        iClinicInvoiceReceipt = new RmtOPInvoice.ClinicInvoiceReceipt();
        DataTable dt = iClinicInvoiceReceipt.SelectReceiptDtlForPrint(1);

        ReportDataSource reportDataSource = new ReportDataSource();
        reportDataSource.Value = dt;
        reportDataSource.Name = "DataSet1";
        localReport.DataSources.Add(reportDataSource);

        string reportType = "PDF";
        string mimeType;
        string encoding;
        string fileNameExtension;

        string deviceInfo =
         @"<DeviceInfo>
            <OutputFormat>PDF</OutputFormat>
            <PageWidth>5.83in</PageWidth>
            <PageHeight>8.27in</PageHeight>
            <MarginTop>0in</MarginTop>
            <MarginLeft>0.in</MarginLeft>
            <MarginRight>0in</MarginRight>
            <MarginBottom>in</MarginBottom>
        </DeviceInfo>";
        Warning[] warnings;

        string[] streams;

        byte[] renderedBytes;

        renderedBytes = localReport.Render(
           reportType,
           deviceInfo,
           out mimeType,
           out encoding,
           out fileNameExtension,
           out streams,
           out warnings);

        return File(renderedBytes, "application/pdf");

I want to display this on view at the same time want to open the print dialog of pdf viewer automaticaly

I just here about putting javscript to pdf here. But am confused of achieving this in my above code. If anybody gone through this please share . That will be really helpful for me.

I just found out the same scenario is done in PHP. Here .


Solution

  • i achieved this using iTextSharp

    Here is the sample project i did.