Google Ads Developer Blog |
How to send PDF reports with AdWords scripts Posted: 19 Nov 2013 12:11 PM PST AdWords scripts allow you to create and email PDF documents, complete with pretty formatting and images. You can schedule a script that emails a professional-looking PDF report to your client weekly, complete with logos, watermarks, signatures, and other artwork. This blog post discusses this feature in more details. Sending an attachment The following snippet sends an email with an attachment: BLOB stands for Binary Large OBject. In Google Apps Script, blobs are used as the in-between data format that allows different services to pass data to each other. Creating a BLOB Start with an HTML string, and use Utilities.newBlob() to convert it into a blob: Converting a blob into PDF is as easy as Dealing with images A reasonable attempt looks like this: But that, unfortunately, won't work. The PDF generator never actually fetches resources that your HTML links to, so the image won't make it into the PDF. You need to specify the source of the image inline instead, as a base64-encoded string: Don't worry about the contents of the base64-encoded strings - they are gibberish and will consume lots of screen space if printed out. Putting it all together The following snippet will fetch the image from imageUrl, embed it into the PDF, and email the results to us...@example.com: Instead of fetching the image from the URL, you can upload it to Google Drive and use DriveApp to fetch it: So there you have it - blobs aren't just fun to say, they're useful as well. If you have questions or feedback about this feature or AdWords scripts in general, you can post them on our developer forum or our Google+ page. |
You are subscribed to email updates from Google Ads Developer Blog To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
No comments:
Post a Comment