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