here is a bit of a problem for all of you. I have an html document stored locally on the device, with locally saved images (not included, on disk). I present an html page in UIWebView with the ability for the user to convert the page to PDF and send an email page. PDF is created using UIMarkupTextFormatter and a custom UIPrintPageRenderer, and not by creating a web page in an image and rendering the image in PDF format. This is because the PDF file must be searched.
Anyway, this worked fine. However, the client now asked that instead of a single page in uiwebview, we instead have large pages, broken into pieces. The export function still requires that the entire web page does not break into the pages that need to be exported.
Now the problem is that the exported PDF file has only images for the current page displayed. So, for example, if I have an entire html page divided into 4 smaller pages and the user views page 3 when they click on export, then pdf will contain all the information about the web page correctly, but only images that were on page 3. PDF does not contain blank images or distorted images, they simply do not exist. If I then go to one of the other pages and export again, I get images for this step. HTML is created from the very beginning, so the only difference is that images are displayed or not.
Now, I assume that UIMarkupTextPrintFormatter only displays images in the cache. This makes sense, because the user usually wants to print the page that they see, so the visualizer does not have to look beyond the cache for resources. Images in an html document have their own paths indicating the location of the file on disk, for example, 'file: /// var / mobile / Applications / C409BDBD-1254-4ADA-BAD8-F9BE5C171C93 / Documents / Export / SoMeJobN / Images / 915F0470-785D -40BF-A3E7-9945646843A7.jpg ', and I checked that all the images exist in this place.
I also rewrote NSURLCache and set the user cache. I found that markupformatter is causing
-(NSCachedURLResponse *) cachedResponseForRequest:(NSURLRequest *)request
for each of the images on the web page that are NOT on the current page, so it requests cache assets that are not on the current web page!
I tried to return the image downloaded from the disk using the following code.
NSString *pathString = [[request URL] absoluteString]; // Load the data NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:pathString]]; // Create the cacheable response UIImage *img = [UIImage imageWithData:data]; NSLog(@"%@",img); NSURLResponse *response = [[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/jpeg" expectedContentLength:-1 textEncodingName:nil] autorelease]; NSCachedURLResponse *cachedResponse = [[[NSCachedURLResponse alloc] initWithResponse:response data:data] autorelease]; return cachedResponse;
and I checked that the UIImage loaded correctly, so the data sounds. But it is not shown in PDF. So, does anyone have any idea why this might happen, have encountered a problem before, or could have come up with something else for me to try. I can reorganize the code to download all the pages in a series and export PDF parts for each page, but this seems like an inelegant solution to the problem.