Email a screenshot

Hi George & Co,

I’m trying, and failing, to do something that I hoped would be possible.
What I would like to do is email a screenshot from an iPad.

Window.print() works just fine but I would like to send the image to an email address as an attachment.

What drives this is the need to replace a load of paper tick box forms. I can set these as a form background image, use a signature panel overlay to collect the ticks etc and then hopefully send the composite image back as an attachment.

Any comments welcome.
kind regards,
Richard

In AppStudio 7, there is a new sample called Print2PDF. You give it the name of a form in your project, and it turns it into a PDF which can be emailed.

You’ll need to be using PhoneGap to make this all work.

Have a look at the sample and see if it helps. We’re still working on documentation to go along with it.

Hi Support,

This had me really confused for a while. Print2PDF is in V6 and does indeed produce a PDF but I can’t seem to attach this to an Email. Perhaps you meant to say try PhoneGapMail. This does grab a screen and attach to an EMail. Alas I need to use phonegap and the app has to be used on ipads. There is no time to put anything on the app store even if I could get the customers permission to expose their forms in this way.

I need to find another solution.

regards Richard

The problem with not doing this in PhoneGap is that there is no way to add an attachment to the email. A non-PhoneGap solution would be to find an Email service on the web which would let you send the data to it using an Ajax call. The service would then send the email.

You can distribute apps privately, without putting them in an app store. Here is more info:

Finally, here is some code for sending a form via email:

btnPreviewSendAsEmail.onclick = (() => {
  'use strict';

  const options = {};
  options.windowWidth = '900px';
  txtPreviewSellerEmail.innerText = 'gh@nsbasic.com';

  html2canvas(previewBody, options).then((canvas) => {
    cordova.plugins.email.open({
      to: txtPreviewSellerEmail.innerText,
      subject: 'Signed Agreement from PrimeTime Auctions',
      body: 'See attached.',
      attachments: `base64:icon.png//${canvas.toDataURL().substr(22)}`,
    });
  });
});

I have been able to do the Android version using phonegapEmail. However I run into an issue when I try to combine it with the version that also saves a PDF.

In the PDF version I have
src=“https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js”>
src=“https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js”>

as extraheaders and all is well. However this gives an error when sending an email as it says: Uncaught TypeError: html2canvas(…).then is not a function
at HTMLButtonElement.Button2.onclick (code.js:8)
Button2.onclick @ code.js:8

If I add:
src=“html2canvas.js” Which works in the standalone Email version PDF still save but trying an email I get:

html2canvas.js:2688 2ms html2canvas: onrendered option is deprecated, html2canvas returns a Promise with the canvas as the value

error @ html2canvas.js:2688
html2canvas @ html2canvas.js:3358
jsPDFAPI.addHTML @ jspdf.debug.js:1890
Button8.onclick @ code.js:25

Is it possible to have both functions in the one app and if so what should the extra headers be?

I’m using 7.0.1.0
kind regards Richard

Hi Support, Another way of possibly asking the same question is this:

If I take the stock print2PDF sample it works great on the PCs browser. It works on Android if deployed via Volt. It hangs on an iPad. (ios 11 + 12 tested)

If deployed using phonegap it does not even operate on Android.

using appstudio 7.0.2
kind regards, Richard

Hi Support,

I have tried updating the extraheader to the latest version. i.e.
…pdf/1.4.1/jsp…

The ipad now generates the PDF and displays it as “blob:” but does not offer to save it.

regards Richard

It’s probably because the browser is not allowed to do anything to affect the user’s filesystem. You’ll need to use PhoneGap plugins to do this.