Loading Adobe Illustrator(.ai) file

Is it possible to load .ai files and open them programmatically?

This is what I have tried:

- (IBAction)openDocument:(id)sender
{
    QLPreviewController *previewController = [[QLPreviewController alloc] init];
    [previewController setDataSource:self];
    [previewController setDelegate:self];
    [self presentModalViewController:previewController animated:YES];
}

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
    return 1;
}

- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    return [[NSBundle mainBundle] URLForResource:@"CNW EXPLODED1" withExtension:@"ai"];
}

But the output is like this:

在这里输入图像描述


There is one way to do that. That is changing the extension of that ai to pdf and load that and as follows,

- (IBAction)openDocument:(id)sender
{
    QLPreviewController *previewController = [[QLPreviewController alloc] init];
    [previewController setDataSource:self];
    [previewController setDelegate:self];
    [self presentModalViewController:previewController animated:YES];
}
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
    return 1;
}
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    return [[NSBundle mainBundle] URLForResource:@"CNW EXPLODED1" withExtension:@"pdf"];
}

OUTPUT:

在这里输入图像描述

This is working perfectly.. But i dont want to change the EXTENSION. Could anyone help me MORE please.

**

UPDATED ANSWER:

- (IBAction)openDocument:(id)sender
{
    UIButton *button = (UIButton *)sender;
    NSURL *URL = [[NSBundle mainBundle] URLForResource:@"CNW EXPLODED1" withExtension:@"ai"];

    if (URL) {
        // Initialize Document Interaction Controller
        self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];

        // Configure Document Interaction Controller
        [self.documentInteractionController setDelegate:self];

        // Present Open In Menu
        [self.documentInteractionController presentOpenInMenuFromRect:[button frame] inView:self.view animated:YES];
    }
}


- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
    return self;
}

This is showing with menu options but with option BUMP. It works only in device

**


It is possible to extract the vector details and re-use these as a path on a CAShapeLayer if you save the Illustrator file as an .eps file but it's not straightforward with complex shapes.

These links should help:

http://jeffmenter.wordpress.com/2011/04/17/method-for-interpreting-illustrator-art-assets-as-cocoa-cgpathref/

http://rdsquared.wordpress.com/2012/01/10/svg-to-coregraphics-conversion/

And definitely do a search for SVGKit on Github.

Hope that helps. Glory to the downvoters.

链接地址: http://www.djcxy.com/p/13708.html

上一篇: 类型检查器可以帮助我吗? 有类型的家庭,也许?

下一篇: 加载Adobe Illustrator(.ai)文件