PDFView printWithInfo:autoRotate: fails - objective-c

I'm trying to print a PDFDocument that I am constructing from a series of images. In case it matters, I'm doing all of this from within a Mozilla plugin.
I create the PDFDocument, and put it into a PDFView, then I call
[printView printWithInfo: [NSPrintInfo sharedPrintInfo] autoRotate: YES];
The print dialog comes up (as a separate window, instead of panel. I assume that that comes from being inside a mozilla window, so I wasn't too worried about it. The dialog shows my document, and I can page through it correctly, and everything looks good.
However, when I hit "Print" the dropdown with "Layout" etc becomes empty, and the view under that becomes empty. The window doesn't disappear, and the document doesn't print. Hitting Cancel does exactly the same thing. The only thing I can do then is force-quit Mozillla.
I based the program off of PDFKitLinker2 from the apple dev site, and that program works. But I can't see any significant differences between it and my version.
Any suggestions on where to look?
thanks.
EDIT: Yes, I know that this is pretty much an exact duplicate of Printing Off-screen PDFViews but that never got a sufficient answer... (And I didn't notice it until just now...)

Sounds like you have a memory management issue here. Have you checked the console log to see if there's an exception being thrown? How are you creating your PDFView?
But why not do it the way WebKit does it?
Specifically, declare a category on PDFDocument
#interface PDFDocument (PDFSecretsIKnowViaWebKit)
- (NSPrintOperation *)getPrintOperationForPrintInfo:(NSPrintInfo *)printInfo autoRotate:(BOOL)doRotate;
#end
Then when you want to print your PDFDocument simply get an NSPrintOperation from it and run it.
NSPrintOperation *op = [myPDFDoc getPrintOperationForPrintInfo:info autoRotate:YES];
[op runOperation];
// [op runOperationModalForWindow:delegate:didRunSelector:contextInfo:] if you have a window to attach it to

This works for me too. I've verified that getPrintOperationForPrintInfo:autoRotate: exists and appears to work correctly on 10.4, 10.5 and 10.6.

Related

AppleScript Syntax error while working around UI elements (Summary Service)

I'm trying to get/set value from Summary Service application using this code
tell application "SummaryService"
activate
delay 0.1
get value of text area 1 of scroll area 1 of window "Summary"
end tell
And whatever I do (get or set) I get this error
Error image
(!) Generally, I'd like to find a way of launching Summary App with text as an argument (I want to add this possibility into my obj-c app). I've googled for some time and what I get is this one. Nevertheless it makes all the work behind scenes, giving to user only result of text transformation and makes to do some amount of unnecessary work, while I just want to launch default app.
Any help will be appreciated!
System Events can get windows, scroll areas and text areas, SummaryService can't.
tell application "SummaryService" to activate
delay 0.1
tell application "System Events"
tell application process "SummaryService"
get value of text area 1 of scroll area 1 of window "Summary"
end tell
end tell
Finally I don't solve my question in the way I previously want, but I found that there're many opensource summerize libs on github, so I use one
Just one moment since I want to use code written in Swift in my Objective-C project is to add
#import <Reductio/Reductio-Swift.h>
To controller where I want to implement desired functionality and call
[Reductio summarizeWithText:textToChange compression:compressionValue completion:^(NSArray<NSString *> * _Nonnull result) {}];
To get result.
PS: I still interested how to open SummaryService programmatically with text I choose.
PS 2: Suddenly I found such function as NSPerformService, which do exactly what I want. So I implement all the needed functionality in this way:
NSString *stringToSetInPb = #"sample text";
NSPasteboard *pb = [NSPasteboard pasteboardWithUniqueName];
[pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
[pb setString:stringToSetInPb forType:NSStringPboardType];
NSPerformService(#"Summarize", pb);
So question officially can be solved!

Why does printing (po) NSURLRequest's URL.path start with / but not when I hover over in Xcode?

I have:
AFHTTPRequestOperation* operation;
...
if ([operation.request.URL.path isEqualToString:somePath])
{
...
}
When I print it out I get:
(lldb) po operation.request.URL.path
/users/12345678/data/something
But when I hover over the variable path, the Xcode popover shows:
users/12345678/data/something
Why?
ps: Shown URLs are purely fictional :-) But it really does happen here and now.
To err on the side of caution, yes, do what Jason said and file a bug, and we will look at it.
On the other hand, be aware that in general, "po" works by running an API on your object provided by the framework vendors. Hovering in Xcode works by invoking the LLDB data formatters provided by the LLDB team.
There is no promise that the two will agree in the way they choose to represent objects (cfr. po #[#1,#2,#3] with p #[#1,#2,#3] to see this very clearly)
This sounds like a bug. If you can make a small self-contained repro example project, I'd encourage you to file a bug report at http://bugreport.apple.com/

App crash - "DiskImageCache: Could not resolve the absolute path of the old directory."

I am working on an app, where I display the data entered by user in a PDF file. PDF File is also created dynamically.
All this is fine.
I have implemented QuickLook framework to display the pdf file. When I call the QL framework, PDF file id displayed quite fine but when come back to the calling screen, my app crashes without any crash log or memory warnings.
I am calling QL with below code:
[[self navigationController] presentModalViewController:qlPreviewer animated:YES];
logs created are
DiskImageCache: Could not resolve the absolute path of the old directory.
[Switching to process 3070 thread 0x17603]
[Switching to process 3070 thread 0x15503]
This is quite interesting.....
When I run the same program in Instruments to check for leaks and Memory Management, i can only find leaks when PDF document is scrolled and all the pages are viewed.
However, interestingly there is no app crash that I can see.
Also, I did try with ZombieEnabled = YES and without it but no app crash with Instruments.
I am quite clueless on how to interpret this and have been trying different things to solve this. Also, I have tried UIWebView but the result is the same.
I was again trying something to check out the issue and found something interesting.
When i execute the code directly from X-Code - i get the crash in as explained above.
In other instance, if I execute the app by clicking on the app in the sim... no crash
I am yet to check this on device. Can someone confirm the crash on the device?
Also, Google does not have answer to this question.
Thanks in advance for your answers.
Can anyone shed some light on this?
I'm having the exact same issue.
As a workaround, you can disable or remove your 'All Exceptions' breakpoint. This might make debugging a little more difficult, but it's not as bad as having to relaunch the application all the time.
This is the breakpoint causing the issue. I had set it so long ago that I'd forgotten it was there
Deleting application from device helped me to solve this problem.
Maybe also at first you should try "Product > Clean" to ensure that all resources will be copied to your device.
I was able to fix mine with this code:
FirstViewController.h
NSURLRequest* reqObj;
#property(nonatomic, retain) NSURLRequest* reqObj;
FirstViewController.m
reqObj = [NSURLRequest requestWithUrl:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest:reqObj delegate:self];
then instead of loading it on my view after this line i waited for the connectionDidFinishLoading then load it to my view
Interesting: This has just started with my app too. No errors when checking for leaks but running the app in the sim actually is causing a Breakpoint, not a crash. I can hit the continue and the app keeps running, no problem.
My issue also is relating to a PDF, but I'm just using a web view to display a PDF from the app bundle. I've checked everything in the dealloc, it's all good, this may be a iOS 5.1 bug. I will update as I learn more.
#JimP, It isn't an iOS 5.1 bug. It has just started happening to my app as well, on iOS5.0. It seems to only affect pdfs of more than one page length, and seems to trigger most commonly on scrolling past the end of the document (although sometimes earlier also). It also seems to happen more often on a second load.
This could happen when you delete the object reference in code but having its reference in xib. Delete the outlet that you no longer need.
Just ran into this problem of loading a pdf file in an App I am converting to iOS 8. This App has been running fine since the first iPhone. I just removed the All Exceptions breakpoint to work around it.
I don't know if it's the same problem but I had an issue where switching from a PDF view to another more than three times via the tab bar controller caused a crash.
Turned out that embedding the views I was switching to within Navigation controllers put a stop to the crashing.

Why is my xcode 4.2 log always empty?

in a method that is accessed three times I want to write something to the log.
NSLog(#"%#", [response responseString]);
But there is nothing in the log. The log windows is completely white. Normally when I start an application there is always some stuff that shows up in the log but now it is totally empty.
How can I fix this?
Perhaps a really silly thing, but in the top right-corner of the console you should see this:
Check that the middle segment or right segment is selected.
NSString *responseString = [response responseString];
NSLog(#"%#", responseString);
set a breakpoint on the first line and debug the application to see if its coming in this code in the first place. If it is, hover over responseString and it will tell you whether it is nil or not.
When Console isn't behaving nicely for me (which happens sometimes when I'm doing driver level stuff or multi-threaded apps), a much more reliable thing to do is something like:
- (void) printToLog: (NSString *) aFormattedStringToPrint
{
// don't forget to remove an older copy of this file before
// your app finishes launching
FILE * aFile = fopen( "/tmp/debuggingoutput.txt", "a");
if(aFile)
{
fprintf(aFile, "%s", [aFormattedStringToPrint UTF8String];
fflush(aFile);
fclose(aFile);
}
}
(you can define a macro like LOGTHIS which might toggle between NSLog and the above more direct and to the point code)
And then you can "tail -f /tmp/debuggingoutput.txt" in your Terminal window while debugging and if nothing appears there, then you know your debugging lines aren't getting hit.
Today I have been frustrated with a similar problem. When the console is activated, only the variables pane is showing. No sign of the console pane. After finding Debug Area Help via right clicking in the variable pane, i could see that it is meant to sit next to it on the right.
The key for me was to Hide the Utilities panel. For me, the little buttons shown in Luke's answer above would not appear until hiding and unhiding the Utilites panel.

iOS access to Safari Reader feature through UIWebView

I am using iOS 4.3 & was wondering if there is any way that I can access the Safari's "Reader" feature through which webpages are removed of ads & other riff raff & the content takes the center stage.
If one opens any article in Safari (on say Wikipedia website), then a "Reader" button appears on the URL bar. Clicking on it presents a new window presenting the content beautifully.
How can I leverage this this functionality in iOS through UIWebView ?
PS: I know there is something called Readability Project. But I have no idea how to use this through UIWebView. Also for some websites Safari's Reader takes a call not to enable "Reader" feature, maybe it has no sufficient confidence?
Important: THIS ANSWER NO LONGER WORKS!
Readability shut down on September 30, 2016.
Here is something they recommend as a replacement:
https://mercury.postlight.com/web-parser/
Keeping the answer as a historical reference
--- Original answer ---
You can use Readability mobilizer for this. You will get a cleaned up version of any article, in the Readability styling:
http://www.readability.com/m?url=http://{URLOFTHEARTICLE}
Just prepare the URL and load it in your UIWebView. Here is how it looks in action:
http://www.readability.com/m?url=http%3A%2F%2Fwww.cnn.com%2F2013%2F01%2F11%2Fshowbiz%2Ftv%2Fgolden-globes-tv-vineyard%2Findex.html%3Fhpt%3Dhp_abar
Apple is making a pretty big deal about the inclusion of "Reader" in iOS 5. I'm assuming by the noise it's not available in 4.3
re: How to use through UIWebView
I can't find any mention of it in the Web Content Guide.
There's nothing about it in the UIWebView class reference.
And there's nothing in QA1630.
Dont parse HTML natively on iOS, I have done it before and its a messy business. Either create your own web service to do all the nasty work or look into using readability (readability.com) they provide an API.
There is also an open source ruby, python and php readability port that you can find here
https://github.com/iterationlabs/ruby-readability
https://github.com/gfxmonk/python-readability
http://code.fivefilters.org/p/php-readability/source/tree/master/
For you ruby enthusiasts, readability is also available as a gem, just google it.
Actually reader button do a bit of analysis where it parse the HTML Page and then it sees a clear body tag to parse. If that plugin is able to extract the exact body it will enable the reader button (My understanding from the readability source code). Now to implement the same for webview you just need to embed java script in your code (this java script is already available in the readability source code) and then you can achieve the same effect.
But I suspect the future plan from apple for the same. Because they can not just let anyone else do this content extraction with the huge business opportunity associated with iCloud with the combination of readability.
If you want you can simple extract the HTML from UIWebView and then extract the body and use it for your purpose. It's not a very rocket science to extract.
For analysis point of view, just have randomly some 10 HTML pages with Reader button enabled, you will see the core cotent belongs to body only and rest of the add, header, footer are separated.
I believe this is the time to re-invent the web content we use, and this is the perfect example of doing the same.
You can even do this by injecting javascript.
#define readJS #"(function(){window.baseUrl='https://www.readability.com';window.readabilityToken='';var s=document.createElement('script');s.setAttribute('type','text/javascript');s.setAttribute('charset','UTF-8');s.setAttribute('src',baseUrl+'/bookmarklet/read.js');document.documentElement.appendChild(s);})()"
And then when your webpage finishes loading
- (void)webViewDidFinishLoad:(UIWebView *)webview
{
[webview stringByEvaluatingJavaScriptFromString:readJS];
You can do it in iOS9.
first import SafariServices:
#import <SafariServices/SafariServices.h>
Afterwards we are instantiating SFSafariViewController and adding it as a subview. We have two options doing so:
Creating with only base URL
Creating with bas URL as well as entering 'Reading Mode' in case it is available
NSString *sURL = #"http://google.com";
NSURL *URL = [NSURL URLWithString:sURL];
SFSafariViewController *safari = [[SFSafariViewController alloc] initWithURL:URL]; // 1.
SFSafariViewController *safari = [[SFSafariViewController alloc] initWithURL:URL entersReaderIfAvailable:YES]; // 2.
[self presentViewController:safari animated:YES completion:nil];