开发者

how can add result of a Linq query result to PdfWriter.GetInstance(doc, new FileStream((Request.PhysicalApplicationPath"),FileMode.Create));

开发者 https://www.devze.com 2023-03-14 18:21 出处:网络
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 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消