Creating and managing documents

This page describes how to perform certain high-level tasks involving documents such as:

  • Create a new document
  • Copy an existing document

The following paragraphs describe these tasks in detail.

Creating a blank document

To create a new document, use the create method on the documents collection, as shown in the following example. This example creates a blank document with a specified title.


private static void createDoc(Docs service) throws IOException {
    Document doc = new Document()
            .setTitle("My Document");
    doc = service.documents().create(doc)
    System.out.println("Created document with title: " + doc.getTitle());


$title = 'My Document';
$document = new Google_Service_Docs_Document(array(
    'title' => $title

$document = $service->documents->create($document);
printf("Created document with title: %s\n", $document->title);


title = 'My Document'
body = {
    'title': title
doc = service.documents() \
print('Created document with title: {0}'.format(

Copying an existing document

To copy a document, use the Google Drive API's files().copy method.

The following examples copy an existing document. You can find the ID to use for the Drive API call in the URL of the document.


String copyTitle = "Copy Title";
File copyMetadata = new File().setName(copyTitle);
File documentCopyFile =
        driveService.files().copy(documentId, copyMetadata).execute();
String documentCopyId = documentCopyFile.getId();


var copyTitle = "Copy Title";
let request = {
  name: copyTitle,
  fileId: documentId,
  resource: request,
}, (err, driveResponse) => {
  let documentCopyId =;


$copyTitle = 'Copy Title';
$copy = new Google_Service_Drive_DriveFile(array(
    'name' => $copyTitle
$driveResponse = $driveService->files->copy($documentId, $copy);
$documentCopyId = $driveResponse->id;


copy_title = 'Copy Title'
body = {
    'name': copy_title
drive_response = drive_service.files().copy(
    fileId=document_id, body=body).execute()
document_copy_id = drive_response.get('id')

Note that you need to use an appropriate Drive API scope to make this call.