服务端用iTextSharp产生图片内容PDF分页问题

nices 2010-10-12 05:03:53
服务端代码如下,其中 context.Request.InputStream是从Silverlight传过来的,从一个StackPanel转换为EditableImage的Stream。现在产生的PDF没有分页,所有的内容都在同一页。
System.IO.Stream incomingStream = context.Request.InputStream; //Get the incoming stream
System.Drawing.Image img = System.Drawing.Image.FromStream(incomingStream); //Create and image from the stream

int pageHeight = img.Height + (_Margin * 2);
int pageWidth = img.Width + (_Margin * 2);

iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(img, System.Drawing.Imaging.ImageFormat.Png);
System.IO.MemoryStream pdfStream = new System.IO.MemoryStream();
//iTextSharp.text.Font pdfFont = iTextSharp.text.Font.
iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(new iTextSharp.text.Rectangle(pageWidth, pageHeight));

//iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4);
pdfDoc.NewPage();
iTextSharp.text.pdf.PdfWriter pdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, pdfStream);

//Insure this is set otherwise when the close method is called on the iTextSharp.text.Document the memory stream
//we are writting to will be closed
pdfWriter.CloseStream = false;

//Open PDF and add image to it
pdfDoc.Open();
pdfDoc.Add(pdfImage);

//Close the PDF document to commit the changes
pdfDoc.Close();

//Insure the stream is at the beginning
if (pdfStream.Position > 0) { pdfStream.Position = 0; };

int contentLength = (int)pdfStream.Length;
//Stream the exported pdf to the client this is needed since the file size could be large in size
Byte[] bytesRead = new Byte[contentLength];
pdfStream.Read(bytesRead, 0, contentLength);
...全文
639 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
foreveryimada 2012-03-02
  • 打赏
  • 举报
回复
是否已经解决这个问题??[Quote=引用楼主 nices 的回复:]
服务端代码如下,其中 context.Request.InputStream是从Silverlight传过来的,从一个StackPanel转换为EditableImage的Stream。现在产生的PDF没有分页,所有的内容都在同一页。
System.IO.Stream incomingStream = context.Request.InputStream; //Get the incomin……
[/Quote]
jv9 2010-10-13
  • 打赏
  • 举报
回复
没有用过iTextSharp控件,iTextSharp控件中是否有独立的分页控制可以有代码进行判断和分页呢?

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧