Results 1 to 4 of 4

Thread: VSTO2005 - Render .doc to pdf

  1. #1

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    VSTO2005 - Render .doc to pdf

    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
    Last edited by staticbob; Jun 9th, 2006 at 11:12 AM.
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  2. #2
    New Member
    Join Date
    Jun 2006
    Posts
    12

    Re: VSTO2005 - Render .doc to pdf

    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

  3. #3

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: VSTO2005 - Render .doc to pdf

    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
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  4. #4
    New Member
    Join Date
    Jun 2006
    Posts
    12

    Re: VSTO2005 - Render .doc to pdf

    Bob,

    I originally found this code on the web. It's helped me massively.

    Hope this helps:

    VB Code:
    1. Public Sub CreatePDF()
    2.  
    3. Dim pdfjob
    4. Dim OldPrinter
    5. Dim sPDFPath, sPDFName As String
    6.  
    7. 'Set your path and filename
    8. sPDFPath = "C:\"
    9. sPDFName = "TestPDF.pdf"
    10.  
    11.  
    12.     Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
    13.  
    14.     With pdfjob
    15.         If .cStart("/NoProcessingAtStartup") = False Then
    16.             MsgBox "Can't initialize PDFCreator.", vbCritical + _
    17.                     vbOKOnly, "PrtPDFCreator"
    18.             Exit Sub
    19.         End If
    20.         .cOption("UseAutosave") = 1
    21.         .cOption("UseAutosaveDirectory") = 1
    22.         .cOption("AutosaveDirectory") = sPDFPath
    23.         .cOption("AutosaveFilename") = sPDFName
    24.         .cOption("AutosaveFormat") = 0    ' 0 = PDF
    25.         .cClearCache
    26.     End With
    27.  
    28. OldPrinter = Word.ActivePrinter
    29. Word.ActivePrinter = "PDFCreator"
    30.  
    31.     'Print the document to PDF
    32.    
    33.     ActiveDocument.PrintOut Background:=False, Copies:=1
    34.     Word.ActivePrinter = OldPrinter
    35.  
    36.     'Wait until the print job has entered the print queue
    37.     Do Until pdfjob.cCountOfPrintjobs = 1
    38.         DoEvents
    39.     Loop
    40.     pdfjob.cPrinterStop = False
    41.  
    42.     'Wait until the PDF file shows up then release the objects
    43.     Do Until Dir(sPDFPath & sPDFName) <> ""
    44.         DoEvents
    45.     Loop
    46.     pdfjob.cClose
    47.     Set pdfjob = Nothing
    48.  
    49.         MsgBox "PDF Created OK", vbOKOnly
    50.        
    51. End Sub

    This is obviously for use in Word.

    Anto
    Last edited by paraguayanto; Jun 21st, 2006 at 07:36 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width