【问题标题】:How to display the PictureBox image into PDF file with the help of PDFsharp in c#?如何在 c# 中借助 PDFsharp 将 PictureBox 图像显示为 PDF 文件?
【发布时间】:2015-05-22 09:10:55
【问题描述】:

我正在用 c# 开发一个 Windows 应用程序。在我的应用程序中,我在 PDFsharp 的帮助下开发了 PDF 文件。我必须在 PictureBox 的 PDF 文件中显示图像。

【问题讨论】:

    标签: c# .net pdfsharp


    【解决方案1】:

    使用PDFsharp的GDI+时,只需调用XImage.FromGdiPlusImage

    XImage img = XImage.FromGdiPlusImage(pb.Image);
    

    pb 是图片框。

    此答案适用于 PDFsharp。

    可以在此处找到使用 PDFsharp 将图像添加到 PDF 文件的示例代码(演示 XImage 类的使用):
    http://pdfsharp.net/wiki/Graphics-sample.ashx#Images_35

    【讨论】:

      【解决方案2】:

      将图像临时保存到本地磁盘并添加到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 后最终删除图像

      【讨论】:

      • 问题标记为 PDFsharp,答案显示 MigraDoc 代码。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多