Search code examples
iphoneobjective-cipadquartz-2d

how to render svg file in iphone and ipad


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);
}

}

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


Solution

  • As per the comments to the question: