[Solved]Printing on iOS



  • For all those who also need this functionality:
    [pic presentFromRect:view.bounds inView:view Animated:YES completionHandler:....
    it's animated
    that was the whole problem. Thx to the guys from digia!
    patrik

    Hi all,
    i'm currently stucked on printing with airprint. So far I can initialize all needed data. Problem is that
    I don't have a UIButton or something similar to pass it to the UIPrintInteractionController. So I tried
    to pass the main view but this ends up in an exception telling: "unrecoginized selector sent to instance".
    Has anyone experience with this, or an other idea? I couldn't find a way to send something to print without
    and objective-c ui element.

    void CMobilePrinter::printPage(QString pathImg){

    QFile f(pathImg);
    qDebug() << f.fileName();
    qDebug() << f.exists();
    
    QTemporaryFile* temp = QTemporaryFile::createNativeFile(f);
    if (temp != NULL){
        qDebug() << temp->rename(temp->fileName()+ ".jpg");
        qDebug() << temp->exists();
        qDebug() << temp->fileName();
        qDebug() << temp->size();
    
    
        NSString *path = temp->fileName().toNSString();
        NSURL* imgURL = [NSURL fileURLWithPath:path];
        UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    
        qDebug() << "ios enter print";
        if  (pic && [UIPrintInteractionController canPrintURL: imgURL] ) {
    
            qDebug() << "ios enter print valid";
            UIPrintInfo *printInfo = [UIPrintInfo printInfo];
            printInfo.outputType = UIPrintInfoOutputGeneral;
    
            printInfo.jobName = @"test.jpg";
            pic.printInfo = printInfo;
            pic.printingItem = imgURL;
            QWindowList list = QGuiApplication::allWindows();
            UIView *view = static_cast<UIView *>( QGuiApplication::platformNativeInterface()->nativeResourceForWindow("uiview", list.at(0)) );
            [pic presentFromRect:view.bounds inView:view Animated:YES completionHandler:
                        ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
                            if (!completed && error)
                                 NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
                            else
                               NSLog(@"ok");
                       }
            ];
        }
    

    }

    thx,
    patrik


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.