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

Posted

技术标签:

【中文标题】.jpg 到 .pdf 转换 - iTextSharp.text.PageSize\' 在 Windows Phone 8.1 中引发异常【英文标题】:.jpg to .pdf Conversion - iTextSharp.text.PageSize' threw an exception in Windows Phone 8.1.jpg 到 .pdf 转换 - iTextSharp.text.PageSize' 在 Windows Phone 8.1 中引发异常 【发布时间】:2015-01-13 08:41:36 【问题描述】:

我正在尝试使用 iTextSharp 库将 .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());

我收到这样的错误:

Message = "'iTextSharp.text.PageSize' 的类型初始化程序抛出 一个异常。” InnerException = System.IO.FileNotFoundException: 无法加载文件或程序集 'System.Drawing,版本 = 1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其之一 依赖关系。系统找不到指定的文件。

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

【问题讨论】:

这篇文章可能对你有所帮助 - ***.com/questions/21827669/… 【参考方案1】:

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

【讨论】:

没有System.Drawing的iTextSharp版本能用吗? 所以,没什么好用的!!该死的Windows手机!!谢谢@Paulo @ChrisHaas:不仅是 System.Drawing,所有文件管理都必须更改,还有许多其他部分。【参考方案2】:

我终于找到了方法。我在 Windows Phone 8.1 项目中添加了 ComponentOne 库。

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);

【讨论】:

它是如何工作的?它对我不起作用?是silverlight还是rt? @Amin 是的,它是 silverlight 伙计!!

以上是关于.jpg 到 .pdf 转换 - iTextSharp.text.PageSize' 在 Windows Phone 8.1 中引发异常的主要内容,如果未能解决你的问题,请参考以下文章

如何将pdf转换成jpg,转换达人教你一招搞定

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

怎么把pdf转化成Excel格式?

在 Linux 中将多个 jpg 合并为单个 pdf

怎么使用软件把jpg转换成pdf格式

JPG(文档)到 PDF(Linux 控制台)[关闭]