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
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.
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
add a comment |
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.
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
how are you rendering currently. show us your pdf creation code.
– Gagan Deep
Mar 8 at 5:27
add a comment |
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.
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
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.
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
asp.net asp.net-mvc razor-pages
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 8 at 20:36
Eli PulsiferEli Pulsifer
13419
13419
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
how are you rendering currently. show us your pdf creation code.
– Gagan Deep
Mar 8 at 5:27