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:
One potential issue is that your Illustrator file may be corrupted. If you're unable to open the file, and you've tried repairing it using the software's built-in options, your best bet may be to try reinstalling Illustrator. If that doesn't work, you may need to find a new copy of the software.
While Adobe Illustrator is a great vector graphics editor utilized by many artists, it saves files in a proprietary format. The AI file type that Adobe Illustrator uses to save projects generally requires Adobe Illustrator to open.
Go to Google Drive here. Select the "My Drive" option. Choose the "Upload File" option. Browse for the Ai file on your computer and open it.
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"];
}
**
- (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;
}
**
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With