2012-01-16 198 views
4

我有一个需要将图像导出为PDF的项目。图像和文字都需要导出到pdf。有没有办法通过使用silverPDF.dll和PdfReader来做到这一点?将图像导出为PDF

代码在这里。

private void btnOutlook_Click(object sender, System.Windows.RoutedEventArgs e) 
    { 
     XBrush xbrush; 
     SaveFileDialog savePDF = new SaveFileDialog(); 
     savePDF.Filter = "PDF file format | *.pdf"; 
     if (savePDF.ShowDialog() == true) 
     { 
      PdfDocument document = new PdfDocument(); 
      PdfPage page = document.AddPage(); 
      XGraphics gfx = XGraphics.FromPdfPage(page); 
      XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); 

      XFont font = new XFont("Huxtable", 20, XFontStyle.Bold, options); 

      for (int x = 0; x < 10; x++) 
      { 
       if (x % 2 == 0) 
       { 
        xbrush = XBrushes.Red; 
       } 
       else 
        xbrush = XBrushes.Black; 
       gfx.DrawString(string.Format("{0}", stringArray[x]), font, xbrush, new XRect(0, (x * 20), page.Width, page.Height), XStringFormats.TopLeft); 
      } 

      document.Save(savePDF.OpenFile()); 
     } 

    } 

在这段代码中,我可以插入一个插入到pdf中的图片吗?有什么办法吗?感谢所有回复。

+0

我不知道SilverPDF什么,但有在线使用其他实用程序类的几个教程。 [Here's](http://forums.asp.net/t/1348035.aspx/1)之一。 – 2012-01-16 05:25:59

回答

1

是否需要成为SilverPDF?作为Iv'e做我以前使用iTextSharp的库雇主之前类似的东西(否则我会一直粘贴示例代码)

iTextSharp-Working-with-images

Download Link

+0

我无法使用它们,它们不是针对Silverlight运行时构建的。对我来说是巨大的问题。 – Nathan 2012-01-18 07:10:16

+1

我现在在使用它们。我刚刚在.Web应用程序中创建了该项目,然后将其以字节传递给Silverlight应用程序进行保存。谢谢您的帮助! – Nathan 2012-03-22 08:37:59