Guys,
I'm using VSTO 2005 to create a word document. I would like the user to be able to hit a button and the document would be rendered to a pdf file, with a predefined filename and path.
Possible ?
Bob
Printable View
Guys,
I'm using VSTO 2005 to create a word document. I would like the user to be able to hit a button and the document would be rendered to a pdf file, with a predefined filename and path.
Possible ?
Bob
Bob,
Firstly, I'm no pro.
I've got PDFCreator from Sourceforge installed on my PC.
It is possible to automate PDFCreator via visual basic so that the printer is changed to PDFCreator and then the output filename and path can also be configured.
Is that what you want?
I'll need to find the code, tidy it up and then I'll post it.
Anto
Thanks for the response Anto,
I have already looked at that option, could you send me the code please ? When I have tried this I couldn't automate it without the user seeing the filename screen.
Thanks again,
Bob
Bob,
I originally found this code on the web. It's helped me massively.
Hope this helps:
VB Code:
Public Sub CreatePDF() Dim pdfjob Dim OldPrinter Dim sPDFPath, sPDFName As String 'Set your path and filename sPDFPath = "C:\" sPDFName = "TestPDF.pdf" Set pdfjob = CreateObject("PDFCreator.clsPDFCreator") With pdfjob If .cStart("/NoProcessingAtStartup") = False Then MsgBox "Can't initialize PDFCreator.", vbCritical + _ vbOKOnly, "PrtPDFCreator" Exit Sub End If .cOption("UseAutosave") = 1 .cOption("UseAutosaveDirectory") = 1 .cOption("AutosaveDirectory") = sPDFPath .cOption("AutosaveFilename") = sPDFName .cOption("AutosaveFormat") = 0 ' 0 = PDF .cClearCache End With OldPrinter = Word.ActivePrinter Word.ActivePrinter = "PDFCreator" 'Print the document to PDF ActiveDocument.PrintOut Background:=False, Copies:=1 Word.ActivePrinter = OldPrinter 'Wait until the print job has entered the print queue Do Until pdfjob.cCountOfPrintjobs = 1 DoEvents Loop pdfjob.cPrinterStop = False 'Wait until the PDF file shows up then release the objects Do Until Dir(sPDFPath & sPDFName) <> "" DoEvents Loop pdfjob.cClose Set pdfjob = Nothing MsgBox "PDF Created OK", vbOKOnly End Sub
This is obviously for use in Word.
Anto