Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server-side word DOC to PDF?

Status
Not open for further replies.

gbaughma

IS-IT--Management
Staff member
Nov 21, 2003
4,772
US
Anybody know of an easy (and preferably free) way to upload a word document in a web page to an ASP server, and have it convert it to a PDF on the server side for publishing?

If I can get it to do the conversion automatically, then folks can just upload their word files for document storage, and have it convert to PDF automatically.

Thanks in advance! (I'm looking for an example script and information about whatever add-on I'd need)



Just my 2¢
-Cole's Law: Shredded cabbage

--Greg
 
If you already have MS Word and Adobe Acrobat installed on the server you should be able to do it by creating an instance of the Word application "office automation" COM object then loading the doc and printing to PDF... I would be worried that it is not completely server thread-safe... so I might go with a singleton server or service type program that is always running.
 
  • Thread starter
  • Moderator
  • #3
Bump.

I don't have full acrobat...

What I really need to do is have an upload link in a web page, where people can upload documents. It will look at the document extension, and if it is a word DOC, then convert that to a PDF on the server, delete the original DOC file, and make the PDF available for viewing.

I'm racking my brain on this one... there *has* to be something (inexpensive, or preferably free) that will do this...



Just my 2¢
-Cole's Law: Shredded cabbage

--Greg
 
Persits has a PDF COM calls ASPPDF. You might want to check that out. I don't know if it will work for you or not.
 
I use the persits object. It works fine but it isn't free.
 
  • Thread starter
  • Moderator
  • #6
Resolved.

Two steps. Server-side load of Word, print using CutePDF/PDF995/etc... but that stalls halfway, and leaves you with a PostScript file.

Soooo... second step was to shell GhostScript and convert it the rest of the way. Total time *well* under a second.



Just my 2¢
-Cole's Law: Shredded cabbage

--Greg
 
Huh. I didn't think of Ghostscript. Care to post your code? I could use that.
 
  • Thread starter
  • Moderator
  • #8
Well, this is what I have working... I still have to fine tune it... this just takes the filename hard coded... it will obviously be the file passed from the upload string...

Code:
<%
Response.Buffer = False

' Note, strFilename has the extension stripped... we already know it's a .doc file
strFilename = "d:\Dload\Test"
strDocName = strFilename & ".doc"
strPDFFilename = strFileName & ".pdf"
strOutTemp = strFilename & "temp.ps"

' - - - - - - - - - - - - - - - - - - - - - - - 
' OPEN WORD DOCUMENT AND CREATE PDF FILE
' 
Response.Write "Opening word document...<br>"
set objWord = Createobject("Word.Application")
set objWordDocs = objWord.Documents
objWord.ActivePrinter = "CutePDF Writer"
set objWordDoc = objWordDocs.Open(strDocName)
Response.Write "Generating PostScript file...<br>"
objWordDoc.Printout False,,,strOutTemp
objWord.ActiveDocument.Close
objWord.Quit
Response.Write "Closing Word document...<br>"
set objWord = Nothing

' We've exported the file as a ps (postscript) file, now call GhostScript to turn it into a PDF

Set oShell = Server.CreateObject("Wscript.Shell")

Response.Write "Launching PS/PDF Converter....<br>"
strCmd = "%ComSpec% /c c:\progra~1\gs\gs8.60\bin\gswin32c -q -dNOPAUSE -sDEVICE#pdfwrite -sOutputFile#" & strPDFFilename & " " & strOutTemp & " quit.ps > nul"

' Response.Write strCmd

oShell.Run strCmd, 1, True

set oShell = Nothing

Response.Write "PDF File created... cleaning up.<br>"
' Delete the temporary file here....
Set filesys = CreateObject("Scripting.FileSystemObject")
filesys.DeleteFile(strOutTemp)

Response.Write "Done!<br>"


' We should now have a PDF file

%>

I know there's still some cleanup to do, error handling and so forth... (why do I always get paranoid when others critique my code? lol)



Just my 2¢
-Cole's Law: Shredded cabbage

--Greg
 
Another tool that you could try is ABCPDF.
It's not free but it's also not expensive and does a heck of a job with more than just word documents.
You can find them at
To build may have to be the slow laborious task of years. To destroy can simply be the thoughtless act of a single day.
 
  • Thread starter
  • Moderator
  • #10
Most of them work the same way, however... it's a two-step process... it essentially is a postscript output printer driver, then it's intercepted and run through something like GhostScript to convert the postscript to PDF.

Of course, the only down side, is you may not get WYSIWYG output; since the PDF page is being re-built from the postscript information.

Regardless, my method works. :D



Just my 2¢
-Cole's Law: Shredded cabbage

--Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top