如何在iphone和ipad中渲染svg文件 [英] how to render svg file in iphone and ipad

查看:857
本文介绍了如何在iphone和ipad中渲染svg文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写代码来显示任何类型的文件,如pdf,svg等。但不幸的是我的代码只使用pdf.the代码是这样的

i wrote code to display any type of file like pdf,svg,etc.But unfortunately my code is working with only pdf.the code is like this

-(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它将起作用但它不起作用,任何人都可以建议我修改。
谢谢

initially i thought that if i change "pathForResources:ofType"method argument is svg it will works but it is not working, can any one suggest me modifications. thank you

推荐答案

根据问题的评论:

SVG不是PDF

这篇关于如何在iphone和ipad中渲染svg文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆