converting word file report to pdf file

i have to convert a report generated in word file through my matlab program, to pdf file to make it non editable. How may i do this....or is there any another solution for this..?

Answers (2)

If you are using report generator and would like to produce a .pdf programatically (for, e.g., a deployed application) but want to do that from a Word Document template, you can do this via the following code:
d = Report(...)
...
close(d);
rptview(d.OutputPath, 'pdf');
it will convert the .docx file to a .pdf. (Thus, you can proceed programatically as .dotx -> .docx -> .pdf, even in a deployed application.)
Unfortunately, this will also display the .pdf file as it is created, which may not be the intended behavior for a deployed application.
UPDATE: Turns out if you use docview(), you can avoid having anything display when you convert from .docx to .pdf:
docview('whateverYourFileHappensToBeNamed.docx','convertdocxtopdf','closeapp');
It is possible that this will not work on Linux (and maybe Mac); in any case, I haven't tested in those environments.

4 Comments

Both approaches apparently don't work on Linux (Ubuntu 20.04).
prepare_doc = Document('doc-template','docx','Prepare_Template.dotx') ;
open(prepare_doc) ;
moveToNextHole(prepare_doc) ;
append(prepare_doc, 'random') ;
close(prepare_doc) ;
rptview(prepare_doc.OutputPath, 'pdf')
%docview('doc-template.docx','convertdocxtopdf','closeapp') ;
doc-template.docx is created and appended according to the first few lines, but both approaches yield the same error.
Check for missing argument or incorrect argument data type in call to function 'rptview'.
%Check for missing argument or incorrect argument data type in call to function 'docview'.
Is there any other strategy for this on Linux?
Best,
Michael
PS Should I open a new thread for this?
Do you have Apache OpenOffice installed? According to the documentation, it seems that this must be installed to the appropriate location on Linux and Mac environments for docview() to work (and maybe, rptview()). (They list '/Applications/OpenOffice.app' as the filepath, but I think this is only correct for Mac.)
It's probably fine to keep it on this thread; definitely if you figure out how to get this to work on Linux, it will likely be helpful for others, too. I wish I could be more help myself, but unfortunately I don't have access to a Linux installation of MATLAB at the moment.
BTW, I think the error you are getting is because 'convertdocxtopdf' is not an option that is allowed on Linux; see the section 'Option' on this page of the documentation: https://www.mathworks.com/help/rptgen/ug/docview.html#bvd_jkj-option
This does not work when using a Table of Contens, it just gets deleted. Any fix for that?

Sign in to comment.

Wayne King
Wayne King on 29 Sep 2011
Hi, are you using MATLAB Report Generator? Because you can generate PDF. Alternatively, Can't you just save the Word document as PDF through MS Word?

Asked:

on 29 Sep 2011

Commented:

on 28 Sep 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!