Using X Command to Convert RTF to PDF with MS10 Word Excecutable

Accepted Solution Solved
Reply
Contributor
Posts: 69
Accepted Solution

Using X Command to Convert RTF to PDF with MS10 Word Excecutable

Hello everyone!

 

I need to convert a .RTF file into a .PDF file. I created the RTF with ODS RTF and proc report. I tried using ODS PDF, but the columns come out pretty weird so I thought using X command would be easier, the problem is, I can't figure out which executable  in Microsoft Office10 if the correct one for the x command. Is anyone familair with doing this? Here is the code I have so far:

 

 

x '"C:\Program Files\Office\Office14\_______.exe" c:\report\temp.rtf d:\report\tempxx.pdf /Y';

 

 

Thank you!


Accepted Solutions
Solution
‎03-14-2017 10:58 AM
Respected Advisor
Posts: 3,907

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

[ Edited ]

@daszlosek

Report writing is not what I'm normally doing so it can be that I miss the point. On a "high level" it's quite simple to add an additional output destination as demonstrated in below code. 

I assume if you have embedded output destination specific formatting in your Proc Report then it's another story.

%let RTF=C:\temp\test6.rtf;
%let PDF=C:\temp\test6.pdf;

ods _all_ close;
ods rtf file="&rtf";
ods pdf file="&pdf";
proc print data=sashelp.class;
run;
ods _all_ close;
ods listing;

 

View solution in original post


All Replies
Super User
Posts: 5,260

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

Sounds like a "clean" Microsoft question.

You may be better off searching for the aswer at support.office.com or other MS focused sites.

Data never sleeps
Contributor
Posts: 69

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

Good idea! I have also posted it on the microsoft forums but I keep on getting asked why am I not manually opening the rtf and turning it into a pdf- which I could do, but the whole point it to automate the process.

Super User
Posts: 3,115

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

Is there a reason why you don't use ODS PDF directly with PROC REPORT?

Contributor
Posts: 69

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

I need both rtf and ods pdf files. I was given the ods rtf and proc report by the company and I just started working for an they have been manually making the pdf files. There are over 10 rtf files that are generated by this code and I thought using X commander would be easier than using ods pdf because I would have to customize each ods pdf code to fit the different rtf files.

Super User
Posts: 3,115

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

OK, but it still might be worth a quick test of direct PDF as you may find you only need to change your ODS statement. If not then revert to your original plan. 

Solution
‎03-14-2017 10:58 AM
Respected Advisor
Posts: 3,907

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

[ Edited ]

@daszlosek

Report writing is not what I'm normally doing so it can be that I miss the point. On a "high level" it's quite simple to add an additional output destination as demonstrated in below code. 

I assume if you have embedded output destination specific formatting in your Proc Report then it's another story.

%let RTF=C:\temp\test6.rtf;
%let PDF=C:\temp\test6.pdf;

ods _all_ close;
ods rtf file="&rtf";
ods pdf file="&pdf";
proc print data=sashelp.class;
run;
ods _all_ close;
ods listing;

 

Respected Advisor
Posts: 3,907

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

I totally agree with what @SASKiwi's question implies: Try a bit harder and make it work with ODS PDF instead of going for work-arounds too early.

 

But just for fun here a way of how to do it. It needs Word 2010 or higher installed on the machine where you execute the SAS code. 

%let RTF=C:\temp\test6.rtf;
%let PDF=C:\temp\test6.pdf;
%let vbscript=C:\temp\test6.vbs;

ods rtf file="&RTF";
proc print data=sashelp.class;
run;
ods rtf close;

filename vbscript "&vbscript";
data _null_;
  file vbscript;
  put
      "Const WORD_PDF = 17"
    / "Const WORD_IN=""&RTF"""
    / "Const PDF_OUT=""&PDF"""
    / "Set objWord = CreateObject(""Word.Application"")"
    / "objWord.Visible = False"
    / "Set objDocument = objWord.Documents.Open(WORD_IN,,False)"
    / "objDocument.SaveAs PDF_OUT, WORD_PDF"
    / "objDocument.Close False"
    / "objWord.Quit"
    ;
run;
filename vbscript;

options symbolgen;
data _null_;
  /* execute vbs */
  call system("&vbscript");
  /* clean up: delete rtf & vbs */
  call system("del /q &vbscript");
  call system("del /q &RTF");
run;
Contributor
Posts: 69

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

Hello Patrick,

I will try this on Monday morning and see if it works!  I have replied to SASKiwi's question as to why I dont just use ods PDF above.

 

 

Thank you all for your input and help- seriosuly I wonderful forum,

 

Donal S.

New Contributor
Posts: 2

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

@Patrick

 

Hi Patrick,

I tried your code and found it works perfect when the path name does not contain space. Can you help me how to specify the path name with space? i.e. I:\Study Documents\test.rtf

 

Thanks,

Emma

Respected Advisor
Posts: 3,907

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

Spaces and even worse '&' need just some additional quoting as done below:

 

%let RTF=C:\temp\test & test\test6.rtf;
%let PDF=C:\temp\test & test\test6.pdf;
%let vbscript=C:\temp\test & test\test6.vbs;

/** no changes below the line required */
%let rtf=%unquote(%str("&rtf"));
%let pdf=%unquote(%str("&pdf"));
%let vbscript=%unquote(%str("&vbscript"));

ods rtf file=""&RTF"";
proc print data=sashelp.class;
run;
ods rtf close;

filename vbscript ""&vbscript"";
data _null_;
  file vbscript;
  put
      "Const WORD_PDF = 17"
    / "Const WORD_IN="&RTF""
    / "Const PDF_OUT="&PDF""
    / "Set objWord = CreateObject(""Word.Application"")"
    / "objWord.Visible = False"
    / "Set objDocument = objWord.Documents.Open(WORD_IN,,False)"
    / "objDocument.SaveAs PDF_OUT, WORD_PDF"
    / "objDocument.Close False"
    / "objWord.Quit"
    ;
run;
filename vbscript;

options symbolgen;
data _null_;
  /* execute vbs */
  call system(""&vbscript"");
  /* clean up: delete rtf & vbs */
  call system("del /q "&vbscript"");
  call system("del /q "&RTF"");
run;
New Contributor
Posts: 2

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

Thank you so much. It works great!

 

Best,

Emma

Contributor
Posts: 31

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

Hi Patrick,

 

Could you please help me how we can use this code to convert txt files to pdf 

 

at the same timce can we give pagenation in output pdf by using vbscript ?

 

Thanks in advance 

 

Respected Advisor
Posts: 3,907

Re: Using X Command to Convert RTF to PDF with MS10 Word Excecutable

Hi @RajasekharReddy

 

Please don't post new questions into an existing thread but post a new question and copy/paste a reference link to the existing thread.

 

SAS has a ODS PDF destination so not sure if you need to use any non-SAS tools at all. Just post your question into forum "ODS and Base Reporting".

 

You will also need to provide a bit more detail of what you have and what you need; best already demonstrating some own work and thinking and if possible also providing sample data in form of a data step and then a description of the desired output.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 13 replies
  • 1131 views
  • 2 likes
  • 6 in conversation