0
A
回答
-1
要将PDF作为UIImage查看,PDF的来源是Base64字符串,请使用此简单类。 (MonoTouch)
using System;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using System.Drawing;
using MonoTouch.CoreGraphics;
using System.IO;
namespace Common
{
public class PDF
{
public static readonly string MyDocuments = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
public static string SavePDFReturnPath (string Base64PDFString, string FileName)
{
string path = Path.Combine (MyDocuments, "pdfs");
if (!Directory.Exists (path))
Directory.CreateDirectory (path);
FileName = FileName.ToLower();
if (!FileName.EndsWith ("pdf"))
FileName = FileName + ".pdf";
path = Path.Combine (path, FileName);
if (File.Exists (path))
File.Delete (path);
using (var f = System.IO.File.Create (path))
{
byte[] encodedDataAsBytes = System.Convert.FromBase64String (Base64PDFString);
f.Write (encodedDataAsBytes, 0, encodedDataAsBytes.Length);
}
return path;
}
public static UIImage GetImageFromPDFThatIsInBase64 (string Base64PDFString)
{
RectangleF PDFRectangle = new RectangleF (0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);
return GetImageFromPDFThatIsInBase64 (Base64PDFString, PDFRectangle);
}
public static UIImage GetImageFromPDFThatIsInBase64 (string Base64PDFString, RectangleF PDFRectangle)
{
UIImage img = null;
try
{
UIGraphics.BeginImageContext (new SizeF (PDFRectangle.Width, PDFRectangle.Height));
CGContext context = UIGraphics.GetCurrentContext();
context.SaveState();
CGPDFDocument pdfDoc = CGPDFDocument.FromFile (SavePDFReturnPath (Base64PDFString, "temp.pdf"));
CGPDFPage pdfPage = pdfDoc.GetPage (1);
img = TransformPDFToImage (pdfPage, PDFRectangle.Width);
pdfDoc.Dispose();
context.RestoreState();
UIGraphics.EndImageContext();
}
catch (Exception e)
{
Console.WriteLine ("GetImageFromBase64PDFImage: {0}", e.Message);
}
return img;
}
private static UIImage TransformPDFToImage (CGPDFPage page, Single width)
{
RectangleF pageRect = page.GetBoxRect (CGPDFBox.Media);
Single pdfScale = width/pageRect.Size.Width;
pageRect.Size = new SizeF (pageRect.Size.Width * pdfScale, pageRect.Size.Height * pdfScale);
//pageRect.Origin = CGPointZero;
UIGraphics.BeginImageContext (pageRect.Size);
CGContext context = UIGraphics.GetCurrentContext();
//White BG
context.SetRGBFillColor (1.0f, 1.0f, 1.0f, 1.0f);
context.FillRect (pageRect);
context.SaveState();
// Next 3 lines makes the rotations so that the page look in the right direction
context.TranslateCTM (0.0f, pageRect.Size.Height);
context.ScaleCTM (1.0f, -1.0f);
CGAffineTransform transform = page.GetDrawingTransform (CGPDFBox.Media, pageRect, 0, true);
context.ConcatCTM (transform);
context.DrawPDFPage (page);
context.RestoreState();
UIImage img = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return img;
}
}
}
0
UIWebView
将加载PDF以及其他几种文件格式。请参阅Using UIWebView to display select document types。
相关问题
- 1. iPad中的PDF查看器
- 2. Ipad DWG/DXF查看
- 3. 如何在pdf文件中打开pdf到pdf查看器
- 4. 如何在pdf查看器中实现pdf.js来查看pdf文件?
- 5. 单击触摸查看PDF
- 6. 如何用PHP制作PDF查看器
- 7. 如何通过WPF查看PDF文件?
- 8. 如何在使用mpdf时查看pdf?
- 9. iphone PDF查看CGPDFDocument
- 10. android webview pdf查看
- 11. Android PDF查看器
- 12. Android PDF查看器
- 13. iTextSharp MVC查看PDF
- 14. 如何阅读pdf文本并使用目标C查看它?
- 15. CSS iPad上查看布局
- 16. iPad模拟器查看
- 17. 如何在查看PDF之前加载PDF
- 18. 如何在石英中嵌入链接PDF查看
- 19. Monotouch:UIDocumentInteractionController,查看文档(pdf,word,excel等)如何?
- 20. 应用程序查看PDF文件
- 21. Java EE PDF查看器
- 22. 在PDF中查看图表
- 23. Windows Phone 8.1 PDF查看器
- 24. 错误android pdf查看库
- 25. 在线PDF查看器
- 26. 在IE6中查看PDF
- 27. PDF预览和查看
- 28. UnsatisfiedLinkError:parseFile与APV(PDF查看器)
- 29. PDF查看器AcroPDF错误
- 30. PDF查看器中的Qt