How to convert Google Docs to HTML

May 1, 2024 / How-to Guide

This guide explains how to convert Google Docs to HTML.

Effortlessly moving content across platforms or formats is frequently required, yet converting content from Google Docs to another document processor often presents challenges, disrupting workflows and causing inefficiencies. Addressing this issue, we will explore two methods for converting Google Docs to HTML format.

You can convert content from Google Docs to HTML either manually through the export feature or by utilising Google Apps Script-

Manual Export from Google Docs

  1. Open Your Document –
    Begin by navigating to Google Docs and opening the specific document you want to convert to HTML.
  2. Access the ‘Download’ Option –
    Once your document is open, locate the File option in the upper-left corner of the screen and click on it to reveal a dropdown menu. Then, hang your cursor over the Download option.
  3. Select the HTML Format –
    From the list of offered formats, select Web Page (.html, zipped). Google Docs will automatically convert your document into HTML format and download it as a zipped file.
  4. Extract the Zipped File –
    Find the downloaded zipped file on your computer, right-click on it, and select Extract All. Select a destination for the extracted files. You will discover an HTML file along with a folder containing any related assets like images.
  5. View the HTML File –
    Open the extracted HTML file in a web browser to view your document as a web page. Instead, you can use a text editor or an HTML editor to view and edit the source code.

Using Google Apps Script

  1. Access Google Apps Script
    Navigate to Google Apps Script and initiate a new project by clicking on “New Project.”
  2. Write the Script-
    In the script editor, you will encounter a blank function named myFunction(). Customise this function according to your preference or keep it as is. Enter the provided script to access Google Doc content and export it as HTML-function exportDocToHtml() {
    var docId = “YOUR_DOCUMENT_ID”; // Replace ‘YOUR_DOCUMENT_ID’ with the ID of your Google Doc
    var doc = DocumentApp.openById(docId);
    var content = doc.getBody().getText();
    var blob = Utilities.newBlob(content, ‘text/html’, ‘output.html’);
    DriveApp.createFile(blob);
    }

    Important Note – To find your document’s ID, open your Google Doc and look at the URL. The ID is the long string of characters between https://docs.google.com/document/d/ and /edit.

  3. Run the Script –
    Save your script and execute it by clicking on the play button (??) at the top of the screen. Upon the first run, Google will prompt for permission to manage files in Google Drive.
  4. Access the HTML File –
    After the successful execution of the script, navigate to your Google Drive. You will find a new file named output.html, containing the HTML version of your Google Doc. Download the file to your computer.
  5. View the HTML File –
    Open the downloaded HTML file in a web browser to view your document as a web page. Instead, use a text editor or HTML editor for extra editing or to access the source code.

In this manner, you can convert Google Docs to HTML. It offers great flexibility. Whether opting for the direct manual export or the versatile Google Apps Script approach, both provide a direct process, allowing easy sharing and presentation of documents in a web-friendly format.

Hope you liked our article!

Dominos Search