views:

539

answers:

5

Is it possible to use Google Docs for Mailer templates? How can I change template variables via API? Basically, I want to keep a template on Google and export it as a PDF file after changing few variables like name, address etc. Is it possible to do it completely via API in PHP?

EDIT

LiveDocX is providing these features but I think docs are not share-able.

EDIT

Is it true that even if no answer is acceptable I've to accept some answer because of bounty?

A: 

you could just download the docs (http://code.google.com/intl/de-DE/apis/documents/docs/3.0/developers_guide_protocol.html#DownloadingDocs) and use preg_replace_callback or something like that to do the template replacement in your php code, then upload it again (as a copy), but performancewise this would suck ...

roman
@Roman: you're right. That'd really suck..
understack
A: 

I am not sure if this is exactly what you are looking for, but in section 5 of this link it describes how to send out auto-generated e-mails based on a template/spreadsheet combo:

http://www.google.com/google-d-s/scripts/mail_merge.html#section5

__nv__
A: 

You can store one document as a template having some meta-symbols (like {0}) to be substituted with real values. Then retrive that document from google docs using API and substitute all metas with values. Then save the result of substitution as a new document, export it as PDF and remove.

All these things should be available through API.

Nikita G.
A: 

Here is something from forum about custom private templates

http://www.google.com/support/forum/p/Google+Docs/thread?tid=40b028a54a1fc981&hl=en

I think it should be possible to create private template by hand, and then edit it through API - create new document based on your private template (probably any saved document), edit it, save it and export as PDF

Hope it helps

Adam Kiss
+2  A: 

Not quite sure that I understand the use case here, but I think what you are wanting to do it to generate a series of PDFs that have been personalized with info like name and address to then mail out as shared web accessible documents on Google Docs.

If that is right, then yes I think you should be able to do that.

Step 1) Create the template in Google Docs.

Step 2) Copy the document using the API here: http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#CopyingDocs

Step 3) Edit the new document with the personalized info using the API here: http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#UpdatingDocs

Step 4) Share the new document with the appropriate person using the API here: http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#AccessControlLists

If you are specifically wanting the customized PDF the API for exporting is here (but I don't think you can share it as a PDF, though you can share it as a read-only document): http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#DownloadingDocs

Hope that helps.

Jackson Miller
@Jackson Miller : Is copying the doc mentioned in step2 necessary? Isn't it possible to change few variables directly in template doc, like we can insert rows in excelsheet without copying it? Or is there something I'm missing here?
understack
That depends on the use case.If you are wanting to share the docs online with other users then you need a copy.If however you are just wanting to export the PDF (to store yourself or mail to someone) then there is no need to copy.
Jackson Miller