Airprint support - Possible ?

Previous topic - Next topic

Neurox

AirPrint (or/and ePrint) support would be really useful with iPhone/iPad in GLBasic developping.

Gernot ?  :whistle:
Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

Moebius

With a *!*GOOGLE SEARCH*!* code comes up for printing an image.  I can't test it, but the attached file compiles fine.  Because of attachment restrictions, you should rename it to a ".m"...
Not sure if you wanted something more than images, but considering the GLBasic is a graphics program, it's probably more suited to printing images that you render.
Possible GLB code, again not tested because I'd need to upgrade the device and sort out Airprint...
Code (glbasic) Select
IMPORT "C" int __stdcall GLBAirPrint(const char* imagePath)

FUNCTION PrintImage: Image%, Filename$ = "Print.png"

LOCAL Documents$ = PLATFORMINFO$("Documents")
SAVESPRITE Documents$ + "\\" + Filename$, Image
GLBAirPrint(Documents$ + "\\" + Filename$)

ENDFUNCTION


[attachment deleted by admin]
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Neurox

Thanks for source code but...
I realized that the AirPrint doesn't work with ipod touch second generation: (
I'll wait to try the new iPod coming next week.

Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

Neurox

Hi,
after 3 days full of tests the result is negative  :giveup:
I've tested the function with iPhone 4 with iOS 4.3.5 and iPod fourth gen
but the printer not receive anything and not print anything :'(
Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

Moebius

The original code was an objective C class, and I have no doubt I messed something up when deleting stuff from it  :whistle:
Unfortunately I can't help here...
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

trucidare

Its working from other applications? if not you need a bonjour compatible router
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

Neurox

I'm using a HP B110 printer, AirPrint compatible.
Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

trucidare

try it with another application first then with glbasic and tell me the difference
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

Neurox

I've made the test.
First of all I printed a html page from safari and then I printed from my program.
Unfortunately, the printer prints only the html page.  :'(
After printing my app didn't blocked but accept no more commands, as if MOUSESTATE function doesn't return any value.   :'(
Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

trucidare

Add a single NSLog(@"Error!"); line if the image is not present and the canPrint else so we could see if the app isnt ready to print
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

Neurox

I put in all the points the NSLog(), I discovered that the print is sent to the printer without problems (even if it doesn't print anything) and exit the function but it seems that GLBasic isn't able to control of the screen.
Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

Moebius

I deleted anything pertaining to 'self' in the class, including the delegate, and if I understand correctly the action should never be recognised as 'complete'.  The code is screwed up - find a better example on the internet.
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

trucidare

the print controller is a shared thing and could be used outside from classes. but apple uses delegates in all shared things so i need the full code to make it workable
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

Moebius

Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

trucidare

#14
very untested and not checked for syntax - please try someone - put them into .mm file

Code (glbasic) Select
//
//  AirPrintGLB.mm
//  AirPrintGLB
//
//  Created by Hiro Kanakawa on 01.08.11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface AirPrintGLB : NSObject <UIPrintInteractionControllerDelegate>

@end


@implementation AirPrintGLB

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }
   
    return self;
}

-(int) GLBAirPrint:(const char *) imagePath
{
NSString *path = [[NSString alloc ]initWithCString: imagePath];
NSData *myData = [NSData dataWithContentsOfFile: path];


UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    if (![UIPrintInteractionController isPrintingAvailable])
    {
        NSLog(@"Sorry printing not supported!");
        return -1;
    }

if(pic && [UIPrintInteractionController canPrintData: myData] ) {
        pic.delegate = self;

UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [path lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = myData;

void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
if (!completed && error) {
                NSLog(@"Error accoured!");
} else {
                NSLog(@"Tadaaaa");
            }
};

[pic presentAnimated:YES completionHandler:completionHandler];

} else {
return 0;
}
return 1;

}

@end

extern "C" int GLBAirPrint(const char* file);

extern "C" int GLBAirPrint(const char* file) {
    AirPrintGLB *printInfo = [[AirPrintGLB alloc]init];
    return [printInfo GLBAirPrint:file];
}


Tested in simulator:

Code (glbasic) Select
[01/Aug/2011:21:51:33 +0200] Save Original to Simulator: Accepted "test.gif" for printing (job #143896126, application/pdf, 1 pages){
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] save-143896126: job-state-changed - Job pending.{
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] Save Original to Simulator: Printing "test.gif" (job #143896126){
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] Viewing "/var/folders/pg/t13mbqm1063d_8wggb6xjpch0000gq/T/PrinterSimulator.RSqXpC/143896126.pdf".{
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] "POST /printers/save HTTP/1.1" 200 4093918 - successful-ok{
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] save-143896126: job-state-changed - Job printing.{
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] Save Original to Simulator: Connecting to printer.{
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] "POST /printers/save HTTP/1.1" 200 382 Get-Job-Attributes successful-ok{
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] Save Original to Simulator: Undefined error: 0{
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:33 +0200] save-143896126: job-completed - Job completed.{
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:34 +0200] Accepted connection from 192.168.125.1:49418 (IPv4){
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:34 +0200] "POST /printers/save HTTP/1.1" 200 295 Get-Printer-Attributes successful-ok{
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:34 +0200] Closing connection from 192.168.125.1:49418 (IPv4){
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:34 +0200] "POST /printers/save HTTP/1.1" 200 382 Get-Job-Attributes successful-ok{
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
[01/Aug/2011:21:51:34 +0200] Closing connection from 192.168.125.1:49416 (IPv4){
    NSFont = "\"Monaco 10.00 pt. P [] (0x10016af40) fobj=0x10030cae0, spc=6.00\"";
}
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC