DATA Step, Macro, Functions and more

WORD to PDF conversion

Reply
Frequent Contributor
Posts: 81

WORD to PDF conversion

Hi guys,

To convert *.DOC files to *.PDF in SAS, I invoke the DDE "WINWORD|SYSTEM" and use WORD commands like fileopen, fileprint etc. But before that I need to open WORD and change the default printer to 'Adobe Pdf' and give the destination to save the PDF files.

Is there a way I can change the default printer to 'Adobe pdf' and give the output destination in SAS?

Thanks for your time!
N/A
Posts: 0

Re: WORD to PDF conversion

I have an example of printing to an XPS file, but Acrobat PDF should be similar.

put '[fileprintsetup .printer="Microsoft XPS Document Writer" .donotsetassysdefault=1]';
put '[fileprint .appendprfile=0 .prtofilename="n:\xx.xps"]';
Frequent Contributor
Posts: 81

Re: WORD to PDF conversion

Thanks for the info Urchin!

I tried using the below code:

PUT '[FILEOPEN .NAME="' "&DIR\&FILENAME..DOC" '"]';
PUT '[FILEPRINTSETUP .PRINTER="ADOBE PDF" .DONOTSETASSYSDEFAULT=1]';
PUT '[FILEPRINT .APPENDPRFILE=0 .PRTOFILENAME = "' "&DIR\&FILENAME..PDF" '" ]';

I first two steps worked fine but somehow I am getting the following error message when executing the third step:

When you create a PostScipt file you have to send the host fonts. Please go to the printer properties, "Adobe PDF Setting" page and turn off the option "Do not send fonts to Distiller".

Does anyone know what might be causing this?

thanks!
Frequent Contributor
Posts: 81

Re: WORD to PDF conversion

- Message was edited by: Nick R
Trusted Advisor
Posts: 2,113

Re: WORD to PDF conversion

Try using ODS. It supports PDF output directly.
Frequent Contributor
Posts: 81

Re: WORD to PDF conversion

Thanks for the reply. Actually, I have so many WORD files which I have to convert to PDF programatically just by batch submitting the program. In short, I have to convert all WORD files in a folder to PDF.
Respected Advisor
Posts: 3,777

Re: WORD to PDF conversion

If found this VBSCRIPT on the internet and somehow figured out a way to alter the registry to set the PDF Output Directory. It works on my computer but I can't get visible=false to work. I set PDF output to same directory as WORD docs but you can change that.

[pre]
filename FT66F001 'path to word docs';

data _null_;
length path script filevar command $256;
path = pathname('FT66F001');
script = catx('\',pathname('WORK'),'DOC2PDF.vbs');
filevar = script;

/* write the script */
file dummy1 filevar=filevar;
put path=:$quote256.;
infile cards eof=eof;
do while(1);
input;
put _infile_;
end;
eof:
/* close the script file by opening another, not used */
filevar = catx('\',pathname('WORK'),'DUMMY.vbs');
file dummy1 filevar=filevar;

/* look at the script, not necessary but may be useful */
infile dummy2 filevar=script end=eof;
file log ls=256;
do _n_ = 1 by 1 until(eof);
input;
put _n_ z3. +1 _infile_;
end;

/* call the script */
command = catx(' ','cscript //nologo',quote(strip(script)));
infile dummy3 pipe filevar=command end=eof length=l;
do until(eof);
input;
putlog _infile_;
end;
stop;
cards;
Set objShell = WScript.CreateObject("WScript.Shell")

hkey = "HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\7.0\AdobePDFOutputFolder"
hkey0 = hkey & "\" '(Default)
default = objShell.RegRead(hkey0) 'Save default

WScript.Echo "Default=" & default

hkey5 = hkey & "\5"
objshell.RegWrite hkey5,path,"REG_SZ" 'PDF Path
objshell.RegWrite hkey0,5,"REG_DWORD" 'Set as default
WScript.Echo objshell.RegRead(hkey0) & " " & objshell.RegRead(hkey5)

Set WordObj = WScript.CreateObject("Word.Application")
WordObj.Visible = False
wordObj.DisplayAlerts = False

Set FS = CreateObject("Scripting.FileSystemObject")
Set FD = FS.GetFolder(Path) 'collection of files in path

For Each File In FD.Files
If Right(File.Name,3) = "doc" then
WordObj.Documents.Open(path & "\" & file.Name)
WordObj.ActivePrinter = "Adobe PDF"
WordObj.Options.UpdateFieldsAtPrint = False
WordObj.Options.PrintBackground = True
WordObj.Options.PrintReverse = False
WordObj.PrintOut
WordObj.Documents.Close
If Err.Number <> 0 then
'MsgBox("error" & Err.Number & vbCR & filename & vbCR & Err.Description)
WScript.Echo "ERROR: " & err.number & " " & filename & " " & Err.Description
end if
End if
Next
WordObj.Quit
objshell.RegWrite hkey0,default,"REG_DWORD"
objshell.RegDelete(hkey5)
;;;;
run;
[/pre]
Frequent Contributor
Posts: 81

Re: WORD to PDF conversion

thanks so much. Will try this now.

-Nick
N/A
Posts: 1

Re: WORD to PDF conversion

the easiest way of converting word to pdf in batch is using a third party software to do the job for you. Acrobat PDF is just one of the tool you can use to open the pdf and process pdf files.

i am using a simple and useful pdf control c#  to do conversion job and view pdf documnets. hope it helps for you.

N/A
Posts: 1

Re: WORD to PDF conversion

You can easily and successfully converts all word file with OLE objects, images, forms, graphs, hyperlinks, tables from word to PDF conversion software. I used

Kernel For Word to PDF software.

Occasional Contributor
Posts: 9

Re: WORD to PDF conversion

One vote for Kernel PDF conversion software. It works great. But I did not know whether it allows us to give output destination in SAS?

Ask a Question
Discussion stats
  • 10 replies
  • 1227 views
  • 0 likes
  • 7 in conversation