1

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!

Jimesh
  • 479
  • 5
  • 17

3 Answers3

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.

Jimesh
  • 479
  • 5
  • 17
0

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>
Omk
  • 1
  • 2
  • 16
0

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.