1

firstly I'm not asking for any code just some advice on how i would go about doing this and if its even possible like this.

So I'm making a website where one of the functions is an Educator can select questions from a question pool and then i would like to put those questions in a pre-formatted style(don't know how to explain that, but like a default layout) and save that as a PDF for them to download so they can print it wherever.

The data for the questions will be fetched from a SQl database, I don't have an issue with this, just don't know if maybe it has to be considered when trying to do this xD.

I'm not sure if it could make a page for it and then save that page as a PDF file or what, I'm honestly clueless on how to approach this.

Thanx in advance.

2
  • 1
    Various approaches, take a look to PDFsharp for a server-side generation or jsPDF for a client side generation. Commented Sep 14, 2015 at 12:05
  • You can simply make a crystal report formatted to the required format then what you need to save is the actual query of the selected question. Then when someone goes on the website and click download you open the report and run the saved query and save as PDF in stream and return to the user. This will trigger a download on the client side and everything will look like a normal download. Commented Sep 14, 2015 at 12:05

6 Answers 6

4

If have access to SQL Reporting Services (SSRS), which comes with most SQL Server editions starting with SQL Server 2000, you can simply use this tool to generate PDF reports from your SQL Server data.

Sign up to request clarification or add additional context in comments.

Comments

2

Get the iTextsharp lib from nuget and get the data. Make a PDF with the data from the SQL server. Here is some sample code:

FileStream fs = new FileStream(filename, FileMode.CreateNew);
Document doc = new Document(PageSize.A4);
PdfWriter pdfWriter = PdfWriter.GetInstance(doc, fs);
PdfPage page = new PdfPage();
pdfWriter.PageEvent = page;
doc.Open();
PdfContentByte cb = pdfWriter.DirectContent;
doc.Add(new Paragraph("the data from sql server:"));
pdfWriter.CloseStream = true;            
doc.Close();
fs.Close();

ps. it is just a snippet. It is not the minimal amount of code required for a PDF file from itextsharp. There is enough documentation about pdf creation in C# and data access with C# and sql server. Show some code, or give us more detail about the actual problem.

6 Comments

Thank you to answering, and to everyone else, Sorry for the late response but i have been extremely busy with college work, Just one thing I want to ask now is, How could i trigger a download function or something once the file is done, I'd like it to download the pdf to the clients pc.
Ive downloaded the ebook and having a look at it
Thank you, I am using this now :)
Depends, webforms or mvc? or no web?
I have it kind of working now with the download and all, Just simple playing around but what i would like to know is there a place i can go to see all the document commands or commands that i can use and see what styling i can do, cause i would like to make a front page that looks in a decent format so styling would be needed for that
|
1

iTextSharp makes it easy to create pdfs. It's available here or through NuGet http://sourceforge.net/projects/itextsharp/

Documentation and further info here: http://itextpdf.com/product/itext

Comments

1

Alternative to iTextSharp you could use Migradoc (& pdfsharp) - could be found there http://www.pdfsharp.net/MigraDocOverview.ashx

Its 100% opensource and not restricts you in commercial use of the library. (MIT License ) https://www.nuget.org/packages/PDFsharp-MigraDoc-GDI/
Worked like charm with our web-app. Renders pdf on the server.

1 Comment

Hi, Ive looked over the website and it seems that this is what i think im gana use, I will start experimenting tomorrow :).
1

You can also use Rotativa

you just need to add few lines

public ActionResult GeneratePDF()
{
  var model = new GeneratePDFModel();
  //get content
  return View(model);
}

Here is a tutorial
and nuget

Comments

0

One alternative that hasn't been mentioned yet is to create the layout of the PDF using a style sheet (xsl-fo). Essentially the steps would be:

1) Convert the SQL data to an xml file 2) Create the style sheet (xsl-fo) 3) Use Apache FOP to merge the xml and xsl-fo and generate a PDF file.

More information can be found here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.