Viewing text docs


#1

I’m building an app that lets users post documents that other users can
view. The format to the type of document doesn’t hold up with a cut and
paste so they have to upload. My question is how to display the content
of a document uploaded to the site without the user having to download
the file. Any help would be great.

Thanks

J


#2

it’s going to depend on the type of document.


#3

I agree with Chris… it can vary very widely depending on the type of
document… basically, what you need is a way to parse the document on
the
server and display it in the page as HTML… HTML being one of the very
few
things you can push across the internet and expect someone to receive…
there are converters for a lot of different document types, you could
possibly conceivably generate an image of the document somehow, etc…
but
it will all hinge on what kind of document it is.


#4

my experience with handling document assets on the web, be they word
docs, pdfs, spreadsheets, whatever, is that you should rely on the
browser and OS to handle the display. No matter how you look at it,
the file data has to be ‘downloaded’, whether it’s displayed in the
page as html or via a plugin or opened in Word. all you should worry
about is setting the correct headers then sending the data.

ex: i click a link to a Word document, Open Office opens to display
the document. I click on a pdf document and the Acrobat plugin
displays the document within the browser.

Chris


#5

To add to Luke and Chris -

Also be aware that it will be your hosting server doing the reading
before any document is served. e.g. If you upload a powerpoint file from
a windows machine, the server would need converters/readers to read that
file type.

Might be easy for a text document. If you are storing the file on the
server, you could simple use

# Return the contents of a file as a string
def file_to_str(filename)
   rv = ""

   if File.exist?(filename) == false
      rv =  nil
    else
      File.open(filename, "rb") do |infile|
         rv = infile.read
      end
  end
  rv
end

to retrieve the file contents as string and serve it any way you want.


#6

The docs will be limited to pdf files. So, if the OS handles the
display, the view should just link_to what, the file itself or is there
a method that needs to be called on it to tell the os have the Acrobat
plugin display it? Sorry for the rookie questions but, I’m a rookie.

Thanks for all the help

J
Chris H. wrote:

my experience with handling document assets on the web, be they word
docs, pdfs, spreadsheets, whatever, is that you should rely on the
browser and OS to handle the display. No matter how you look at it,
the file data has to be ‘downloaded’, whether it’s displayed in the
page as html or via a plugin or opened in Word. all you should worry
about is setting the correct headers then sending the data.

ex: i click a link to a Word document, Open Office opens to display
the document. I click on a pdf document and the Acrobat plugin
displays the document within the browser.

Chris


#7

Your browser should handle a link to a pdf if you have the plugin or
reader installed. Worse case is your browser will open a dialog and
ask if you want to save or open with whatever your default viewer is
set to.

I believe that with the Acrobat plugin, it will open the document
directly in the browser.

one thing i’ve done in the past is have an iframe setup for displaying
documents using the acrobat plugin. you can then target that iframe
from the link and the acrobat plugin should open within the targeted
iframe and display your document.

Chris