I've been searching through posts but haven't found a solution. Can anybody tell me how to print a DOC file to the PDF Writer? -in order to get a PDF version of my DOC-
Printable View
I've been searching through posts but haven't found a solution. Can anybody tell me how to print a DOC file to the PDF Writer? -in order to get a PDF version of my DOC-
Nevermind... I found it out.
could you tell us how you did it? :)
Sure... putting all the code together (I have them on different subs) would be soemthing like thisVB Code:
Private objWord As Word.Application Private objDocument As Word.Document Private Sub WritePDF(FileName As String) Dim fName As String Dim pName As String Dim p As Printer On Error Resume Next Set objWord = GetObject(, "Word.Application") ' if error then Word wasn't open If Err.Number <> 0 Then ' open Word Set objWord = CreateObject("Word.Application") End If Err.Clear On Error GoTo 0 Set objDocument = objWord.Documents.Open(FileName) ' activate the document objDocument.Activate 'Save the default printer name pName = Printer.DeviceName With objWord On Error Resume Next ' I can not find a way to create the files where I want, and this 'is the default directory... so I delete all the PDF files, and 'LOG files first. Make sure this is not a problem. Kill "C:\Program Files\Adobe\Acrobat 4.0\PDF Output\*.log" Kill "C:\Program Files\Adobe\Acrobat 4.0\PDF Output\Microsoft Word - *.pdf" On Error GoTo 0 'Set the Acrobat Distiller as the default printer .ActivePrinter = "Acrobat Distiller" 'Print the File .PrintOut FileName:="", Range:=wdPrintAllDocument, item:= _ wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _ Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _ PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0 'Wait until the LOG file is created... this means the PDF has just 'been created Do DoEvents Loop Until Len(Dir("C:\Program Files\Adobe\Acrobat 4.0\PDF Output\Microsoft Word - *.log", _ vbArchive)) 'Get the created PDF filename fName = Dir("C:\Program Files\Adobe\Acrobat 4.0\PDF Output\Microsoft Word - *.pdf", vbArchive) 'Create the PDF Filename out of the DOC filename FileName = Trim$(FileName) FileName = Left$(FileName, Len(FileName) - 4) & ".pdf" 'Copy the file to the same directory where the DOC was. FileCopy "C:\Program Files\Adobe\Acrobat 4.0\PDF Output\" & fName, _ FileName Do Until Len(Dir(FileName, vbArchive)) DoEvents Loop MsgBox "The PDF has been created" 'Set the default printer to the original. .ActivePrinter = pName End With 'Close Word. objWord.Quit ' clean up after our-selves Set objWord = Nothing Set objDocument = Nothing End Sub
Let me know if you have any problems.
I don't have teh Type definitions for "Word", but oh well, I was just wondering :) not important
You need the "Microsoft Word 9.0" (or similar) reference for that to work.
You may also want to check the registry to see where the files are going to be created.VB Code:
Private objWord As Word.Application Private objDocument As Word.Document Private Sub WritePDF(FileName As String) Dim fName As String Dim pName As String Dim p As Printer Dim Branch As String Dim Path As String Branch = "Software\Microsoft\Windows NT\CurrentVersion\Print\Printers\Acrobat Distiller" Path = GetSettingString(HKEY_LOCAL_MACHINE, Branch, "Port", "") If Path = "" Then Path = "C:\Program Files\Adobe\Acrobat 4.0\PDF Output\" Else Path = Left$(Path, InStrRev(Path, "\")) End If On Error Resume Next Set objWord = GetObject(, "Word.Application") ' if error then Word wasn't open If Err.Number <> 0 Then ' open Word Set objWord = CreateObject("Word.Application") End If Err.Clear On Error GoTo 0 Set objDocument = objWord.Documents.Open(FileName) ' activate the document objDocument.Activate 'Save the default printer name pName = Printer.DeviceName With objWord On Error Resume Next ' I can not find a way to create the files where I want, and this 'is the default directory... so I delete all the PDF files, and 'LOG files first. Make sure this is not a problem. Kill Path & "*.log" Kill Path & "Microsoft Word - *.pdf" On Error GoTo 0 'Set the Acrobat Distiller as the default printer .ActivePrinter = "Acrobat Distiller" 'Print the File .PrintOut FileName:="", Range:=wdPrintAllDocument, item:= _ wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _ Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _ PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0 'Wait until the LOG file is created... this means the PDF has just 'been created Do DoEvents Loop Until Len(Dir("C:\Program Files\Adobe\Acrobat 4.0\PDF Output\Microsoft Word - *.log", _ vbArchive)) 'Get the created PDF filename fName = Dir("C:\Program Files\Adobe\Acrobat 4.0\PDF Output\Microsoft Word - *.pdf", vbArchive) 'Create the PDF Filename out of the DOC filename FileName = Trim$(FileName) FileName = Left$(FileName, Len(FileName) - 4) & ".pdf" 'Copy the file to the same directory where the DOC was. FileCopy "C:\Program Files\Adobe\Acrobat 4.0\PDF Output\" & fName, _ FileName Do Until Len(Dir(FileName, vbArchive)) DoEvents Loop MsgBox "The PDF has been created" 'Set the default printer to the original. .ActivePrinter = pName End With 'Close Word. objWord.Quit ' clean up after our-selves Set objWord = Nothing Set objDocument = Nothing End Sub
You would need this BAS (or similar functions) to work with the registry.
BTW, I've already tried to write a different directory in the registry -to get the files created where I was asking- but the Acrobat Distiller raised an error and didn't created. So... this is the only way I found.
However... like I said on other thread:
Quote:
Ok, I've already found out how to open Word and print to the PDF Writer to get the PDF I needed. However, does any of you know how to set the security of the PDF? It creates a PDF with these properties:
Security Method: None
Open Password: No
Security Password: No
Printing: Allowed
Changing the Document: Allowed
Selecting Text and Graphics: Allowed
Adding or Changing Annotations and Forms Fields: Allowed
I don't want to change all this stuff... but at least the Changing the Document to Not Allowed (for obvious reasons)
Any ideas?
how come it always loop at this statment when i run?
Do
DoEvents
Loop Until Len(Dir("C:\Program Files\Adobe\Acrobat 4.0\PDF Output\Microsoft Word - *.log", _
vbArchive))
VB Code:
'Wait until the LOG file is created... this means the PDF has just 'been created
Anyway... Try this instead:VB Code:
Do DoEvents Loop Until Len(Dir(Path & "Microsoft Word - *.log", _ vbArchive))
BTW, let's post the code as it should be:
If we are using a Path variable... let's use it in the whole code.VB Code:
Private objWord As Word.Application Private objDocument As Word.Document Private Sub WritePDF(FileName As String) Dim fName As String Dim pName As String Dim p As Printer Dim Branch As String Dim Path As String Branch = "Software\Microsoft\Windows NT\CurrentVersion\Print\Printers\Acrobat Distiller" Path = GetSettingString(HKEY_LOCAL_MACHINE, Branch, "Port", "") If Path = "" Then Path = "C:\Program Files\Adobe\Acrobat 4.0\PDF Output\" Else Path = Left$(Path, InStrRev(Path, "\")) End If On Error Resume Next Set objWord = GetObject(, "Word.Application") ' if error then Word wasn't open If Err.Number <> 0 Then ' open Word Set objWord = CreateObject("Word.Application") End If Err.Clear On Error GoTo 0 Set objDocument = objWord.Documents.Open(FileName) ' activate the document objDocument.Activate 'Save the default printer name pName = Printer.DeviceName With objWord On Error Resume Next ' I can not find a way to create the files where I want, and this 'is the default directory... so I delete all the PDF files, and 'LOG files first. Make sure this is not a problem. Kill Path & "*.log" Kill Path & "Microsoft Word - *.pdf" On Error GoTo 0 'Set the Acrobat Distiller as the default printer .ActivePrinter = "Acrobat Distiller" 'Print the File .PrintOut FileName:="", Range:=wdPrintAllDocument, item:= _ wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _ Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _ PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0 'Wait until the LOG file is created... this means the PDF has just 'been created Do DoEvents Loop Until Len(Dir(Path & "Microsoft Word - *.log", _ vbArchive)) 'Get the created PDF filename fName = Dir(Path & "Microsoft Word - *.pdf", vbArchive) 'Create the PDF Filename out of the DOC filename FileName = Trim$(FileName) FileName = Left$(FileName, Len(FileName) - 4) & ".pdf" 'Copy the file to the same directory where the DOC was. FileCopy Path & fName, _ FileName Do Until Len(Dir(FileName, vbArchive)) DoEvents Loop MsgBox "The PDF has been created" 'Set the default printer to the original. .ActivePrinter = pName End With 'Close Word. objWord.Quit ' clean up after our-selves Set objWord = Nothing Set objDocument = Nothing End Sub
Is there any special installation required?
I can use Acrobat Distiller manually,
but I cannot see the printer 'Acrobat Distiller' in the printer list
I can't remember. What's most important is that the Distiller Printer is in the list.
The problem is I cannot see the Distiller in the printer list
Then something is missing... that code won't help.
This is good with changing .doc to .pdf, what about if I have to save my email message wether its outlook message or netscape message to a .pdf message by selecting File menu>print, and how can you give an a name to the saved .pdf file automatically?
I think it's possible to save email message to .pdf I have seen this in one of document managment application, but I don't know the code behind it !!!
Me neither... and I don't have time to start trying to do it. I gave you the idea, play with it to get what you need. Sorry.
By the way... that would be what I would have to do (play with that code), but I neither have the time nor the need to have it done. So, I won't be able to be of much help.
i recieved this error
c:\prt.vbs(1, 17) Microsoft VBScript compilation error: Expected end of statement
What did you try to do??Quote:
Originally posted by sentme_mail
i recieved this error
c:\prt.vbs(1, 17) Microsoft VBScript compilation error: Expected end of statement
i save the file as .vbs and run it.
is there something missing?
Yes... that code is not VB Script. It's Visual Basic.
how do i run a vb?
With Microsoft Visual Studio
i am acutally look for a vb script which can automatically print a text file which i have exported from the NT event log. do you have any?
a "text" file? Man, you're way out in the wrong thread!Quote:
Originally posted by sentme_mail
i am acutally look for a vb script which can automatically print a text file which i have exported from the NT event log. do you have any?
where should i post it ?
Post a http://www.vbforums.com/images/newthread.gif. This thread was discussing how to print a PDF file (with Visual Basic)Quote:
Originally posted by sentme_mail
where should i post it ?
i posted it here.
http://www.vbforums.com/showthread.p...hreadid=246602
but no answer...
Ok... be patient! Don't garbage this thread anymore... it has nothing to do with what you need.
How do it go about doing it. I tried to convert the vb code, but faced a lot of errors. Appreciate the help
I think you should post it in the .Net forums. I've no idea, but should not be that hard since I see nothing that "strange".
We install PDF Print Drivers (from Adobe) on our customers machines and a PDF Printer simply appears in the PRINTER collection.
This requires no programming changes whatsoever - simply print to it like it's another printer.
I hear there are shareware versions of PDF Print drivers available if the cost of the Adobe is too much.
Why go through all this to get a output file in .PDF format?
Well, i simply need to convert the word doc to pdf using new .net technology. There was no code snippet on this. Anyway thx for the replies. Just wondering because i'm keep getting errors.
Regards,
Frank
The code I posted does just that. It changes the active printer to the Acrobat's, prints it and change the active printer to the one that was selected before.Quote:
Originally posted by szlamany
We install PDF Print Drivers (from Adobe) on our customers machines and a PDF Printer simply appears in the PRINTER collection.
This requires no programming changes whatsoever - simply print to it like it's another printer.
I hear there are shareware versions of PDF Print drivers available if the cost of the Adobe is too much.
Why go through all this to get a output file in .PDF format?
Sorry - it's a little early here and we are already having customer breakdown all over...Quote:
Originally posted by Mc Brain
The code I posted does just that. It changes the active printer to the Acrobat's, prints it and change the active printer to the one that was selected before.