Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved]Printing on iOS
Forum Updated to NodeBB v4.3 + New Features

[Solved]Printing on iOS

Scheduled Pinned Locked Moved Mobile and Embedded
iosprintingobjective-c
1 Posts 1 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    patrikd
    wrote on 9 Mar 2015, 16:23 last edited by patrikd
    #1

    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

    1 Reply Last reply
    0

    1/1

    9 Mar 2015, 16:23

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved