Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 3    Views: 157

AppOne
buzztouch Evangelist
Profile
Posts: 348
Reg: Apr 03, 2012
London
13,980
10/17/13 08:21 AM (12 years ago)

How to Add a Print Button & AirPrint for Custom HTML

Just add the following code to the Custom HTML plugin: (note:didn't get the document titling to work) (in .h file) @property (nonatomic, retain) UIBarButtonItem *printButton; @property (nonatomic, retain) NSString *navBarTitleText; (in .m file) - (void)viewDidLoad { //Adding a Print Button// if ([UIPrintInteractionController isPrintingAvailable]) { UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(printWebView:)]; [self.navigationItem setRightBarButtonItem:barButton animated:NO]; self.printButton = barButton; [barButton release]; } } // implement the printWebView method // - (void)printWebView:(id)sender { UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController]; UIViewPrintFormatter *formatter = [self.webView viewPrintFormatter]; controller.printFormatter = formatter; UIPrintInfo *printInfo = [UIPrintInfo printInfo]; printInfo.outputType = UIPrintInfoOutputGeneral; printInfo.jobName = _navBarTitleText; controller.printInfo = printInfo; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { [controller presentFromBarButtonItem:self.printButton animated:YES completionHandler:NULL]; } else { [controller presentAnimated:YES completionHandler:NULL]; } }
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
10/17/13 03:49 PM (12 years ago)
Nice :) This goes in my snippet collection. Cheers! -- Smug
 
fusionsch
I hate code!
Profile
Posts: 516
Reg: Dec 28, 2010
Montreux Switze...
11,610
like
12/14/13 02:06 AM (12 years ago)
Thanks for the tip! This tweak is quite important... (Hope someday the print function will be part of the 'standard' BT core!) I tried to implement the function in PDF Doc plugin (BT 3.0 self-hosted) but I got errors... Did you try it in the new core? Thanks for any advice! Cheers Jack
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
12/18/13 12:51 PM (12 years ago)
Hi, @fusionch This works for me: http://www.buzztouch.com/forum/thread.php?tid=F7D97EB3E0777F64B4A4415 Although at the end when changing the navRightbar it is done in the BT_Viewcontroller and not BT_utilities Also, that code has changed and it will give you a warning but it works. Here is that modified code: if([navBarRightButtonType isEqualToString:@"home"]) theBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Print", @"Print") style:UIBarButtonItemStylePlain target:self action:@selector(printdoc) ]; Good luck
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.