앱 번들의 일부로 전화에 로컬로 저장된 PDF를 볼 수있는 간단한 앱을 작성해야합니다.ipad - HelloWorld PDF를 보는 방법
UIBuilder에서 PDF를 표시하는 데 사용할 수있는 컨트롤이 있습니까?
앱 번들의 일부로 전화에 로컬로 저장된 PDF를 볼 수있는 간단한 앱을 작성해야합니다.ipad - HelloWorld PDF를 보는 방법
UIBuilder에서 PDF를 표시하는 데 사용할 수있는 컨트롤이 있습니까?
PDF 원본을 Base64 문자열로 사용하는 UIImage로 PDF를 보려면이 간단한 클래스를 사용하십시오. (모노 터치)
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;
}
}
}
UIWebView
은 다른 파일 형식뿐만 아니라 PDF도로드합니다. Using UIWebView to display select document types을 참조하십시오.