Consulting

Results 1 to 12 of 12

Thread: Image Converting

  1. #1
    VBAX Newbie
    Joined
    Jun 2006
    Posts
    4
    Location

    Image Converting

    Hello,

    Any idea on converting documents to images. Ex) .doc, or .pub into images. Is there an image converter??



    Tejwani

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hit your print screen key and then open your grapics program and paste as a new image.

    or

    in your graphics program use screen capture
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi there,

    You can use PDFCreator, a free open source PDF writer to do this. Most of the work I've done with it has been for Excel, but I managed to mock this up for Publisher:

    [vba]Sub PrintToPDFCreator_Early()
    'Macro Purpose: Print to Output file using PDFCreator
    ' (Download from http://sourceforge.net/projects/pdfcreator/)
    ' Designed for early bind, set reference to PDFCreator

    Dim OutputJob As PDFCreator.clsPDFCreator
    Dim sOutputName As String
    Dim sOutputPath As String
    Dim lOutputType As Long
    Dim i As Integer

    '/// Change the output file name and type here! ///
    sOutputName = "test"

    '0=PDF, 1=Png, 2=jpg, 3=bmp, 4=pcx, 5=tif, 6=ps, 7=eps, 8=txt
    lOutputType = 2

    sOutputPath = ActiveDocument.Path & Application.PathSeparator
    Set OutputJob = New PDFCreator.clsPDFCreator

    'Set correct filename extension
    Select Case lOutputType
    Case Is = 0
    sOutputName = sOutputName & ".pdf"
    Case Is = 1
    sOutputName = sOutputName & ".png"
    Case Is = 2
    sOutputName = sOutputName & ".jpg"
    Case Is = 3
    sOutputName = sOutputName & ".bmp"
    Case Is = 4
    sOutputName = sOutputName & ".pcx"
    Case Is = 5
    sOutputName = sOutputName & ".tif"
    Case Is = 6
    sOutputName = sOutputName & ".ps"
    Case Is = 7
    sOutputName = sOutputName & ".eps"
    Case Is = 8
    sOutputName = sOutputName & ".txt"
    End Select

    'Set job defaults
    With OutputJob
    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") = sOutputPath
    .cOption("AutosaveFilename") = sOutputName
    .cOption("AutosaveFormat") = lOutputType
    .cClearCache
    End With

    'Print the document to PDF

    ThisDocument.ActivePrinter = "PDFCreator"
    ThisDocument.PrintOut

    'Wait until the print job has entered the print queue
    Do Until OutputJob.cCountOfPrintjobs = 1
    DoEvents
    Loop
    OutputJob.cPrinterStop = False

    'Wait until the PDF file shows up then release the objects
    Do Until Dir(sOutputPath & sOutputName) <> ""
    DoEvents
    Loop
    OutputJob.cClose
    Set OutputJob = Nothing
    End Sub[/vba]

    Remember that you'll need to download (I use the PDFCreator 0.9.1, GPLGhostscript.exe download package) and install PDFCreator, and set a reference to it in the VBE. (Tools|References|PDFCreator).

    Unfortunately, I cannot get this to work in Word, for some reason. It gets stuck waiting for a job to enter the print queue, although it works as soon as you break the code and step into it. Publisher, it works a treat though. Only caveat is that you need to save your file first, as it uses that file's path to save the output file. That can be changed, however.

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  4. #4
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Doesn't Publisher have a SaveAsPicture() method where the file type is determined by the extension? May also work with Word.

    .02
    Stan

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Stan,

    True enough, Publisher does, but Word it doesn't look like Word does. (At least not SaveAsPicture anyway.)

    Actually, truth be told, I was thinking about that as I was writing the code, but got wrapped up in it and never checked the object browser to see.

    I will say, though, that the above code for publisher is a bit more robust than the SaveAsPicture method. While it might not be needed if you just want to save as a jpg, the PDFCreator code can also be used to save as PDF, BMP, etc...

    At any rate, if you just need a jpg from a publisher document, then yes, use the SaveAsPicture method.

    Thanks for pointing it out!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  6. #6
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    At any rate, if you just need a jpg from a publisher document, then yes, use the SaveAsPicture method.
    I may be wrong here, but .ActiveDocument.SaveAsPicture("c:\temp\temp.jpg") will save as a Jpeg, but .ActiveDocument.SaveAsPicture("c:\temp\temp.gif") will save as GIF

    When I mentioned Word, I got confused about Document Image Converter which is a 3rd party add-on that gives SaveAsPicture functionality to Word. Thanks for pointing that out.

    Stan

  7. #7
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Stan,

    Just tested, and it looks like the SaveAsPicture method is part of the Page collection, so the code needs to be like this:

    [vba]Sub test()
    ThisDocument.Pages(1).SaveAsPicture ("c:\temp\temp.jpg")
    ThisDocument.Pages(1).SaveAsPicture ("c:\temp\temp.gif")
    End Sub[/vba]

    It definately does work.

    Interesting thing... I inferred from the help that it would only do JPG files though:

    Quote Originally Posted by MS Help
    This example saves the first page in the active publication as a JPEG picture file. (Note that PathToFile must be replaced with a valid file path for this example to execute properly.)
    It isn't really obvious that you can use any valid picture extension there.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  8. #8
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Hmmm.. this from the VBA Reference. Then we can put this puppy to sleep

  9. #9
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Stan, what version are you running? I'm on 2003, and mine isn't reading quite the same...
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  10. #10
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by Ken Puls
    Stan, what version are you running? I'm on 2003, and mine isn't reading quite the same...
    2003 - Server Edition. Microsoft didn't include the vba .chm files with the installation, so we had to download them.

    http://msdn.microsoft.com/office/download/vba/

    Stan

  11. #11
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Ah, okay. I'm using 2003 Pro (desktop edition). Mine just says:

    FileName Required String. The path and file name of the new picture created.
    Then the example just uses the jpg file. I just looked at mine with too narrow a focus.

    Thanks for the banter on it!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  12. #12

    Post imagicon once you put it in paint and is bitmap


Posting Permissions

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