Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to add a page with its content each time I loop. but it just adds the last page with its data removing all previous data and pages. and the result is only 1 page.

I want to create pdf pages according to the loop

C#
foreach(item in list){
PdfPage page = new PdfPage();
                                Size pageSize = bmp.Size;
                                page.Width = 1700;
                                page.Height = 1800;
                            
                               
                                document.AddPage(page);

                                XGraphics gfx = XGraphics.FromPdfPage(page);
                                gfx.DrawImage(bmp, 0, 0);

 using (MemoryStream memoryStream = new MemoryStream())
                    {
                        //Save the Watermarked image to the MemoryStream.
                        document.Save(memoryStream, false);

                        memoryStream.Position = 0;

                        //Start file download.
                        Response.Clear();
                        Response.ContentType = "application/pdf";
                        Response.AddHeader("Content-Disposition", "inline; filename=" + filename);

                        //Write the MemoryStream to the Response.
                        Response.BinaryWrite(memoryStream.ToArray());
                        memoryStream.Close();
                        Response.Flush();
                        Response.Close();
                        HttpContext.Current.ApplicationInstance.CompleteRequest();
                    }
}


Thanks in advance

What I have tried:

I used a pdfsharper .. looped over items in list
i write on images then convert it to pdf content.
Posted
Updated 9-Mar-16 3:07am
Comments
Member 14376289 17-May-19 9:39am    
what is bmp here? im kinda in the same situation only missing that

1 solution

because you are saving the document WITHIN the loop where you add pages! Move the code to save it outside the "foreach" loop where you create pages and add to document.
 
Share this answer
 
v2
Comments
Sandy Safwat 9-Mar-16 9:07am    
Thanks

you are right!

it solved the problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900