【发布时间】:2015-05-22 09:10:55
【问题描述】:
我正在用 c# 开发一个 Windows 应用程序。在我的应用程序中,我在 PDFsharp 的帮助下开发了 PDF 文件。我必须在 PictureBox 的 PDF 文件中显示图像。
【问题讨论】:
我正在用 c# 开发一个 Windows 应用程序。在我的应用程序中,我在 PDFsharp 的帮助下开发了 PDF 文件。我必须在 PictureBox 的 PDF 文件中显示图像。
【问题讨论】:
使用PDFsharp的GDI+时,只需调用XImage.FromGdiPlusImage:
XImage img = XImage.FromGdiPlusImage(pb.Image);
pb 是图片框。
此答案适用于 PDFsharp。
可以在此处找到使用 PDFsharp 将图像添加到 PDF 文件的示例代码(演示 XImage 类的使用):
http://pdfsharp.net/wiki/Graphics-sample.ashx#Images_35
【讨论】:
将图像临时保存到本地磁盘并添加到pdf文档对象(创建pdf文档后,您可以删除图像。)
示例代码:
Bitmap bmpImage = null;
string strPdfDocSavePath = @"D:\Images\";
bmpImage = PctrBx.Image;
string strImageName = System.DateTime.Now.ToString("yyyyMMddHHmmssfff");
bmpImage.Save(strPdfDocSavePath + @"\" + strImageName + ".bmp");
MigraDoc.DocumentObjectModel.Shapes.Image img = row.Cells[0].AddImage(strPdfDocSavePath + @"\" + strImageName + ".bmp"); // Here i am using table for displaying image , add column and row to table, add image to desired cell
row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
img.LockAspectRatio = true;
img.WrapFormat.Style =MigraDoc.DocumentObjectModel.Shapes.WrapStyle.Through;
img.Width = "7cm";
创建 pdf 后最终删除图像
【讨论】: