BookmarkSubscribeRSS Feed
NickR
Quartz | Level 8
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!
10 REPLIES 10
deleted_user
Not applicable
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"]';
NickR
Quartz | Level 8
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!
NickR
Quartz | Level 8
- Message was edited by: Nick R
Doc_Duke
Rhodochrosite | Level 12
Try using ODS. It supports PDF output directly.
NickR
Quartz | Level 8
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.
data_null__
Jade | Level 19
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]
NickR
Quartz | Level 8
thanks so much. Will try this now.

-Nick
lifemore
Calcite | Level 5

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.

sorenroma
Calcite | Level 5

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.

cathyhill
Calcite | Level 5

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?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 3243 views
  • 0 likes
  • 7 in conversation