diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index 208d83f..8498d24 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -2867,6 +2867,64 @@ gedit_document_get_encoding (GeditDocument *doc)
 	return doc->priv->encoding;
 }
 
+gboolean
+gedit_document_set_encoding (GeditDocument	 *doc,
+			     const GeditEncoding *enc,
+			     gboolean		  set_by_user)
+{
+	GtkTextIter start, end;
+	gchar *text;
+	gchar *intermediate_text;
+	gchar *converted_text;
+	const gchar *charset;
+	gsize bytes_written;
+	GError *error = NULL;
+
+	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+	g_return_val_if_fail (enc != NULL, FALSE);
+	/* Get all text in doc */
+	gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &start, &end);
+	text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (doc),
+					 &start,
+					 &end,
+					 FALSE);
+	/* Convert from UTF-8 to currently assumed encoding *
+	 * Effectively convert text back to its origin form */
+	charset = gedit_encoding_get_charset (gedit_document_get_encoding (doc));
+	intermediate_text = g_convert (text,
+				       -1,
+				       charset,
+				       "UTF-8",
+				       NULL,
+				       &bytes_written,
+				       &error);
+	g_free(text);
+	if (error != NULL) {
+		return FALSE;
+	}
+	/* Assume encoding is enc and convert to UTF-8 *
+	 * Effectively interpret origin text as enc    */
+	charset = gedit_encoding_get_charset (enc);
+	converted_text = g_convert (intermediate_text,
+				   -1,
+				   "UTF-8",
+				   charset,
+				   NULL,
+				   &bytes_written,
+				   &error);
+	g_free(intermediate_text);
+	if (error != NULL) {
+		return FALSE;
+	}
+	/* set convert text back to doc */
+	gtk_text_buffer_set_text (GTK_TEXT_BUFFER (doc),
+				  converted_text,
+				  -1);
+	/* set encoding of doc to enc */
+	set_encoding (doc, enc, set_by_user);
+	return TRUE;
+}
+
 glong
 _gedit_document_get_seconds_since_last_save_or_load (GeditDocument *doc)
 {
diff --git a/gedit/gedit-document.h b/gedit/gedit-document.h
index 70c69cd..913b5e9 100644
--- a/gedit/gedit-document.h
+++ b/gedit/gedit-document.h
@@ -295,6 +295,10 @@ GtkSourceLanguage
 const GeditEncoding 
 		*gedit_document_get_encoding	(GeditDocument       *doc);
 
+gboolean	 gedit_document_set_encoding	(GeditDocument       *doc,
+						 const GeditEncoding *encoding,
+						 gboolean	      set_by_user);
+
 void		 gedit_document_set_enable_search_highlighting 
 						(GeditDocument       *doc,
 						 gboolean             enable);
