I've created a word processing document that will be used by many people (a style sheet for writers), and will also be updated periodically. I suspect that well have some who print the document out for reference. Is it possible in Google Documents to put field codes in the footer that indicate the print date or the save date? If not, maybe we could name the document "[document title] version [x]" and have that print in the footer?
3 Answers
Alas, this doesn't seem possible right now; Google Docs doesn't support the auto-updating fields that Office does.
Here is a support thread where you can request this feature, though - I've also posted a reply on it.
-
Thanks; I added a comment as well. That thread did tell me how to add a page count (i.e., page X of Y), that would have been my next question! Commented Sep 7, 2010 at 21:33
-
Unfortunately, that link is now out of date. Commented May 11, 2016 at 2:38
Yes, it is possible. However, it is not something that is really possible utilizing the existing API. Really the lack of fields and the associated capabilities like in Word is a major disability for document automation.
Something like this will insert a footer on document open and reopen, but it is ultimately not a good solution.
function onOpen() {
var time = new Date();
time = Utilities.formatDate(time, "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");
var doc = DocumentApp.getActiveDocument();
var s;
if (!doc.getFooter()) {
var footer = doc.addFooter();
var footerText = footer.appendParagrap(time);
} else {
var footer = doc.getFooter();
var footerElements = footer.getNumChildren();
var para = footer.getParagraphs();
s = para[footerElements-1].getText();
var footerText = footer.replaceText(s , time);
}
};
EDIT: How to add the script.
This code as I have presented above really should be in its own function called from the OnOpen() function rather than in there wholesale, but all good for example purposes.
If you go the Tools menu of an open document then down to Script Manager, when it loads check that it is currently empty, if has a records there, you are on your own for placement of the code.
Close the script manager, back to the Tools Menu and select Script Editor. Now if you had nothing in your script manager, select all the code and delete it. You can then paste in the code provided above and then save it.
Close the document and re-open and you should find there is now a Time Date in the footer. It should update on every open of the document, nothing fancy but will get you going.
Now for those of you who have code already associated with your document. Adding the code above minus the first and last lines into the onOpen() function will also work, but it may not due to code already present conflicting.
Hope this gets you going.
This is an expansion of jCisco's answer, and is a set-and-forget solution that works well in google docs, and could be tweaked to work for sheets etc.
Put this into your document's footer section:
Uncontrolled when Printed/Saved: 2016-09-03 14:05. Refresh pdf: goo.gl/xXXxxx
That goo.gl link is a short version of your document's "Anyone can view" sharing link, but replace
/edit?usp=sharing
at the end of the link with/export?format=pdf
(or/export/pdf
if it's a sheet). Then take your edited sharing link over to goo.gl to shorten it.Open your doc's script editor (Tools > Script Editor...) and add the below code. You have to open the editor from within the doc so that you end up with a script that is bound to the document, rather than a separate script that gets saved in your google drive.
Code:
function DocControl() {
var time = new Date();
time = Utilities.formatDate(time, "GMT+10:00", "yyyy-MM-dd' 'HH:mm");
var doc = DocumentApp.getActiveDocument();
var bod = doc.getBody();
var fol = bod.getParent();
// Define a custom paragraph style.
var style = {};
style[DocumentApp.Attribute.FONT_FAMILY] = 'Proxima Nova';
style[DocumentApp.Attribute.FONT_SIZE] = 8;
style[DocumentApp.Attribute.ITALIC] = true;
for (i = 0; i<fol.getNumChildren(); i++){
var child = fol.getChild(i);
if (child.getType() == DocumentApp.ElementType.FOOTER_SECTION) {
var footerText = child.asFooterSection().replaceText("Uncontrolled when Printed\/Saved: (.*). Refresh pdf: ", "Uncontrolled when Printed\/Saved: " + time + ". Refresh pdf: ");
footerText.setAttributes(style);
}
}
}
You might want to edit the timezone (mine is AEST) and the paragraph style to suit your needs.
- Add a Time-driven trigger (Resources > Current project's triggers). Set it to run "DocControl" every minute. Set notifications to weekly.
The time in the footer will now update every minute. There is no need to have the doc open or be online etc as Google's servers are doing all of the work.
However you can expect to get a weekly email from google listing the occasional times the script failed to run, but for me it was only ~1% of the time, and it runs again the next minute, so overall it didn't matter.