How do I export MATLAB plots and tables from MATLAB to PDF directly?

64 views (last 30 days)
I am currently using 'ps2pdf' function available on File Exchange, to export my MATLAB figures and table objects to a ghost script and then convert it to PDF. My table in the PDF is distorted and a recent PDF update is suspected to cause this issue. Is there a way I could fix this distortion. Is there a MATLAB function that can export MATLAB objects to a PDF report directly without the use of 'ps2pdf'?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Jan 2022
The PS2PDF function is an external tool offered through MathWorks File Exchange. Please contact the author to receive support using this tool.
  1. Since a uitable object is used in this example, the widths of the various columns in the table, position of the table and the figure window containing the table can be adjusted for appropriate visualization before exporting the object to a PDF report.
As an alternative to using 'ps2pdf' other functions that export MATLAB objects to PDF directly can be used:
MATLAB Report Generator:
 This contains the ‘mlreportgen.dom’ class that contains methods to append tables directly (without requiring a post scripts) to a PDF report. Therefore, this would replace the ps2pdf workflow. The Getting Started page is linked below.
 
Listed below are links to some relevant methods:
  1. Creating a formal table using "mlreportgen.dom.FormalTable" class: https://www.mathworks.com/help/rptgen/ug/mlreportgen.dom.formaltable-class.html
  2. Creating a figure using "mlreportgen.report.Figure" class: https://www.mathworks.com/help/rptgen/ug/mlreportgen.report.figure-class.html
  3. Add Content to a Report: https://www.mathworks.com/help/rptgen/ug/add-content-to-a-report.html
  4. There are plenty of methods that support table and report formatting. To get a complete list of the methods please type “help mlreportgen.report.report” and “help mlreportgen.dom” in the command window to take a look at some of the methods.
  5. Once a report is created, all figures, tables need to be added to the report before closing the report. Once the report is closed the document cannot be called back to append objects and make any edits.
  6. A demo script that exports a MATLAB plot and table to a PDF report using MATLAN report generator is attached.
exportgraphics:
 This is a single function that can be used to export plots and graphics to PDF directly, starting MATLAB R2020a. The reference page is linked below:
  1. The 'append' functionality for this function was introduced in a later release verified in R2021b and later versions.
  2. Using ‘exportgraphics’ you can append multiple figures to a PDF report.
  3. With ‘exportapp’, uitables can be exported to PDF documents. However, this function does not support appending/attaching multiple figures to a PDF documents. Therefore, two workarounds are suggested:
    1. Use an external tool for appending multiple tables.
    2. If size permits, include all uitables to a single figure object before exporting.
To create a PDF report with a combination of plots and tables, the reports containing plots and tables would have to be combined using an external tool. This would result in figures and tables to be reported in different pages.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!