window.print() does not work

1,445 views
Skip to first unread message

aktham nassar

unread,
Jun 13, 2011, 6:47:18 AM6/13/11
to phonegap
Hello,
I am using Phone Gap with sencha touch
i have a form panel that has XTemplate with all information loaded
i want to print this panel
i tried to use window.print() but nothing happened
can you help please.

Andrew Lunny

unread,
Jun 13, 2011, 11:49:38 AM6/13/11
to phon...@googlegroups.com

Mobile devices typically don't have printers. It makes them much harder to carry.

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

Shazron Abdullah

unread,
Jun 13, 2011, 7:07:02 PM6/13/11
to phon...@googlegroups.com
window.print only works in Mobile Safari, not in an embedded UIWebView. You will need a plugin for this. Do a search for print in the group.

aktham nassar

unread,
Jun 14, 2011, 2:34:14 AM6/14/11
to phonegap
Hello Andrew Lunny,
I am using I Pad 2 and wireless mac printer and it support printing.

On Jun 13, 6:49 pm, Andrew Lunny <andrew.lu...@nitobi.com> wrote:
> Mobile devices typically don't have printers. It makes them much harder to
> carry.
>

aktham nassar

unread,
Jun 14, 2011, 2:40:02 AM6/14/11
to phonegap
Thanks for your reply,
I don't no how to write a print plugin ,Is there anyone tried to do
that?,
i searched this group and there is no any example for print plugin.
It seems that i am the first one who is looking for that!
If any one knows how to do that , please post it.
Thank You.

On Jun 14, 2:07 am, Shazron Abdullah <shazron.abdul...@nitobi.com>
wrote:
> window.printonly works in Mobile Safari, not in an embedded UIWebView. You will need a plugin for this. Do a search forprintin the group.
>
> On 2011-06-13, at 3:47 AM, aktham nassar wrote:
>
>
>
>
>
>
>
> > Hello,
> > I am using Phone Gap with sencha touch
> > i have a form panel that has XTemplate with all information loaded
> > i want toprintthis panel

Shazron Abdullah

unread,
Jun 14, 2011, 2:00:12 PM6/14/11
to phon...@googlegroups.com
There is an example how in the Groups, I had a link to it (you'll have to find it). Then create one yourself - if no one steps forward.
If there was one, most likely its in the Plugins repo http://github.com/phonegap/phonegap-plugins

aktham nassar

unread,
Jun 15, 2011, 5:33:33 AM6/15/11
to phonegap
Thank You for Your Reply.
I wrote a phone gap plugin for print and here the objective c CODE
which i took from http://marceloprogramming.blogspot.com/2010/12/resolving-runtime-issues-with-airprint.html

when i compiled it at first time i have 3 errors so i fixed them as
below

now , when i call window.plugins.print.printWebPage(); it shows the
printer pop and i select the configuration and print
It prints BUT :
1. my application screen "pone gap web view " shows the printed
page(sign in page) without styles .!
2. it always print the first card which is the (sign in page) not the
current page that displays in my application that i want to print!
Can You Help Please . i want to print the current view of my
application when i press print button without destroy my application
style
i need your help ASAP ,
Thanks

/////////////////////////

- (void)printWebPage:(NSArray*)arguments withDict:
(NSDictionary*)options
{

if ([UIPrintInteractionController class]) {

UIPrintInteractionController *controller =
[UIPrintInteractionController sharedPrintController];
if(!controller){
NSLog(@"Couldn't get shared UIPrintInteractionController!");
return;
}
void (^completionHandler)(UIPrintInteractionController *, BOOL,
NSError *) =
^(UIPrintInteractionController *printController, BOOL completed,
NSError *error) {
if(!completed && error){
NSLog(@"FAILED! due to error in domain %@ with error code %u",
error.domain, error.code);
}
};



if ([UIPrintInfo class]) {

UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
//printInfo.jobName = [Singleton sharedInstance].globalBlogTitle;///
error1 Singleton undeclared
printInfo.duplex = UIPrintInfoDuplexLongEdge;
controller.printInfo = printInfo;
controller.showsPageRange = YES;
}

if ([UIViewPrintFormatter class]) {
//UIViewPrintFormatter *viewFormatter = [self.blogDetailsWebView
viewPrintFormatter];//error2 blogDetailsWebView undeclared
UIViewPrintFormatter *viewFormatter = [self.webView
viewPrintFormatter];
viewFormatter.startPage = 0;
controller.printFormatter = viewFormatter;
//error 3 navigationItem undeclared

//if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//[controller
presentFromBarButtonItem:self.navigationItem.rightBarButtonItem
animated:YES completionHandler:completionHandler];
//} else
[controller presentAnimated:YES
completionHandler:completionHandler];
}
}
}
///////////////////////////////////


On Jun 14, 11:00 am, Shazron Abdullah <shazron.abdul...@nitobi.com>
wrote:
> There is an example how in the Groups, I had a link to it (you'll have to find it). Then create one yourself - if no one steps forward.
> If there was one, most likely its in the Plugins repohttp://github.com/phonegap/phonegap-plugins

aktham nassar

unread,
Jun 15, 2011, 9:37:25 AM6/15/11
to phonegap
here My Print.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "PhoneGapCommand.h"

@interface Print : PhoneGapCommand {

}

- (void)printWebPage:(NSArray*)arguments withDict:
(NSDictionary*)options;

@end


and here my Print.m

@implementation Print

- (void)printWebPage:(NSArray*)arguments withDict:
(NSDictionary*)options
{
//the above code
}
@end

i found that my the interface is destroyed when i call the
printWebPage
and press one of the button in the print pop up except the cancel!!!!
Can You Help?

On Jun 14, 11:00 am, Shazron Abdullah <shazron.abdul...@nitobi.com>
wrote:
> There is an example how in the Groups, I had a link to it (you'll have to find it). Then create one yourself - if no one steps forward.
> If there was one, most likely its in the Plugins repohttp://github.com/phonegap/phonegap-plugins

aktham nassar

unread,
Jun 15, 2011, 9:36:11 AM6/15/11
to phonegap
here My Print.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "PhoneGapCommand.h"

@interface Print : PhoneGapCommand {

}

- (void)printWebPage:(NSArray*)arguments withDict:
(NSDictionary*)options;

@end


and here my Print.m

@implementation Print

- (void)printWebPage:(NSArray*)arguments withDict:
(NSDictionary*)options
{
//the above code
}
@end

i found that my the interface is destroyed when i call the
printWebPage
and press one of the button in the print pop up except the cancel!!!!
Can anyone Help?

Shazron Abdullah

unread,
Jun 15, 2011, 12:26:41 PM6/15/11
to phon...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages