Download and View PDFs in iPhone - iphone

I'm planning to develop an iPhone app in which will do the following:
download PDF file from my
website.
open PDF file which is password
protected
access this PDF file offline from
the iPhone
I really want to know how to achieve the above, what classes to use and what tips should I consider?
Thanks

When downloading large files on mobile devices it's a good idea to save the data as it comes in. I suggest you use a good network library that performs all this work for you: ASIHTTPRequest and AFNetworking are both very good and actively maintained.
Since your pdf files are password protected you'll need to write a custom pdf viewer. For non-password protected pdf files you could have used the QuickLook framework to display pdf files.
You can unlock pdf files by using the CGPDFDocumentUnlockWithPassword function which takes 2 arguments: a CGPDFDocumentRef reference to the pdf document and a const char* password. Opening the pdf file first with the CGPDFDocumentCreateWithURL function will give you a CGPDFDocumentRef reference.
Now that you've opened the pdf file you'll need to draw each page individually to a UIView. This is the hardest part and takes a lot of work to get it done right. This question on SO has helped me a lot while working on my customizable framework for rendering PDF files.

I've written a pretty good Kiosk-Example that does the download, displaying the progress bar, saving the pdf in documents directory, displaying, opening - everything you want.
Password support is included, and looks like that:
const char *key = [passwordString UTF8String];
BOOL success = CGPDFDocumentUnlockWithPassword(pdf, key);

Related

Failed to display UIWebView to display docx/xlsx file with SFUZipEndOfCentralDirectoryError error with custom URL

We are writing some program to display documents on iOS. I think that there are a lot of confusion on the web about what type of documents which iOS UIWebView could display. Generally people refer to Technical Q&A QA1630 Using UIWebView to display select document types to see that all the MS office 07+ files (such as docx, xlsx, pptx) could not be displayed, however actually that is not what we see from testing. Actually we are able to display docx/xlsx/pptx document at UIWebView either loading from a remote URL, local file or in memory (loadData, here the baseURL can not be nil on simulator, see this link). Of course We are testing on latest version of iOS on iPhone simulator, it might be that the support was not at older iOS. At this point, We don't know that yet. If you know, please let me know.
However right now, We have one issue to display document at UIWebView by using custom URL for security reason. I did the custom URL by following the code here: protecting iOS resource. We could display xls, doc, ppt, pdf file, but not docx/xlsx/pptx, We got some error like this:
EXCEPTION SFUZipEndOfCentralDirectoryError: Could not find the end of central directory record
We tried to debug and could not figure what's to do here. Do you see similar error here? Could anyone shed some lights on this? Thanks very much.
It looks like the document you're trying to open might be corrupt. docx, xlsx, and pptx files are actually zip files containing a bunch of XML documents and other data. Check if you are able to uncompress the file on your computer by renaming it to .zip and then unzipping.

How can I download a .webarchive with ASIHTTPRequest?

I was just wondering how I can download a .webarchive from my UIWebView using ASIHTTPRequest. I've looked at their documentation but unfortunately, it doesn't mention anything about saving web archives.
I noticed that this app saves .webarchives to the iOS device and loads them.
To quote http://en.wikipedia.org/wiki/Webarchive :
"The webarchive format is a concatenation of source files with
filenames saved in the binary plist format using NSKeyedEncoder"
As jbat100 mentions, the ASIWebPageRequest code is likely to be a useful starting point - you'll need to write code to do the saving of the files into the binary plist format yourself.

Reading pdf file in ipad application

In my Ipad application i need to read .pdf files. these pdf files are stored in my server. the size of the pdf files are nearly 20Mb. Normaly in ipad we can view the pdf using UIwebview, but it's not useful in this case. the reason is normaly in iPad the pdf files are downloaded and showed in UIWebview.. but in my case the size maters..so i need another solution to read pdf files.
my suggestion is take the pdf in a spitted fashion.means suppose ur pdf contains 1000 pages download first page and load on the webView and start download for the remaining pages in the background something like nsoperationquee .so you need to modify in the server side also if you like my suggestion.
You have pdf url that in server right? get the pdf files from the server and store it locally like DB. After that you can display the PDF files from the DB. This is the one time process.Then it not take much time for download.
Or you get the pdf images and display in the uiimageview its simple and easy. But one drawback is you can read the text but not do any action on that i.e., copy the text like that
Thanking you

Change in resolution in pdf after save by itextsharp

New to itextsharp. I'm not sure if this is the right forum; this is due to the fact that there are three programs involved in the project I'll describe below: silverlight 4, Amyuni's PDF for Silverlight, and itextsharp 4. Add to that the fact that I'm using code I got in a project off the web to translate the silverlight inkpresenter into an image. This includes and "editableimage" class that calls a png encoder class. As you can see in my rush to get this working I've found many tools, any one of which may be causing my problem (translate that to mean that I am using one or more them incorrectly :-).
I have a feeling it's something in the way I'm using itextsharp to save a pdf though it occurred to me that the pngencoder may have something to do with it. At the very least I can see it doesn't compress the png that it creates.
I have a project where I am loading a pdf from a file to a silverlight inkpresenter using Amyuni's Pdf for silverlight. As proof of concept I brought the first page of a pdf into the inpresenter using Amyuni, created a bitmap using a writeablebitmap, passed that to the editableimage object and the png encoder mentioned above. The png is then streamed to an httphandler where itextsharp converts it to a pdf. This pdf is saved in a database table. I made sure the rectangle for the pdf had the same dimensions as the bitmap created by the writeable bitmap and editableimage.
I then used Amyuni Pdf for Silverlight to read the pdf saved in the database back to the inkpresenter. For some reason the loaded pdf is bigger than the original page from the pdf file. The font is larger, less of the pdf fits into the same inkpresenter. I'm not sure but it seems like the dimensions of the pdf page saved to the database are larger than they were when they were loaded into the same inkpresenter from the file. I suspect that it's some mistake I'm making when saving the pdf page using itext sharp. I have seen posts here in stackoverflow where other people have experienced the same thing. I've done my best to figure this out by googling but, unfortunately, it's hard to pin the issue down considering all the differnt kinds of software I'm using.
Any advice would be appreciated.
Fig000
If you are already using Amyuni PDF Creator for showing PDF files in Silverlight, you could also use it to generate your PDF files with the png image, at server side.
The code will look like this:
PDFCreactiveX pdfdoc = new PDFCreactiveXClass();
pdfdoc.CreateObject(ObjectTypeConstants.acObjectTypePicture, "Picture1");
pdfdoc.set_ObjectAttribute("Picture1", "FileName", "C:\\mytemppicture.png");
pdfdoc.set_ObjectAttribute("Picture1", "Left", 0);
pdfdoc.set_ObjectAttribute("Picture1", "Top", 0);
pdfdoc.Save("c:\\mytemppdf.pdf", FileSaveOptionConstants.acFileSaveDefault);

How can I output tables to a PDF file with the iPhone SDK?

I want to output a PDF using UIKit's PDF creation methods. I see plenty of information on the web about creating a graphic context in a PDF, but I want to create smart text tables whose cells the user can later copy and paste into other applications (Word, Excel, etc.). How do I do this?
Unfortunately, that's not trivial. I recommend you the libharu PDF library for iPhone as a good point to start from.