{"id":1142,"date":"2015-06-27T16:53:14","date_gmt":"2015-06-27T21:53:14","guid":{"rendered":"http:\/\/xlinesoft.com\/blog\/?p=1142"},"modified":"2026-08-16T10:19:47","modified_gmt":"2026-08-16T15:19:47","slug":"using-google-docs-viewer-to-preview-documents-online","status":"publish","type":"post","link":"https:\/\/xlinesoft.com\/blog\/2015\/06\/27\/using-google-docs-viewer-to-preview-documents-online\/","title":{"rendered":"Using Google Docs Viewer to preview documents online"},"content":{"rendered":"<p>Google Docs Viewer can be used to preview uploaded Word, Excel and PDF files directly in the browser. Instead of downloading a document first, a user can click a link in the PHPRunner application and open the file in the viewer.<\/p>\n<p><a href=\"http:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2015\/06\/google_docs_preview.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2015\/06\/google_docs_preview-300x186.png\" alt=\"\" title=\"google_docs_preview\" width=\"300\" height=\"186\" class=\"alignnone size-medium wp-image-1143\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2015\/06\/google_docs_preview-300x186.png 300w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2015\/06\/google_docs_preview-1024x637.png 1024w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2015\/06\/google_docs_preview-150x93.png 150w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2015\/06\/google_docs_preview-400x249.png 400w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2015\/06\/google_docs_preview.png 1071w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n<!--more--><\/p>\n<p>The basic viewer URL is:<br \/>\n<em>https:\/\/docs.google.com\/viewer?url=&lt;url of your document><\/em><\/p>\n<p>The important part is that Google must be able to reach the document URL. A file that is available only on a local network, behind authentication, or through a temporary session URL may not be accessible to the viewer.<\/p>\n<p>In PHPRunner, the setup depends on whether the field uses the Basic upload control or the Advanced upload control. In both cases, set the uploaded field to View as: Custom and build the viewer link from the stored file name.<\/p>\n<p><strong>Basic upload control:<\/strong><\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"php\" name=\"mshighlighter\" >\r\n$value = \"<a target=\"_blank\" href='https:\/\/docs.google.com\/viewer?url=https:\/\/yourwebsite.com\/project\/files\/\".$value.\"' rel=\"noopener\">\".$value.\"<\/a>\";<\/textarea><\/pre>\n<\/div>\n<p>Replace <em>https:\/\/yourwebsite.com\/project\/files\/<\/em> with the public URL of the folder where your uploaded files are stored.<\/p>\n<p><strong>Advanced upload control:<\/strong><\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"php\" name=\"mshighlighter\" >\r\n$fileArray = my_json_decode($value);\r\n$value=\"\";\r\n\r\nfor($i = 0; $i < count($fileArray); $i++)\r\n{\r\n\t$value .= \"<a target=\"_blank\" href='https:\/\/docs.google.com\/viewer?url=https:\/\/yourwebsite.com\/project\/\".$fileArray[$i][\"name\"].\"' rel=\"noopener\">\".\r\n\t\t$fileArray[$i][\"usrName\"].\"<\/a> \";\r\n}<\/textarea><\/pre>\n<\/div>\n<p>Replace <em>https:\/\/yourwebsite.com\/project\/<\/em> with the public URL of your web application.<\/p>\n<p><strong>Troubleshooting:<\/strong><br \/>\nIf the viewer does not open the document, first paste the document URL itself into a private\/incognito browser window. If the file cannot be opened there without logging in, Google Docs Viewer will not be able to retrieve it either.<\/p>\n<p>Also make sure the final document URL is a complete public URL beginning with https:\/\/ and does not point to a local file-system path.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Google Docs Viewer can be used to preview uploaded Word, Excel and PDF files directly in the browser. Instead of downloading a document first, a user can click a link in the PHPRunner application and open the file in the viewer.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,3,8],"tags":[],"_links":{"self":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/1142"}],"collection":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/comments?post=1142"}],"version-history":[{"count":11,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/1142\/revisions"}],"predecessor-version":[{"id":3431,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/1142\/revisions\/3431"}],"wp:attachment":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/media?parent=1142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/categories?post=1142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/tags?post=1142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}