How to render area of ASP .Net Core razor page (for pdf)How do I import a namespace in Razor View Page?jsreport .net client API returns empty PDFRendering an aspx page in razor view (cshtml)jsReport - Embed HTML in MVC razor viewASP.NET Core 2.0 Razor vs Angular/React/etcRazor-Page: render a complete page (chstml+chstml.cs)Razor Pages - Issue with Partial View and Getting Data from Model.net core routing to a razor pages area based on current domain name?.net core 2.1 reusing _Layout throughout various projectsASP.NET Core Razor Page anchor tag not working inside an Area

Is this part of the description of the Archfey warlock's Misty Escape feature redundant?

How much theory knowledge is actually used while playing?

Which Article Helped Get Rid of Technobabble in RPGs?

What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?

Pre-mixing cryogenic fuels and using only one fuel tank

Stack Interview Code methods made from class Node and Smart Pointers

15% tax on $7.5k earnings. Is that right?

Will number of steps recorded on FitBit/any fitness tracker add up distance in PokemonGo?

Multiplicative persistence

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

Why do Radio Buttons not fill the entire outer circle?

Why does Carol not get rid of the Kree symbol on her suit when she changes its colours?

How to draw a matrix with arrows in limited space

How to explain what's wrong with this application of the chain rule?

Why is the Sun approximated as a black body at ~ 5800 K?

Is there a RAID 0 Equivalent for RAM?

What is Cash Advance APR?

Can I say "fingers" when referring to toes?

Shouldn’t conservatives embrace universal basic income?

Delete multiple columns using awk or sed

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

Did the UK lift the requirement for registering SIM cards?

What's the name of the logical fallacy where a debater extends a statement far beyond the original statement to make it true?

How to preserve electronics (computers, iPads and phones) for hundreds of years



How to render area of ASP .Net Core razor page (for pdf)


How do I import a namespace in Razor View Page?jsreport .net client API returns empty PDFRendering an aspx page in razor view (cshtml)jsReport - Embed HTML in MVC razor viewASP.NET Core 2.0 Razor vs Angular/React/etcRazor-Page: render a complete page (chstml+chstml.cs)Razor Pages - Issue with Partial View and Getting Data from Model.net core routing to a razor pages area based on current domain name?.net core 2.1 reusing _Layout throughout various projectsASP.NET Core Razor Page anchor tag not working inside an Area













0















I am writing an ASP.Net Core Web App with Razor pages and need to render part of a page to a PDF. I'm pretty sure the actual PDF creation should be simple using one of the pdf libraries available like jsreport. I found several samples for rendering a page to a string which is great except I only want the report area.



What I'm struggling with is how to render just a portion of my page for the PDF. This image shows basically how my page is structured. The header, nav and footer come from the _Layout for my app. The range partial is shared by all the report pages and the report content is the actual page.



enter image description here



Is there a way to render just a section of a page?



If the content area was also a partial could that be rendered separately?



I have almost no experience with UI development so please pardon my naivety :)










share|improve this question






















  • how are you rendering currently. show us your pdf creation code.

    – Gagan Deep
    Mar 8 at 5:27















0















I am writing an ASP.Net Core Web App with Razor pages and need to render part of a page to a PDF. I'm pretty sure the actual PDF creation should be simple using one of the pdf libraries available like jsreport. I found several samples for rendering a page to a string which is great except I only want the report area.



What I'm struggling with is how to render just a portion of my page for the PDF. This image shows basically how my page is structured. The header, nav and footer come from the _Layout for my app. The range partial is shared by all the report pages and the report content is the actual page.



enter image description here



Is there a way to render just a section of a page?



If the content area was also a partial could that be rendered separately?



I have almost no experience with UI development so please pardon my naivety :)










share|improve this question






















  • how are you rendering currently. show us your pdf creation code.

    – Gagan Deep
    Mar 8 at 5:27













0












0








0








I am writing an ASP.Net Core Web App with Razor pages and need to render part of a page to a PDF. I'm pretty sure the actual PDF creation should be simple using one of the pdf libraries available like jsreport. I found several samples for rendering a page to a string which is great except I only want the report area.



What I'm struggling with is how to render just a portion of my page for the PDF. This image shows basically how my page is structured. The header, nav and footer come from the _Layout for my app. The range partial is shared by all the report pages and the report content is the actual page.



enter image description here



Is there a way to render just a section of a page?



If the content area was also a partial could that be rendered separately?



I have almost no experience with UI development so please pardon my naivety :)










share|improve this question














I am writing an ASP.Net Core Web App with Razor pages and need to render part of a page to a PDF. I'm pretty sure the actual PDF creation should be simple using one of the pdf libraries available like jsreport. I found several samples for rendering a page to a string which is great except I only want the report area.



What I'm struggling with is how to render just a portion of my page for the PDF. This image shows basically how my page is structured. The header, nav and footer come from the _Layout for my app. The range partial is shared by all the report pages and the report content is the actual page.



enter image description here



Is there a way to render just a section of a page?



If the content area was also a partial could that be rendered separately?



I have almost no experience with UI development so please pardon my naivety :)







asp.net asp.net-mvc razor-pages






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 23:43









Eli PulsiferEli Pulsifer

13419




13419












  • how are you rendering currently. show us your pdf creation code.

    – Gagan Deep
    Mar 8 at 5:27

















  • how are you rendering currently. show us your pdf creation code.

    – Gagan Deep
    Mar 8 at 5:27
















how are you rendering currently. show us your pdf creation code.

– Gagan Deep
Mar 8 at 5:27





how are you rendering currently. show us your pdf creation code.

– Gagan Deep
Mar 8 at 5:27












1 Answer
1






active

oldest

votes


















0














Here is my solution to render the report area of my page.
The simple answer is, post the html content of the page section I want to render back to the server, render it to a PDF and return that as a file for downloading.



To do this I first needed to get the html content for the section of the page containing the report. I did this by setting the id of the div for my reports to “report-content” and then using some script to capture that html.



$(function () 
$("#btnSubmit").click(function ()
$("input[name='ReportContent']").val($("#report-content").html());
);
);


The form to submit the request has a hidden “ReportContent” element where the html is stored.



@using (Html.BeginForm("Export", "Home", FormMethod.Post))

<input type="hidden" name="ReportContent" />
<input type="submit" id="btnSubmit" value="Download PDF" />



On the server side I created a method using JsReport API to render the PDF from the html.



protected async Task<IActionResult> RenderPDFAsync(string content)

var rs = new LocalReporting().UseBinary(JsReportBinary.GetBinary()).AsUtility().Create();

var report = await rs.RenderAsync(new RenderRequest()

Template = new Template()

Recipe = Recipe.ChromePdf,
Engine = Engine.None,
Content = content

);

return new FileStreamResult(report.Content, new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/pdf"));



Finally, I added the handler for the post that renders the PDF and returns the file result to each report page.



public async Task<IActionResult> OnPostAsync()

return await RenderPDFAsync(Request.Form["ReportContent"].ToString());



My code has a bit more validation than shown here and I have a common PageModel derived base class for all of my report pages so the only thing required for new reports is adding the post hander and setting the id on the section to be included in the PDF. I also intend to move the rendering to a service so it can be shared rather than recreated every time a report is created.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054596%2fhow-to-render-area-of-asp-net-core-razor-page-for-pdf%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Here is my solution to render the report area of my page.
    The simple answer is, post the html content of the page section I want to render back to the server, render it to a PDF and return that as a file for downloading.



    To do this I first needed to get the html content for the section of the page containing the report. I did this by setting the id of the div for my reports to “report-content” and then using some script to capture that html.



    $(function () 
    $("#btnSubmit").click(function ()
    $("input[name='ReportContent']").val($("#report-content").html());
    );
    );


    The form to submit the request has a hidden “ReportContent” element where the html is stored.



    @using (Html.BeginForm("Export", "Home", FormMethod.Post))

    <input type="hidden" name="ReportContent" />
    <input type="submit" id="btnSubmit" value="Download PDF" />



    On the server side I created a method using JsReport API to render the PDF from the html.



    protected async Task<IActionResult> RenderPDFAsync(string content)

    var rs = new LocalReporting().UseBinary(JsReportBinary.GetBinary()).AsUtility().Create();

    var report = await rs.RenderAsync(new RenderRequest()

    Template = new Template()

    Recipe = Recipe.ChromePdf,
    Engine = Engine.None,
    Content = content

    );

    return new FileStreamResult(report.Content, new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/pdf"));



    Finally, I added the handler for the post that renders the PDF and returns the file result to each report page.



    public async Task<IActionResult> OnPostAsync()

    return await RenderPDFAsync(Request.Form["ReportContent"].ToString());



    My code has a bit more validation than shown here and I have a common PageModel derived base class for all of my report pages so the only thing required for new reports is adding the post hander and setting the id on the section to be included in the PDF. I also intend to move the rendering to a service so it can be shared rather than recreated every time a report is created.






    share|improve this answer



























      0














      Here is my solution to render the report area of my page.
      The simple answer is, post the html content of the page section I want to render back to the server, render it to a PDF and return that as a file for downloading.



      To do this I first needed to get the html content for the section of the page containing the report. I did this by setting the id of the div for my reports to “report-content” and then using some script to capture that html.



      $(function () 
      $("#btnSubmit").click(function ()
      $("input[name='ReportContent']").val($("#report-content").html());
      );
      );


      The form to submit the request has a hidden “ReportContent” element where the html is stored.



      @using (Html.BeginForm("Export", "Home", FormMethod.Post))

      <input type="hidden" name="ReportContent" />
      <input type="submit" id="btnSubmit" value="Download PDF" />



      On the server side I created a method using JsReport API to render the PDF from the html.



      protected async Task<IActionResult> RenderPDFAsync(string content)

      var rs = new LocalReporting().UseBinary(JsReportBinary.GetBinary()).AsUtility().Create();

      var report = await rs.RenderAsync(new RenderRequest()

      Template = new Template()

      Recipe = Recipe.ChromePdf,
      Engine = Engine.None,
      Content = content

      );

      return new FileStreamResult(report.Content, new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/pdf"));



      Finally, I added the handler for the post that renders the PDF and returns the file result to each report page.



      public async Task<IActionResult> OnPostAsync()

      return await RenderPDFAsync(Request.Form["ReportContent"].ToString());



      My code has a bit more validation than shown here and I have a common PageModel derived base class for all of my report pages so the only thing required for new reports is adding the post hander and setting the id on the section to be included in the PDF. I also intend to move the rendering to a service so it can be shared rather than recreated every time a report is created.






      share|improve this answer

























        0












        0








        0







        Here is my solution to render the report area of my page.
        The simple answer is, post the html content of the page section I want to render back to the server, render it to a PDF and return that as a file for downloading.



        To do this I first needed to get the html content for the section of the page containing the report. I did this by setting the id of the div for my reports to “report-content” and then using some script to capture that html.



        $(function () 
        $("#btnSubmit").click(function ()
        $("input[name='ReportContent']").val($("#report-content").html());
        );
        );


        The form to submit the request has a hidden “ReportContent” element where the html is stored.



        @using (Html.BeginForm("Export", "Home", FormMethod.Post))

        <input type="hidden" name="ReportContent" />
        <input type="submit" id="btnSubmit" value="Download PDF" />



        On the server side I created a method using JsReport API to render the PDF from the html.



        protected async Task<IActionResult> RenderPDFAsync(string content)

        var rs = new LocalReporting().UseBinary(JsReportBinary.GetBinary()).AsUtility().Create();

        var report = await rs.RenderAsync(new RenderRequest()

        Template = new Template()

        Recipe = Recipe.ChromePdf,
        Engine = Engine.None,
        Content = content

        );

        return new FileStreamResult(report.Content, new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/pdf"));



        Finally, I added the handler for the post that renders the PDF and returns the file result to each report page.



        public async Task<IActionResult> OnPostAsync()

        return await RenderPDFAsync(Request.Form["ReportContent"].ToString());



        My code has a bit more validation than shown here and I have a common PageModel derived base class for all of my report pages so the only thing required for new reports is adding the post hander and setting the id on the section to be included in the PDF. I also intend to move the rendering to a service so it can be shared rather than recreated every time a report is created.






        share|improve this answer













        Here is my solution to render the report area of my page.
        The simple answer is, post the html content of the page section I want to render back to the server, render it to a PDF and return that as a file for downloading.



        To do this I first needed to get the html content for the section of the page containing the report. I did this by setting the id of the div for my reports to “report-content” and then using some script to capture that html.



        $(function () 
        $("#btnSubmit").click(function ()
        $("input[name='ReportContent']").val($("#report-content").html());
        );
        );


        The form to submit the request has a hidden “ReportContent” element where the html is stored.



        @using (Html.BeginForm("Export", "Home", FormMethod.Post))

        <input type="hidden" name="ReportContent" />
        <input type="submit" id="btnSubmit" value="Download PDF" />



        On the server side I created a method using JsReport API to render the PDF from the html.



        protected async Task<IActionResult> RenderPDFAsync(string content)

        var rs = new LocalReporting().UseBinary(JsReportBinary.GetBinary()).AsUtility().Create();

        var report = await rs.RenderAsync(new RenderRequest()

        Template = new Template()

        Recipe = Recipe.ChromePdf,
        Engine = Engine.None,
        Content = content

        );

        return new FileStreamResult(report.Content, new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/pdf"));



        Finally, I added the handler for the post that renders the PDF and returns the file result to each report page.



        public async Task<IActionResult> OnPostAsync()

        return await RenderPDFAsync(Request.Form["ReportContent"].ToString());



        My code has a bit more validation than shown here and I have a common PageModel derived base class for all of my report pages so the only thing required for new reports is adding the post hander and setting the id on the section to be included in the PDF. I also intend to move the rendering to a service so it can be shared rather than recreated every time a report is created.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 20:36









        Eli PulsiferEli Pulsifer

        13419




        13419





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054596%2fhow-to-render-area-of-asp-net-core-razor-page-for-pdf%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived