View Single Post
  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Brettjg Brettjg is offline
external usenet poster
 
Posts: 6
Default Converting Word docs to pdf

Thanks very much for that Graham, I'll have a play around with it and link
the library. If it can work it will be great because of the advantages over
Primo (smaller size, no licence required, totally free). I'll let you know
how I get on (I'll bet I'll have another question!), regards Brett.

http://sourceforge.net/projects/pdfcreator

is where you can get PDFCreator. Check it out!






"Graham Mayor" wrote:

I don't have PDFCreator to check, but the Excel macro uses the PDFCreator
object library. If this is made available to Word vba (vba tools
references) then I guess you could use the same method to print from Word.

You can get the name and path required as follows:

sPDFPath = ActiveDocument.Path & Application.PathSeparator
sPDFName = ActiveDocument.Name
intPos = InStrRev(sPDFName, ".")
sPDFName = Left(sPDFName, intPos - 1)
sPDFName = sPDFName & ".pdf"

to replace the lines

sPDFName = Range("pdf.name").Value
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator

and to replace Excel commands with Word commands:

ActiveDocument.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
to replace the line
ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"

and

If Len(sPDFPath) = 0 Then Exit Sub
to replace
If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub

The rest I suspect will be goverened by what the object library adds to the
feast - which I doin't have to check


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Brettjg wrote:
Hi Doug, thanks for that. The very cool part of PDFCreator is that
you don't need a licence to do these things (I just don't know how to
in Word VB, I can in Excel) and the file sizes are smaller. Ken Puls
is an Excel MVP and he has some code on his website for automation of
Excel sheets into PDFs and it works brilliantly. I just have a cell
called "pdf.name" containing the name that I want to save the
document as, and simply execute the macro, nothing more to do.

Perhaps if I put the code that I use in Excel here it may prompt an
idea (my difficulty is that I know NUTH-ING about Word and a
reasonable amount of Excel).

This code creates a PDF from one worksheet:
Option Explicit
Sub PDF_from_1_Worksheet() 'EARLY BINDING
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim printer_memory
printer_memory = Application.ActivePrinter

sPDFName = Range("pdf.name").Value
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator

If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub
Set pdfjob = New 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
.cClearCache
End With

ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False

Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose
Set pdfjob = Nothing

Application.ActivePrinter = printer_memory
End Sub


"Doug Robbins - Word MVP" wrote:

That is something that you would probably have to set up in
PDFCreator. In Acrobat, the prompt for filename/display of the
created file can be controlled by accessing the Properties dialog of
the Adobe PDF Printer.

It may be possible to do it the same way with PDFCreator, but I
believe that with PrimoPDF, you have to purchase a Developer Licence
to be able to access and control such features.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Brettjg" wrote in message
...
Hello out there

I'm using the code below to (successfully) create a nice small file
from a Word doc using PDFCreator. I want to use this rather than
Primo because the
pdf is the same quilaity but much smaller.

The question is: how can I modify this code to automatically take
the document name and save it as "Document name.pdf" into the
folder of the document origin without getting the prompts from
PDFCreator?

Sub PDF_FILE_PRINT()
Dim printer_memory
printer_memory = Application.ActivePrinter
Word.ActivePrinter = "PDFCreator"
Word.ActiveDocument.PrintOut
ActiveDocument.Close wdDoNotSaveChanges
Word.ActivePrinter = printer_memory
Application.OnTime When:=Now + TimeValue("00:00:01"),
Name:="zz_CLOSE_WORD"
End Sub
Sub zz_CLOSE_WORD()
Application.Quit wdDoNotSaveChanges
End Sub