My app downloads a PDF file from a web server and stores it locally on the iOS device. I then display it to the user using a UIDocumentInteractionController which is declared as a property named "controller" in the .h file.
NSURL *urlToFileToPreview = [NSURL fileURLWithPath:pathToFile];
self.controller.URL = urlToFileToPreview;
[self.controller presentPreviewAnimated:YES]
This works perfectly, but the UIDocumentInteractionController preview provides the ability to highlight text and add comment boxes, and I can't find an example of how to save those annotations so that when the file is opened again they are persistent.
Since I already have the URL of where the file is stored in the device's Documents directory, it would be a simple matter to overwrite it, but I have no idea how to extract the "changed/highlighted" file once the user presses the done button.
Since I can't find a way to save the changed file I simply want to disable highlighting so that the user doesn't have the expectation that the changes they have made will be persistent.
Related
My problem is that we have made an block that opens a page witha a mform on it. And we use the editor element to start the tinyMCE editor, on the page. But when we save the output, the images oploaded to the text field is only viewable to the admin (the person who uploaded it) and in the mdl_files it sets it to be a draft file. I have been through the documentation, and i might have lost the context on the new page, but im not sure.
In Moodle, files uploaded to a form (either to a filemanager element or a text editor) are stored in a temporary 'draft' area while the form is being edited.
This is so that the actual files are not changed until the form is submitted (e.g. if an admin changed the image embedded in some text, deleting the original, you do not want anyone viewing the page during the editing to see a broken image link).
When working with files embedded in a text editor in Moodle, you need to make sure you copy all existing files into the 'draft' area before you show the form, then copy the 'draft' images into the real area, after the form is submitted.
See https://docs.moodle.org/dev/Using_the_File_API_in_Moodle_forms#editor for details about how to do this.
Please also note that your plugin will also need a PLUGINTYPE_PLUGINNAME_pluginfile() function in its lib.php, in order to authenticate any file requests from the user's browser and return the file contents. See any of the core activities for examples of this (e.g. mod/data/lib.php - function data_pluginfile()).
I have an app opening URLs that may be PDFs.
I can detect a PDF is opened in the UIWebView control, and if so, I propose to save it locally, in the iPad.
To date, the only solution I found (as described in this topic : Save PDF which is displayed by UIWebView locally, is to RELOAD the remote PDF file in a new NSData object, then save it to disk.
Is it possible to use the UIWebView's NSData property, and write it directly on the disk, to avoid reloading a potentially large PDF file that is already loaded and displayed ? Thanks to all.
I think you can't access the data that the UIWebView caches. But, you can download first the PDF and later display in UIWebView from the local PDF.
EDIT
Reading your question I understand that:
First you display the PDF in you UIWebView.
You ask the user for download.
You download the PDF (Second request for the PDF).
I propose you:
Check that the URL is a PDF.
Ask user to download.
Download it.
Display the PDF in UIWebView loading the local file.
Did you examine the UIWebView content, using...
NSString HtmlCOntent = [NSMutableString stringWithString:[self.webView stringByEvaluatingJavaScriptFromString:#"document.body.outerHTML"]];
It could help you to understand how the WebView deals with the content of the PDF file
So I need to download PDFs that are password protected, unlock them, and then display them via the UIDocumentInteractionController. So far, I'm downloading the password protected PDFs and found out how to unlock a PDF using the CG framework (CGPDFDocumentRef) but I can't figure out how to get the unlocked document back as an NSData from CG. Plus I'm not sure how to pass UIDocumentInteractionController an NSData object. If anyone has done this before, please help.
The answer is no. UIDocumentInteractionController only works with NSURL objects and there is no way to pass UIDocumentInteractionController in-memory data. Since I didn't want to spend any more time on this, I decided to instead, each time a user taps the document, to decrypt the PDF, save it to disc and then pass UIDocumentInteractionController the path to the temp file (temp file must exist on disc while UIDocumentInteractionController is open). I'll probably have to role my own PDF viewer if this doesn't fly with the client's security requirements.
I am making a basic text editor from this tutorial here:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextArchitecture/Tasks/TextEditor.html
My text editor can save, write, and open documents in RTF and TXT format, but cannot save graphics along with any text. Formatted text is saved, and the graphic does display when the window is open, but does not get saved.
You're almost there, you just need to implement a bit more in your app's Info.plist.
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
NSData *data;
[self setString:[textView textStorage]];
NSMutableDictionary *dict =
[NSDictionary dictionaryWithObject:NSRTFTextDocumentType
forKey:NSDocumentTypeDocumentAttribute];
Notice that in the method which asks for the data to be saved to file, no matter what, it's set up to use NSRTFTextDocumentType rather than NSRTF*D*TextDocumentType. RTFD means RTF with attachments, which saves an .rtfd document which is actually a package/bundle (a folder that is presented to the user as if it were a single file). Saving as NSRTFTextDocumentType will effectively discard the stuff that can't fit into an RTF document, like the images.
After step 12 is the following:
At this stage of its development, your editor opens and saves documents only with an extension of ????. To enable your application to save and open documents with a recognized file type, you need to use Xcode to configure the document types settings in the application’s property list file in the Resources folder in Xcode. (The Xcode template names the file with your project name followed by -Info.plist.) You can edit this file in Xcode by selecting the file in the Groups & Files list and using the built-in editor. Click the disclosure triangles to edit the value of the first item under CFBundleTypeExtensions to the preferred extension for your document files.
For more information about property list files, see “Storing Document Types Information in the Application's Property List” in Document-Based Applications Overview. For complete details about application property lists, see Runtime Configuration Guidelines.
Basically, right now, you're being passed in a generic DocumentType in that data method shown above. Once you claim in your Info.plist that you can handle RTF and RTFD data (as 2 separate entries), you will be passed in a different value in that method, depending on what the user has chosen in the Format popup button in the NSSavePanel. You can check the value of the passed in type and then specify NSRTFTextDocumentType or NSRTFDTextDocumentType accordingly.
You can probably look at TextEdit's Info.plist to use as the basis of your Document types, though be sure to change the NSDocument subclass name to your own so the NSDocumentController knows what class to use.
maybe your images are not saved in the same directory?
for example if I create a rtf document with TextEdit it creates an folder called something.rtfd and contains the TXT.rtf and all the images.
I have a Cocoa document-based app that (currently at least) functions as a basic text editor. It saves .txt, .rtf, and .rtfd, and loads those plus .doc and .docx. If I open a .doc or .docx file and edit it, then try to close, it reminds me to save, but the save option doesn't do anything since the application is only a viewer for those types of files. How can I make that function as "Save As" for types that can only be viewed, like .doc and .docx?
Override the saveDocumentWithDelegate::: in your customised NSDocument to the following:
- (void)saveDocumentWithDelegate:(id)delegate didSaveSelector:(SEL)didSaveSelector contextInfo:(void *)contextInfo
{
if (delegate != nil)
{
// use delegate or contextInfo to decide what operation you need to use...
[self runModalSavePanelForSaveOperation:NSSaveAsOperation
delegate:delegate
didSaveSelector:didSaveSelector
contextInfo:contextInfo];
}
else
{
[super saveDocumentWithDelegate:delegate
didSaveSelector:didSaveSelector
contextInfo:contextInfo];
}
}
By default the delegate is either an NSWindow on window close or NSDocumentController if you quit the application and the controller enumerates the windows for reviewing changes.
Not completely clear if you actually want to write the updated file after editing, or prevent editing and thus prevent the warning that the document has been modified.
To not see the Save warning, first you would want to set your document type role to "Viewer", if it happens to be "Editor". This is in the Target settings.
Then you need to
1. ensure that the contents of the document isn't changed, and/or
2. tell the document not to bother showing itself as dirty
However, if you want to allow editing and saving the document, you would have to write those files back in the proper format. That's non-trivial, except for the fact that the source code for TextEdit is available and included with Xcode. But from a cursory glance, it appears that NSDocument already supports .doc and .docx.
You will find the Project folder for TextEdit in /Xcode/Examples.