2

I have a function in my AppMaker app that works like a charm -- when you click on a button, it takes the data from the current record, applies some logic to it, and mashes it up and styles it as HTML. I want to deliver the results to the user in two ways:

  1. Print -- the function has a return that sends the HTML back to the browser, which opens up a print dialog as expected.
  2. PDF by Email -- the function also generates a PDF which is attached to an email sent to the user.

I heard feedback from users that the PDF version cuts off the bottom two lines, so I'm trying to find out why.

  • To send the PDF as an email attachment, I use Utilities.newBlob() to first blobify my HTML. Then I get the blob as a PDF, and then I send the PDF as an email attachment. The code looks like this:
var pdfContent = Utilities.newBlob(html, 'text/html', 'PE-' + name + '.html')
var pdf = pdfContent.getAs("application/pdf");
GmailApp.sendEmail(to, subject, body, {attachments: pdf});

The email is delivered correctly with a PDF attached to it, and when you open it up, it looks pretty much like the HTML that gets sent to the print dialog. When you go to print it, though, the last lines clearly get cut off. My advice to users (until I could dig into the problem) was to use the "Fit to Page" function in the print dialog. Looking at it more closely, though, I had an inkling that it might be a page size issue -- there's something off about the proportions when you view the PDF. Sure enough, upon changing the paper size from letter to A4 in the print dialog, the page lays out perfectly.

So now I can't figure out where the default to A4 is happening.

  • I tried setting the @page attribute for size in the <style> tag, with no effect -- it doesn't seem to survive the transition from HTML to blob to PDF:
html += '<style>@page {size: 215.9mm 279.4mm; margin: 15mm;}</style> etc...';

For size I've used millimeters (as above) and px as units, and I've tried just using the word 'letter'. No version of the above works.

Is there some other place where I can specify page size to make this stop happening?

Lynn Hoffman
  • 200
  • 11
  • since the part that you are having issues with is google apps script, I'd add that tag. There might be someone with more experience translating blobs to pdf that know if you can force anything. – J. G. Jun 14 '19 at 18:45
  • If the PDF looks good but only when printing the last two lines get cut off, that is not an issue with your logic but rather with the printer. My printer has a margin set up by default that cannot be changed and I don't use the proper margins, the last part always gets cut off. I hate it! – Morfinismo Jun 15 '19 at 13:37
  • @Morfinismo It's actually in the print dialog preview for the PDF where I'm first seeing the last two lines getting cut off when I have the paper size set to Letter. When I switch it to A4, the preview updates and the page content appears to fit. I haven't brought in any A4 paper from home to test with in the printer, but I'll do that next. – Lynn Hoffman Jun 17 '19 at 15:57

0 Answers0