Loading Adobe Illustrator(.ai) file
Asked Answered
T

2

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

Thermoelectric answered 23/5, 2013 at 12:16 Comment(8)
Is it possible or not is also a closing question then what's the use of SO ?Thermoelectric
Loading an ai-file...? Doubt it! However take a look at this question for loading vector graphics.Slouch
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?Trypsin
Bit off-topic, but why do you want a .ai file?Peggie
If client asks you what you will do ? @OscarApelandThermoelectric
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 pdfPeggie
I had already suggested that. @OscarApelandThermoelectric
@VenkatManoharPerepa Well, you should have a nice talk with your clients about file compatibility on iosPeggie
T
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

**

Thermoelectric answered 23/5, 2013 at 13:18 Comment(1)
Cool. Seems a bit fragile though. What would happen if the .ai file contained something that is not supported by .pdf?Mclemore
D
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.

Diplomatics answered 23/5, 2013 at 13:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.