Convert Data from a Datatable to PDF

HI,

We have been using Aspose.PDF for .net since a year.

We have been using the Repsonse object to show the converted PDF to the user in a web application.

I have a requirement now where we have to convert the data which is fetched from the data base in a datatable to PDF document. Please let me know in case this can be done. Quick help will be highly appreciated

Thanks,

Sankalp

Hello Sankalp,

For information on working with database please visit http://www.aspose.com/documentation/file-format-components/aspose.pdf.kit-for-.net-and-java/interoperate-with-database-net.html

In fact the information over page is for filling form fields over pdf file, but it can give an idea on how to interoperate with Database.

Hi,

We have Aspose.PDF for .net not the Kit. I have the data present in the form of HTML format as well, is it possible to convert it into pdf using memory stream logic. Please suggest.

Quick Help will be highly appreciable

Thanks,
Sankalp Singhal

Hi,

Sorry for Nayyer's reply. Please refer to Integrate Table with Database. If you want to add HTML into PDF, please refer to HTML Tags in Text.

Thanks for the reply. It works while i save the pdf to harddisk using pdf.save(@"C:\test1.pdf"), however we want to write the data into memory stream and ultimately have to convert it into a byte array so that it can be written into response object.

i am using the below mentioned code

MemoryStream msPdf = new MemoryStream();

try

{

if (res != null && res.GeneratePDFMsgs != null && res.GeneratePDFMsgs.Length != 0)

{

DataTable dtDetail = BdrReportMsgToDataTable(res);

Pdf pdf = new Pdf();

//Create a section in the Pdf instance

Section sec = pdf.Sections.Add();

//Create a Table object

Aspose.Pdf.Table tab = new Aspose.Pdf.Table();

//Add the Table object in the paragraphs collection of the section

sec.Paragraphs.Add(tab);

//Set column widths of the table

tab.ColumnWidths = "60 60 60 60 60 60";

//Set default cell border of the table using BorderInfo object

tab.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.1F);

//Import data into the Table object from the DataTable created above

tab.ImportDataTable(dtDetail, true, 0, 1);

pdf.IsTruetypeFontMapCached = true;

pdf.TruetypeFontMapPath = ConfigurationManager.AppSettings["logPath"];

Trace.Listeners.Clear();

Trace.Flush();

Trace.Close();

pdf.Save(msPdf);

return msPdf.GetBuffer();

}

}

And we are using this memory stream msPDF

string timeStamp = DateTime.Now.ToString();

Response.Expires = -1;

Response.ContentType = "application/" + FileType;

Response.AddHeader("Content-Type", "application/" + FileType);

Response.AddHeader("Content-Disposition", "attachment;filename=" + prog + "_" + timeStamp.Replace("/", "").Replace(" ", "").Replace(":", "") + "." + FileType);

Response.BinaryWrite(arrExport);

Response.End();

Please let me know the solution.

thanks,

Sankalp

Hi,

Sorry for replying to you late.

In fact you can use the public void Save(string,SaveType,HttpResponse); to save the resuting PDF into web browser. It is also OK if you want to save the PDF into stream and write it to web browser by yourself.