Email: Save Email as PDF

Hello, has anyone tried to save or export an email as a pdf?
Sometimes it would be nice to be able to keep a certain email as a document on the smartphone.
I’ve already looked into the sources from the browser on the topic “Save page as PDF”. Maybe we could use a few code snippets from there.
But I’m afraid that’s almost beyond my programming skills.

Thanks

1 Like

They have the same backend nowadays… so it should be doable.

Invocation of save-as-pdf can be found here:

7 Likes

Thank you for your feedback. That encourages me to give it a try ;-).

3 Likes

I could give a try also. It seems that I should put some code into some file. But which file?
It’s more than ok if you can tell where I can find the info if there is some info.

OK, I did it. Here is a first try.
I put the code in the “MessageViewPullDown.qml”.
So this is for users who use the email view with pulldown menu (modified “HtmlViewer.qml”). As a noob, that was the simplest solution for me ;-).
The PDF files end up in Downloads.
There is definitely room for improvement.
For example, a reminder popup when saving or a status message after the download is complete would be nice.
It’s a pity, you can’t attach PDF files as an example here

/*
 * Copyright (c) 2013 – 2019 Jolla Ltd.
 *
 * License: Proprietary
 */

import QtQuick 2.0
import Sailfish.Silica 1.0
import Sailfish.WebView.Controls 1.0
import Sailfish.WebEngine 1.0
import Nemo.Notifications 1.0

PullDownMenu {
    id: root

    signal removeRequested
    signal savePageAsPDF

    function _openComposer(action) {
        pageStack.animatorPush(Qt.resolvedUrl("ComposerPage.qml"), { popDestination: previousPage, action: action, originalMessageId: message.messageId })
	}

    onSavePageAsPDF: {
		var filename = ((message.subject && message.subject.length !== 0) ? message.subject : (message.Id || "unnamed_file")) + ".pdf"
		var targetUrl = DownloadHelper.createUniqueFileUrl(filename, StandardPaths.download)
                    WebEngine.notifyObservers("embedui:download",
                                              {
                                                  "msg": "saveAsPdf",
                                                  "to": targetUrl
                                             })
		var text = "Nachricht wird gespeichert: " + targetUrl
		showSingleLineNotification(text) 
	}                           

   function showSingleLineNotification(text) {
        if (text.length > 0) {
            var n = notificationComponent.createObject(null, { 'summary': text,
                                                              'appIcon': "image://theme/icon-m-file-download-as-pdf" })
            n.publish()
        }
    }


    MenuItem {
        //% "Delete"
        text: qsTrId("jolla-email-me-delete")
        onClicked: {
            pageStack.pop()
            root.removeRequested()
        }
    }
    MenuItem {
        //: Forward message menu item
        //% "Forward"
        text: qsTrId("jolla-email-me-forward")
        onClicked: _openComposer('forward')
    }
    MenuItem {
        visible: replyAll
        //: Reply to all message recipients menu item
        //% "Reply to All"
        text: qsTrId("jolla-email-me-reply_all")
        onClicked: _openComposer('replyAll')
    }
    MenuItem {
        //: Reply to message sender menu item
        //% "Reply"
        text: qsTrId("jolla-email-me-reply")
        onClicked: _openComposer('reply')
    }
    MenuItem {
        //: Save message as PDF
        //% "Save as PDF
	text: qsTrId("Nachricht als PDF speichern")
	onClicked: savePageAsPDF()
   }
}

Edit - 09.07.23
I’ve added info using “SingleLineNotification”.

2 Likes

Working!
This is neat! Thanks for sharing.
For the ones like me who don’t know about modified HtmlViewer.qml, infos here.

2 Likes