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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create PDF on the fly

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
Hi Folks,

I need to run a script every night which generates a PDF document and emails it a recipient. At the moment, my script generates a word document and emails it. So I just need to figure out the PDF generation part.

I have Acrobat 6.0 and Distiller 6.0 installed on my system. I use VBScript to create the word file. Can anyone tell me how I use Distiller to create the PDF using my script file.

Thanks

Mighty
 
Distiller processes PostScript files. So, a round-a-bout way of doing this is using VBScript to generated your Word file, as always, and then doing a "Print" to the "Adobe PDF Printer". That will, internally, stream a PostScript file to Distiller. Then, grab the resultant PDF.



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Hi Thomas,

Thanks for the reply. I have the following code to try to figure out how to do this:

wordFile = "C:\DVDsale24 Letter.doc"
set wordApp = CreateObject("word.application")
wordApp.Visible = false
wordApp.DisplayAlerts = false
wordApp.Documents.Open wordFile
wordApp.ActivePrinter = "Adobe PDF"
wordApp.PrintOut
wordApp.Documents.close
set wordApp = nothing

However, this prompts me for a file name to save the PDF to. Is there any way that I can specify a filename so that it won't prompt. I need this to be completely automatic.

I tried:

wordApp.PrintOut , , , "c:\test.pdf"

But the resultant PDf file doesn't open. Any help would be appreciated.


Mighty
 
Actually, while I am on the subject I really need to combine 3 files (2 Excel and 1 word) on the fly. Basically every night I will run a script that generates two Excel files and a word file. I then need to convert these to PDF and email them to a specific user. The creation of the word/excel documents is not a problem - it's the PDF conversion that is the issue for me at the moment.

Mighty
 
Found a solution on the web. Thanks for the help.

Mighty
 
Sure - sorry should have done that!!

This is the complete script that converts the word document to PDF. What I need to figure out now is how to combine several different documents into one PDF. Any idea if this is possible.


Dim fso ' As FileSystemObject
Dim wdo ' As Word.Application
Dim wdoc ' As Word.Document
Dim wdocs ' As Word.Documents
Dim sPrevPrinter ' As String
Dim oDistiller ' As PDFDistiller.PDFDistiller.1

' Create an Adobe Distiller Object
Set oDistiller = CreateObject("PDFDistiller.PDFDistiller.1")

' Create File System Object
Set fso = CreateObject("Scripting.FileSystemObject")

' Create Word Application
Set wdo = CreateObject("Word.Application")
Set wdocs = wdo.Documents

' Generate the name of the temp file to be created
sTempFile = fso.GetSpecialFolder(TemporaryFolder) + "\" + fso.GetTempName()

' Specify the word document and the PDF document
sDocFile = "c:\DVDsale24 Letter.doc"
sPDFFile = "c:\DVDsale24 Letter.pdf"

' Remember current active printer
sPrevPrinter = wdo.ActivePrinter

' Set the Active Printer to the Adobe PDF printer
wdo.ActivePrinter = "Adobe PDF"

' Open the Word document
Set wdoc = wdocs.Open(sDocFile)

' Print the Word document to the Acrobat Distiller -
' will generate a postscript (.ps) (temporary) file
wdo.ActiveDocument.PrintOut False , , , sTempFile

' This outcommented part was used while trying to use "Acrobat PDFWriter"
Do While wdo.BackgroundPrintingStatus > 0
' 'Do nothing - just wait for printing to finish before closing Word
Loop

wdoc.Close 0
wdo.ActivePrinter = sPrevPrinter
wdo.Quit 0
Set wdo = Nothing

' Distill the postscript file to PDF
oDistiller.FileToPDF sTempFile, sPDFFile, "Print"
Set oDistiller = Nothing

' Delete the temporary postscript file...
fso.DeleteFile(sTempFile)
Set fso = Nothing


Mighty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top