Generate pdf of the inserted row values in asp .net webforms c#

There is a simple asp.net webform which inserts data into three tables which are related to a common ID.

Table A : ID(P.K), Name.
Table B : B_Id(P.K), ID(F.K references ID of Table A), Address.
Table C : C_Id(P.K), ID(F.K references ID of Table A), Contact.
  • On Insert button click event after the insert operation I want to
    generate a pdf report which would consist of all the fields which we inserted into the tables lastly.
  • I can get the ID by using SCOPE_IDENTITY().

What can I use for generating pdf report in such scenario?

  • Note: The report must be viewed and also must be downloadable.

Code sample is appreciated.
Thank you in advance for the answer!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

On Saving the records to the database I fetched them and performed the pdf generation as well as sent it via email attachment.

Link: https://www.aspsnippets.com/Articles/Generate-Create-PDF-and-send-as-email-attachment-in-ASPNet.aspx

This solved my problem.

Method 2

you can use:

https://help.syncfusion.com/file-formats/pdf/create-pdf-file-in-asp-net-web-forms

The best workaround you can have is to make a zip file then do Response.Write(zipFile)

But if you still insist on having them separately(multiple downloads) better you save each file on the server first by:

using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
  Page.RenderControl(hw);
  StringReader sr = new StringReader(sw.ToString());
  Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
  PdfWriter.GetInstance(pdfDoc, new FileStream(Server.MapPath("~") + pdfName + ".pdf");
}

then use this trick https://stackoverflow.com/a/30682695/336511 to support multiple download. note that this will work on modern browsers.

var links = [
  'https://s3.amazonaws.com/Minecraft.Download/launcher/Minecraft.exe',
  'https://s3.amazonaws.com/Minecraft.Download/launcher/Minecraft.dmg',
  'https://s3.amazonaws.com/Minecraft.Download/launcher/Minecraft.jar'
];

function downloadAll(urls) {
  var link = document.createElement('a');

  link.setAttribute('download', null);
  link.style.display = 'none';

  document.body.appendChild(link);

  for (var i = 0; i < urls.length; i++) {
    link.setAttribute('href', urls[i]);
    link.click();
  }

  document.body.removeChild(link);
}
<button onclick="downloadAll(window.links)">Test me!</button>

Method 3

For Creating pdf. you can also use reporting services rdlc reports. it’s part of visual studio. and it supports RTL for Arabic and Persian languages.
you can render reports in background.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x