PDA

View Full Version : Image Converting



tejwani
06-20-2006, 10:50 AM
Hello,

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



Tejwani

lucas
06-20-2006, 01:24 PM
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

Ken Puls
06-20-2006, 02:50 PM
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 (http://www.excelguru.ca/node/21), but I managed to mock this up for Publisher:

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

Remember that you'll need to download (http://sourceforge.net/projects/pdfcreator/) (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,

stanl
06-21-2006, 08:21 AM
Doesn't Publisher have a SaveAsPicture() method where the file type is determined by the extension? May also work with Word.

.02
Stan

Ken Puls
06-21-2006, 08:29 AM
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!

stanl
06-21-2006, 10:14 AM
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:dunno

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

Ken Puls
06-21-2006, 10:39 AM
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:

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

It definately does work. :)

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


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.

stanl
06-21-2006, 04:13 PM
Hmmm.. this from the VBA Reference. Then we can put this puppy to sleep:friends:

Ken Puls
06-21-2006, 04:19 PM
Stan, what version are you running? I'm on 2003, and mine isn't reading quite the same...

stanl
06-22-2006, 02:55 AM
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

Ken Puls
06-22-2006, 09:01 AM
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!

EdCompSci
09-24-2006, 09:26 PM
hasn't always worked, but http://msxml.webcrawler.com/info.wbcrwl/clickit/search?r_aid=9AB7828F3D334C61972CE05A45370530&r_eop=5&r_sacop=2&r_spf=0&r_cop=main-title&r_snpp=2&r_spp=0&qqn=ropfO%2BEQ&r_coid=239138&rawto=http://www.topshareware.com/Imagicon-download-37332.htm