使用pdfsharp在pdf文档中的几个pdf页面 [英] Several pdf pages in pdf document using pdfsharp

查看:315
本文介绍了使用pdfsharp在pdf文档中的几个pdf页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在每次循环时添加一个包含其内容的页面。但它只是添加了最后一页,其数据删除了所有以前的数据和页面。结果只有1页。



我想根据循环创建pdf页面



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

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();
                    }
}





提前致谢



我尝试了什么:



我使用了pdfsharper ..循环列表中的项目

i write在图像上然后将其转换为pdf内容。



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.

推荐答案

因为您正在将文档保存在添加页面的循环中!移动代码将其保存在创建页面并添加到文档的foreach循环之外。
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.


这篇关于使用pdfsharp在pdf文档中的几个pdf页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆