i am designing a asp.net mvc project. i want to convert my document into pdf. i am using itextsharp-all-5.1.1 for this conversion.
i created object as
PdfWriter.GetInstance(doc, new FileStream((Request.PhysicalApplicationP开发者_运维问答ath + "\\1.pdf"), FileMode.Create));
now i want to add the result of following query in doc object, so how can i add the result of this queryin doc object.
i have this query:-
var vv= (from x in db.RawMaterial join y in db.ProductFormulation on x.ID equals y.RawMaterialID where y.ProductID == 1 select new { x.Description, y.Quantity });
please help me please...
So, if I understand you correctly you are creating a PDF file using itextsharp and you want to add to this pdf file the result of some query which is a collection of some item that contains a description and a quantity.
If this is the case I wonder why your question is tagged with asp.net-mvc as this has nothing to do with it. It's itextsharp problem. Here's a nice example illustrating how to create a PDF document containing a table.
So for your query you could adapt it like this:
var vv =
from x in db.RawMaterial
join y in db.ProductFormulation
on x.ID equals y.RawMaterialID
where y.ProductID == 1
select new { x.Description, y.Quantity };
var table = new PdfPTable(2);
table.AddCell("Description");
table.AddCell("Quantity");
foreach (var item in vv)
{
table.AddCell(item.Description);
table.AddCell(item.Quantity);
}
doc.Add(table);
精彩评论