8

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:

enter image description here

NSGod
  • 22,699
  • 3
  • 58
  • 66
Manu
  • 4,730
  • 2
  • 20
  • 45
  • Is it possible or not is also a closing question then what's the use of SO ? – Manu May 23 '13 at 12:24
  • 1
    Loading an ai-file...? Doubt it! However take a look at [this question](http://stackoverflow.com/questions/1957282/how-can-i-load-vector-image-directly-with-iphone-sdk) for loading vector graphics. – Groot May 23 '13 at 12:55
  • 2
    Adobe Illustrator (.ai) files are just PDF files. So yes, this is very much possible. Why do people vote to close if they have no clue about the topic? – NSGod May 23 '13 at 14:11
  • Bit off-topic, but why do you want a .ai file? – Oscar Apeland May 23 '13 at 14:12
  • 1
    If client asks you what you will do ? @OscarApeland – Manu May 23 '13 at 14:14
  • I would say thats its most likely unnecessary and would suggest pdf for better performance. If they have the technical abilities to use AI I would assume theyre able to export as pdf – Oscar Apeland May 23 '13 at 14:42
  • I had already suggested that. @OscarApeland – Manu May 24 '13 at 04:48
  • @VenkatManoharPerepa Well, you should have a nice talk with your clients about file compatibility on ios – Oscar Apeland May 24 '13 at 08:20

2 Answers2

4

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:

enter image description here

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

**

Manu
  • 4,730
  • 2
  • 20
  • 45
0

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.

Steve
  • 988
  • 1
  • 12
  • 25