Results 1 to 12 of 12

Thread: PDFCreator

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    PDFCreator

    Hi
    I want to write a VB6 code that automatically converts word document into PDF format

    Here's my code but it doesn't work

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim cPDFCreator As clsPDFCreator
    3. Dim PDFName As String
    4. Dim PDFPath As String
    5.    
    6.    
    7. Set cPDFCreator = New clsPDFCreator
    8. Set cPDFCreatorOptions = New clsPDFCreatorOptions
    9. Set cPDFCreator.cOptions = cPDFCreatorOptions
    10. 'Am storing default printer to restore it later
    11. strDefaultPrinter = Printer.DeviceName
    12. If cPDFCreator.cStart("/NoProcessingAtStartup") = False Then
    13.         MsgBox "Can't initialize PDFCreator.", vbCritical + _
    14.                 vbOKOnly, "Error!"
    15.         Exit Sub
    16.     End If
    17.  
    18.  
    19. With cPDFCreator
    20. .cOption("UseAutosave") = 1
    21. .cOption("UseAutosaveDirectory") = 1
    22. .cOption("AutosaveDirectory") = "C:\PDFTEST\test"
    23. .cOption("AutosaveFilename") = "Description du service.pdf"
    24. .cOption("AutosaveFormat") = 0    ' 0 = PDF
    25. .cSaveOptions
    26. .cClearCache
    27. .cPrinterStop = False
    28. .cDefaultPrinter = "PDFCreator"
    29. .cPrintFile "C:\PDFTEST\Description du service.doc"
    30.  End With
    31. Printer.Print
    32.    
    33. Set cPDFCreator = Nothing
    34. Set cPDFCreatorOptions = Nothing
    35.    
    36. End Sub

    Can anyone help me

    thanks

  2. #2
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Godzone, oops Oz
    Posts
    355

    Re: PDFCreator

    Strangely just looking into this after our printing department decided they would really really rather have pdf than doc. Strangely still have to use the doc to merge approx 1300 forms

    First question, did you make a reference to PDFCreator in your project? Just working through it at the moment, so asking the easy questions first.

  3. #3
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Godzone, oops Oz
    Posts
    355

    Re: PDFCreator

    OKay got it to work creating a single document, recursive calls aren't working so figure I've change the state of something.

    Note this is in a sub as need to send a bunch of documents to it each time I run the overall project. A bit of tidy up on the declarations required I think.

    Code:
    Private Sub GeneratePDF(ByVal sDocument As String, ByVal sValue As String)
        '
        Dim cConverter As clsPDFCreator
        Dim cConverterOptions As clsPDFCreatorOptions
        '
        Set cConverter = New clsPDFCreator
        Set cConverterOptions = New clsPDFCreatorOptions
        Set cConverter.cOptions = cConverterOptions
        '
        ' Check we can initialise Converter
        '
        If cConverter.cStart("/NoProcessingAtStartup") = False Then
            MsgBox "Can't Initiase PDF Converter", vbCritical, "Letter Generation Error"
            Exit Sub
        End If
        '
        With cConverter
            .cOption("UseAutoSave") = 1
            .cOption("UseAutoSaveDirectory") = 1
            .cOption("AutoSaveDirectory") = sNewFolder
            .cOption("AutoSaveFileName") = sValue & ".pdf"
            .cOption("AutoSaveFormat") = 0 ' 0 = pdf
            .cSaveOptions
            .cClearCache
            .cPrinterStop = False
            .cDefaultPrinter = "PDFCreator"
            .cPrintFile sDocument
        End With
        '
        Set cConverterOptions = Nothing
        Set cConverter = Nothing
        '
    End Sub
    Figure my problem now is focus is bouncing between four applications

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: PDFCreator

    What is the exact problem? Are you getting errors?

  5. #5
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Godzone, oops Oz
    Posts
    355

    Re: PDFCreator

    Quote Originally Posted by Hack
    What is the exact problem? Are you getting errors?
    If asking me, then I'm still working on it. The above works to convert a single word document to pdf, but doesn't work for multiple documents. At the moment working on moving the declarations around and seeing if I don't have to reset the word object after "printing" the first pdf document.

    Never done this before so am having fun getting it to work

    No doubt I'll get stuck somewhere though.

  6. #6
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Godzone, oops Oz
    Posts
    355

    Re: PDFCreator

    Okay got this working for multiple documents. You need to do the merge first for all documents, then convert them to pdf. If anyone wants the code to do this can pop it over to you.

    One problem left, how do you do the conversion without showing the word document each time? Have tried the normal things setting visible to false etc but still popping a word window for each document.

  7. #7
    New Member
    Join Date
    May 2010
    Posts
    5

    Re: PDFCreator

    Hey KiwiDexter,
    did you workout how to stop word openning? I am trying to get this working in Visual Studio 2008 with pdfcreator 0.9.9 and using their sample 1 code. it opens the word document at the . cPrintfile(fi.fullname) and then sits there until i exit out of the word doc. it does not create the pdf file. works fine for a txt file
    Code:
    With _PDFCreator
                    .cOptions = opt
                    .cClearCache()
                    DefaultPrinter = .cDefaultPrinter
                    .cDefaultPrinter = "PDFCreator"
                    .cPrintFile(fi.FullName)
                    ReadyState = False
                    .cPrinterStop = False
    End With

  8. #8
    New Member
    Join Date
    Sep 2009
    Posts
    6

    Re: PDFCreator

    hi,
    why dont u use cute PDF.......
    advantage: it is hooked to ALL Programms as a printer and where u need it u can use it... and its FREE

    kind regards
    dieter

  9. #9
    Addicted Member
    Join Date
    Jul 2007
    Posts
    228

    Re: PDFCreator

    ... or ... use the Publish as PDF option of MS Word

  10. #10
    New Member
    Join Date
    May 2010
    Posts
    5

    Re: PDFCreator

    Quote Originally Posted by HellsBells View Post
    hi,
    why dont u use cute PDF.......
    advantage: it is hooked to ALL Programms as a printer and where u need it u can use it... and its FREE

    kind regards
    dieter
    Sorry but I am very new to vb programming. How do I reference Cutepdf so as to automate the save screen ( ie I dont want the save screen to show to the user, i want it to save to a predefined directory as a file name the same as the word doc)???? PDF Creator had sample vb code, does cutepdf????

  11. #11
    Addicted Member
    Join Date
    Jul 2007
    Posts
    228

    Re: PDFCreator

    I believe most of the free PDF print drivers, whether it's CutePDF, PrimoPDF, DoIt PDF, (there are many) do not offer a silent option. If you upgrade to a paid version, that option is often available.

    I'll ask again... why not use MS Office Automation to invoke Word's Publish as PDF option?

  12. #12
    New Member
    Join Date
    May 2010
    Posts
    5

    Re: PDFCreator

    Quote Originally Posted by Tom Moran View Post
    I believe most of the free PDF print drivers, whether it's CutePDF, PrimoPDF, DoIt PDF, (there are many) do not offer a silent option. If you upgrade to a paid version, that option is often available.

    I'll ask again... why not use MS Office Automation to invoke Word's Publish as PDF option?
    unfortunately we are using 2003 and can not upgrade to 2007 in the near future

    news flash

    Found the issue, word macro security was set to high. set it to low and away it went.
    Last edited by basbrian; May 7th, 2010 at 02:06 AM. Reason: Found solution

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