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. Sharing pdf file via email
QtWS25 Last Chance

Sharing pdf file via email

Scheduled Pinned Locked Moved Mobile and Embedded
iospdf
2 Posts 2 Posters 1.3k Views
  • 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.
  • G Offline
    G Offline
    Grace Chang
    wrote on 22 Jun 2015, 22:34 last edited by
    #1

    QT Forum: Attach PDF Email Issue

    I'm writing a function in QT to generate a pdf file and share the file via email. On iOS I am encountering an issue where a pdf file gets generated and attached to an email and sent successfully, but the received email does not contain the original pdf file for some reason.

    The pdf file got generated as below returns true:

    qDebug() << QFile(attachedFile).exists();

    I was able to see the file got attached to an email and sent it. I was able to receive the email sent. However, when I opened up the email it did not contain the file attached.

    Here is my implementation.

    /* Constants */
    #define FILE_NAME "test.pdf"
    #include <QtWidgets>

    void ShareSheetWidget::open(QString attachedFile)
    {

    /* added iOS specific */
    #ifdef _WIN32
    #elif __APPLE__
        #if TARGET_OS_IPHONE
    
    /* Compute system directory from name */
    QString path = QStandardPaths::standardLocations(QStandardPaths::DataLocation).value(0);
    QDir dir(path);
    if (!dir.exists())
    dir.mkpath(path);
    if (!path.isEmpty() && !path.endsWith("/"))
    
    attachedFile = path+"/"+FILE_NAME;
    
    qDebug() << "attachedFile= " + attachedFile;
    
    QFile f(attachedFile);
    if(f.open(QIODevice::ReadWrite)) {
        QPdfWriter* writer = new QPdfWriter(&f);
        QPainter* p = new QPainter(writer);
        writer->setPageSize(QPagedPaintDevice::A5);
        p->drawText(QRect(100, 100, 2000, 200), "test");
        writer->newPage();
        p->drawText(QRect(100, 100, 2000, 200), "test");
        delete p;
        delete writer;
        f.close();
    }
    
    qDebug() << QFile(attachedFile).exists();
    
    if(QFile::exists(attachedFile)) {
        share(attachedFile);
    }
    else {
        qDebug() << "File not exists: " + attachedFile;
    }
    
    #endif
    #endif
    

    }

    void ShareSheetWidget::share(QString attachedFile)
    {
    /* added iOS specific /
    #ifdef _WIN32
    #elif APPLE
    #if TARGET_OS_IPHONE
    Mailer
    mailer = new Mailer(this);
    QString subject = "Sharing Master Rig";
    QList<QString> recepients;
    recepients << “grace.chang@123.com";
    QString body = "See attached file";
    mailer->open(subject, recepients, body, attachedFile);
    #endif
    #endif
    }

    The mailer class I'm referencing is written in Xcode and can be found here.

    https://github.com/ndesai/qt-mobile-modules/blob/master/Platform/mailer.mm

    Grace

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 Jul 2015, 22:49 last edited by
      #2

      Hi and welcome to devnet,

      You should also try to contact the author of the module. He might be able to help you since he wrote that code.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

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