Conversion of Data to a letter(PDF format)

Hi,

I am writing this application (in C#.NET off course) for my organization where I extract data from a SQL server database and then print out the data in pdf format. I am done with this part, the part that I need help is that upon extraction of the customer information from the database, my company wants to print out a letter with the customer information on it which can be later mailed to the customer. So in short, for every customer there in the database, a letter needs to be generated with the extracted information on it and this letter needs to be in pdf format. I was doing some research and somebody somewhere mentioned crystal reports. I have no idea how to use crystal reports in this particular instance or in any instance for that matter. The letter has to have a predetermined format, complete with the company logo and all that jazz. Can somebody help me with this



Answer this question

Conversion of Data to a letter(PDF format)

  • sherif attia

    There will be quite a bit of a learning curve using crystal reports. I would suggest using the open source pdf lib iTextSharp found on sourceforge.

    You create the template pdf in your editor of choice. Simply loop through your recordset loading the template and setting the variable fields and then flattening the pdf.

    It literally takes less than 10 lines of code to accomplish this. Let me know if you'd like an example.

    You can download the source of iTextSharp so you know exactly what is going on in the lib. This will probably make management feel better as well as the price; it's free!

    Let me know if you want to learn more and I'll post some code.

    -Nathan

  • qwv

    Hi,

    You can desin your report as a ASP.NET page and then use a html to pdf converter to get a pdf report. The HTML to PDF library for .NET from http://www.dotnet-reporting.com or the HTML to PDF converter from http://www.winnovative-software.com is what you need. It's pure .NET library, it doesn't use a printer driver. There is also a free html to pdf converter application built on top of this library. The conversion can be done with only a few lines of code:

    Code Snippet

    PdfConverter pdfConverter = new PdfConverter();
    pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
    pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait;
    pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
    pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true;
    pdfConverter.PdfDocumentOptions.ShowFooter = false;
    pdfConverter.PdfDocumentOptions.ShowHeader = false;
    pdfConverter.LicenseFilePath = Server.MapPath(@"~/Bin");
    byte[] downloadBytes = pdfConverter.GetPdfFromUrlBytes(MyURL);

    Regards,

    Florin


  • Robertis Tongbram

    First, when management say foolish things like "no third party vendors - write everything inhouse", it's a good time to ask for a raise.

    Second, point out to them that, techinically, Business Objects SA, makers of Crystal Reports, is a third party vendor.

    Third, if not third-party vendor, would they accept Open Source code There are several PDF producing library on SourceForge. (note, several are ports of the Java-base iText library, but the quality of the port varies widely among the different versions).



  • Rick Walders

    Hi,

    The HTML to PDF library for .NET from http://www.dotnet-reporting.com or the HTML to PDF converter from http://www.winnovative-software.com is what you need. It's pure .NET library, it doesn't use a printer driver. There is also a free html to pdf converter application built on top of this library. The conversion can be done with only a few lines of code:

    Code Snippet

    PdfConverter pdfConverter = new PdfConverter();
    pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
    pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait;
    pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
    pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true;
    pdfConverter.PdfDocumentOptions.ShowFooter = false;
    pdfConverter.PdfDocumentOptions.ShowHeader = false;
    pdfConverter.LicenseFilePath = Server.MapPath(@"~/Bin");
    byte[] downloadBytes = pdfConverter.GetPdfFromUrlBytes(MyURL);

    Regards,

    Razva


  • Michael Herman - Parallelspace

    Can somebody tell me if using crystal reports is a good idea for my particular problem or there is some other way to convert the data from my database into a pdf letter having a preconcieved format
  • Olle Gustafsson

    It would be best for you to use Crystal Reports. You will need to add references to the proper dll's [ CrystalDecisions.CrystalReports.Engine; CrystalDecisions.Shared; CrystalDecisions.Web ]. You will probably be interested in CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream.
    You will also want to look at ReportDocument.ExportOptions.

    Hope it helps.



  • claudio32

    My organization just told me that no third party vendors will be used for this project, so pretty much that leaves me back on square one.
  • gsylvest

    Hey Nathan,

    Thanks a lot for your response. Yeah, an example would be really great...

    Thanks a ton...


  • Rockford Lhotka

    Hello

    You can use any Third Party components for generating PDF files, here http://www.websupergoo.com/abcpdf-8.htm you can find one which I have personalu used, it is easy and I am not suer about licencing but I think trial version is avaliable.

    You have to just pass an Html page and it will generate PDF for you,



  • rodniko

    Thanks a lot...
  • RayClark096

    No Problem.

    two references
    using iTextSharp.text;
    using iTextSharp.text.pdf;

    //create pdf meta data
    Hashtable meta = new Hashtable();
    meta["Title"] = "YOUR TITLE HERE";
    meta["Author"] = "YOUR AUTHOR HERE";
    meta["Creator"] = "YOUR CREATOR HERE";

    //create pdf
    PdfStamper stamper = new PdfStamper(new PdfReader(@"c:\uniquefilename.pdf")),new FileStream(@"c:\uniquefilename.pdf"),FileAccess.Write);
    stamper.MoreInfo = meta;

    // set form fields
    AcroFields fields = stamper.AcroFields;
    fields.SetField("form_firstname", dr["firstname"].ToString());
    fields.SetField("form_lastname", dr["lastname"].ToString());

    // flatten form fields and close document
    stamper.FormFlattening = true;
    stamper.Reader.Close();
    stamper.Close();

    I'm assuming you know how to loop through a recordset so I left that our for brevity.

    Let me know if I can help with anything else.

    Nathan


  • doughboy

    hey man,

    i am exactly doing what you have posted.i have been trying hard to run my hand on the same.but in vain.Can you please send me the code if you have been successful in getting the right code regarding conversion into pdf format.

    my email id is rithwick123@gmail.com.

    thanks in advance

    rithwik


  • Conversion of Data to a letter(PDF format)