PDF Render directly

6 posts, 0 answers
  1. Louis
    Louis avatar
    80 posts
    Member since:
    Jun 2011

    Posted 02 Jul Link to this post

    Hello.

     

    3 questions :

    1) I use ASP.NET MVC Core report (last version).  Everything works fine with the viewer.  Thanks a lot to TELERIK.

    I want generate directy a PDF version of the report.  Like user click on a link and the report is downloaded directly.

    Can I have some sample to doing this (C#)?

     

    2) And how I can use    @(Html.TelerikReporting().ReportViewer() rather javascript :

            $(document).ready(function () {

                $("#reportViewer1")
                    .telerik_ReportViewer({

     

     ...TelerikReporting() is always in red.  Nuget missing?  See attachement for the ones in have in my project.

     

    3) ReportingEngineConfiguration is misssing in ReportController.  See attachement.

     

     

     

  2. Louis
    Louis avatar
    80 posts
    Member since:
    Jun 2011

    Posted 03 Jul Link to this post

    Sorry see attachment for question #3.
  3. Louis
    Louis avatar
    80 posts
    Member since:
    Jun 2011

    Posted 04 Jul in reply to Louis Link to this post

    Ok i got the answer for the question #1.  If it's can help someone else too.

     

    public  FileStreamResult Imprimer(string id)
    {
        if (!String.IsNullOrEmpty(id))
        {
            if (Guid.TryParse(id, out Guid Id))
            {
                Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
     
                // set any deviceInfo settings if necessary
                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                 
                var uriReportSource = new Telerik.Reporting.UriReportSource();
     
                // Specifying an URL or a file path
                uriReportSource.Uri = @"C:\Users\Lo\Source\Repos\HazMat\HazMat\wwwroot\Reports\Report1.trdp";
                uriReportSource.Parameters.Add("NoMat", id);
              
                Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", uriReportSource, deviceInfo);                  
                 
                // Écrire le fichier en mémoire plutôt que sur le disque.
                MemoryStream ms = new MemoryStream();
                ms.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
                ms.Seek(0, SeekOrigin.Begin);//set position to beginning.  Semble nécessaire lors du return.
                ms.Flush();
                // Il faut ajouter l'extension car "application/pdf" n'indique rien
                return new FileStreamResult(ms, "application/pdf") { FileDownloadName = result.DocumentName + ".pdf" };
            }
        }
        return null;
    }

     

     

  4. Neli
    Admin
    Neli avatar
    121 posts

    Posted 05 Jul Link to this post

    Hi Louis,

    Let me start with the second question:
    The only viewer that may be used in a .NET Core application is the pure HTML5 Viewer. The MVC Viewer cannot be used in .NET Core. This means that the reportSource is a pure JavaScript object.

    About the third question:
    I suggest to take a look at our How to implement Telerik Reporting in ASP.NET Core 2.1 MVC KB article to compare your code with the sample. Note that it might depend where the ConfigurationService is implemented. For example, in our demo it is located in the Startup class. Then the method in the ReportsContrоller is 
    public ReportsController(Startup.ConfigurationService configSvc) .


    Regards,
    Neli
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Louis
    Louis avatar
    80 posts
    Member since:
    Jun 2011

    Posted 05 Jul in reply to Neli Link to this post

    Hello Neli,

     

    THank  you for the fast answer.  But I still this issue (question #3) : ReportingEngineConfiguration is misssing in ReportController.

    When I compare the definition of my project to the demo project telerik provide (AspNetCoreMvcDemo) I notice this :

    My project :

    #region Assembly Telerik.Reporting, Version=13.1.19.618, Culture=neutral, PublicKeyToken=a9d7983dfcc261be
    // C:\Users\Louis\.nuget\packages\telerik.reporting\13.1.19.618\lib\net40\Telerik.Reporting.dll
    #endregion

    your project :

    #region Assembly Telerik.Reporting, Version=13.0.19.222, Culture=neutral, PublicKeyToken=a9d7983dfcc261be
    // C:\Users\Louis\.nuget\packages\telerik.reporting\13.0.19.222\lib\netstandard2.0\Telerik.Reporting.dll
    #endregion

     

    So my main question :  what is the way to provide the connection string using report nuget package (that use net40)  (see atachement)?  It's seem not the same way as you show in your demo project.

    I try to use netstandard2.0 in my project but got this error :

    An error occurred while starting the application.
    TypeLoadException: Violation des règles de sécurité liées à l'héritage par le type 'Telerik.Reporting.Services.AspNetCore.ReportsControllerBase'. Les types dérivés doivent correspondre à l'accessibilité à la sécurité du type de base ou être moins accessibles.
    Unknown location
     
    ReflectionTypeLoadException: Impossible de charger un ou plusieurs des types requis. Extrayez la propriété LoaderExceptions pour plus d'informations.
    System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
     
    Loader Exceptions:
    Violation des règles de sécurité liées à l'héritage par le type 'Telerik.Reporting.Services.AspNetCore.ReportsControllerBase'. Les types dérivés doivent correspondre à l'accessibilité à la sécurité du type de base ou être moins accessibles.
    TypeLoadException: Violation des règles de sécurité liées à l'héritage par le type 'Telerik.Reporting.Services.AspNetCore.ReportsControllerBase'. Les types dérivés doivent correspondre à l'accessibilité à la sécurité du type de base ou être moins accessibles.

     

     

     

     

     

     

  6. Louis
    Louis avatar
    80 posts
    Member since:
    Jun 2011

    Posted 05 Jul in reply to Neli Link to this post

    Hello Neli,

    I got the solution after few hours on this case.  Thank you and have nice week-ned you and your team.

Back to Top