.jpg.pdf转换 - iTextSharp.text.PageSize“在Windows Phone 8.1中抛出异

本文关键字:Phone Windows 转换 pdf iTextSharp text PageSize jpg | 更新日期: 2023-09-27 18:37:15

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

我收到这样的错误:

消息 ="'iTextSharp.text.PageSize' 的类型初始值设定项抛出 是个例外。InnerException = {System.IO.FileNotFoundException: 无法加载文件或程序集"系统绘图,版本=1.0.5000.0, Culture=中性,PublicKeyToken=b03f5f7f11d50a3a' 或其之一 依赖。系统找不到指定的文件。

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

.jpg.pdf转换 - iTextSharp.text.PageSize“在Windows Phone 8.1中抛出异

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

终于找到了方法。我在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);
}