0

I'm trying to display the .docx file in the browser using perl script but this is not work.

My script

print "Content-type: application/docx\n\n";
my $file = 'perl.docx';
open(my $f, "$file");
binmode $f;
binmode STDOUT;
my $buffer;
while (read($f, $buffer, 1024, 0)) {
  print $buffer;

}

Actually this is the viewing for pdf file extract from the google search.

When run the program into browser, downloaded the pl file. How can i display on browser?

mkHun
  • 5,891
  • 8
  • 38
  • 85
  • 1
    This was asked (far more clearly) [before](http://stackoverflow.com/questions/5001497/word-document-viewer-browser-plugin). I didn't vote to close since the link in the top answer is dead. – ikegami Dec 18 '14 at 14:33

2 Answers2

0

You haven't configured your server to run the Perl program so it is returning it as plain text.

You'll need to consult the documentation for your webserver for how you execute the program.

You appear to be writing CGI (don't do that, write PSGI and then use a CGI handler to deploy if it you really need CGI) so use that as your search term in the manual.

Here is a detailed tutorial on how to do it with Apache.


Once you deal with that, the browser will probably still download the Word document. Most browsers do not have plugins to display Word documents in the browser window these days. There is no way to work around that short of converting the document to HTML on the server.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
-1

As suggested in some of the comments have you considered converting the .DOCX file to PDF. If you convert the file to PDF then you should be able to display the PDF version of the file through pretty much all modern browsers. See PDF not showing in browser when read through a perl script for instructions on how to display your PDF file through Perl.

Note: for transparency I work for Zamzar (an online file conversion service). Should you need a converter to convert your DOCX file to PDF then we have recently released a developer API (https://developers.zamzar.com/) to convert files programatically and could support your conversion from DOCX to PDF which you can then plugin to your script to display in a browser.

Community
  • 1
  • 1
MJWStack
  • 1
  • 1