.jpg到.pdf转换 - iTextSharp.text.PageSize'在Windows Phone 8.1中引发了异常

时间:2015-01-13 08:41:37

标签: c# pdf windows-phone-8.1 itextsharp

我正在尝试使用iTextSharp Library将.jpg文件转换为PDF。

请参阅下面的代码:

 using (MemoryStream newStream = new MemoryStream())
 {
     Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate());                    
     PdfWriter writer = PdfWriter.GetInstance(doc, newStream);
     writer.CloseStream = false;

     byte[] all = newStream.ToArray();
 }

但是,我在这一行中遇到错误:

Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate());

我收到这样的错误:

  

消息="' iTextSharp.text.PageSize'的类型初始值设定项扔   一个例外。" InnerException = {System.IO.FileNotFoundException:   无法加载文件或程序集“System.Drawing,Version = 1.0.5000.0,   Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其中一个   依赖。系统找不到指定的文件。

如何处理这个,请建议我。 谢谢!

2 个答案:

答案 0 :(得分:1)

iTextsharp(尚未)支持Windows Phone。您遇到的问题之一是System.Drawaing在Windows手机中不存在,但在其他地方会失败。有一个Windows Phone支持的程序集列表here

答案 1 :(得分:0)

最后我找到了方法。我在Windows Phone 8.1项目中添加了ComponentOne Library。

using C1.Phone.Pdf;
using C1.Phone.PdfViewer;

C1PdfDocument pdf = new C1PdfDocument(PaperKind.PrcEnvelopeNumber3Rotated);
pdf.Landscape = true;

var rc = new System.Windows.Rect(20,30,300,200);
pdf.DrawImage(wbitmp, rc);

var fillingName = "Test.pdf";
var gettingFile = IsolatedStorageFile.GetUserStoreForApplication();

using (var loadingFinalStream = gettingFile.CreateFile(fillingName))
{
   pdf.Save(loadingFinalStream);
}