Render HTML to a Google Doc using app script? -


we work using google drive, docs, etc.

background of problem: 1 of our departments needs print hundreds of emails file away, page information included. have google web app takes contents of gmail thread, saves messages html blob, , exports these folder pdf. our users download these pdfs hard drive, , mass-print them.

the problem itself: our users need have page information on these pdfs when being printed. this, we're having app save emails google doc first, adding footers relevant info, convert pdfs afterwards. however, we're trying isn't working, , we're throwing stuff @ wall see stick.

this have working (allmessages string containing html content of email thread):

//save html content pdf file. var htmlbodyfile = myfolder.createfile("filename.html", allmessages, "text/html"); var pdfblob = htmlbodyfile.getas("application/pdf"); 

we tried (and failed):

//save html content google doc. getas() needs mimetype.  var htmlbodyfile = myfolder.createfile("filename.html", allmessages, "text/html"); var mydoc = htmlbodyfile.getas("google_docs"); // application/google_docs, , application/vnd.google-apps.document don't work either 

i noticed use ui right-click html file in drive , open docs. create new google doc , render html properly. when tried script (and failed),

var htmlbodyfile = myfolder.createfile("filename.html", allmessages, "text/html"); var mydoc = documentapp.openbyid(htmlbodyfile.getid()); 

it give me "document missing (perhaps deleted?)"

the following create doc, doesn't render html.

var mydoc = documentapp.create("docname");    var mybody = mydoc.getbody(); mybody.settext(allmessages); mydoc.saveandclose(); 

now i'm out of ideas.

we tried looking other solutions involving adobe. unfortunately, acrobat expensive , prints docs in random order (and doesn't allow command-line printing can script something). , reader doesn't have ability add page information need. seems our choice insert info here, when saving in google drive.

does know how render html google doc using app script?

i have solution this. line of code convert file appropriate google document. e.g. if it's csv file turned spreadsheet , if it's html converted google document.

var newfileid = drive.files.copy({title: newfilename}, oldfileid, {convert: true}).id; 

alternatively can convert blob containing html directly document.

var newfileid = drive.files.insert({title: newfilename}, blob, {convert: true}).id; 

for work first have turn on advanced drive api explained here

the entire advanced drive api explained here documentation rest version of api have somehow figure out how translate apps script using explanation on this site under "how method signatures determined" , examples here. auto complete feature in apps script editor helps this.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -