我写的代码来显示任何类型如PDF,SVG文件SVG文件,etc.But不幸的是我的代码工作,只有pdf.the代码是这样的如何呈现在iphone和ipad
-(void)drawRect : (CGRect)rect {
CGPDFPageRef myPage;
NSString * pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@ "pdfdoc" ofType:@ "pdf"];
NSURL * pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
// NSLog(@"%@",pdfUrl);
CGPDFContentStreamRef myContentStream;
document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);
// NSLog(@"%@",[document description]);
if (document) {
int numOfPages = CGPDFDocumentGetNumberOfPages(document);
// NSLog(@"%d",numOfPages);
CGPDFPageRef myPage = CGPDFDocumentGetPage(document, pgno);
myContentStream = CGPDFContentStreamCreateWithPage(myPage);
// CGPDFOperatorTableRef myTable;
// myScanner = CGPDFScannerCreate (myContentStream, myTable, NULL);
// CGPDFPageRef page = CGPDFDocumentGetPage(document, 1);
// page = CGPDFDocumentGetPage(document, 2);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
CGContextTranslateCTM(ctx, 0.0, [self bounds].size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextConcatCTM(ctx,
CGPDFPageGetDrawingTransform(myPage, kCGPDFCropBox, [self bounds], 0, true));
CGContextDrawPDFPage(ctx, myPage);
CGContextRestoreGState(ctx);
}
}
最初我以为,如果我改变“pathForResources:OfType”方法参数是svg它将工作,但它不工作,任何人都可以建议我的修改。 谢谢
SVG是一种完全不同于PDF的文件格式。你为什么期望CGPDFDocument能够处理它? – 2010-11-23 14:32:25
[iPhone应用程序中的SVG图像]的可能重复(http://stackoverflow.com/questions/1251029/svg-images-in-an-iphone-application) – 2010-11-23 14:38:45