Empty pdf if table is saved as pdf

5 views (last 30 days)
Chris Pruefert
Chris Pruefert on 7 Jun 2024
Answered: Milan Bansal on 7 Jun 2024
I am trying save the table t1 by uisng the suggested table-to-figure mathod. However, the saved pdf remains empty.
t1=table(ones(5));
fig = uifigure('Name','Numbers');
t = uitable(fig,'Data',t1);
exportapp(fig,'Peak_assigments.pdf')

Answers (2)

Ganapathi Subramanian R
Ganapathi Subramanian R on 7 Jun 2024
Hi Chris,
The following code worked for me in saving the uitable along with its contents as a pdf file.
t1=ones(5);
fig = figure('Name','Numbers');
t = uitable(fig,'Data',t1);
saveas(gcf,'Peak_assignments','pdf')
I hope this helps.
Thanks

Milan Bansal
Milan Bansal on 7 Jun 2024
Hi Chris Pruefert,
I understand that you want to export a table create in MATLAB as a pdf but are facing issues with it.
Instead of using exportapp, you can use the print function and set the format type as "-dpdf". Please refer to the following code snippet for the implementation.
% Sample data for the table
data = {'Apple', 52; 'Banana', 89; 'Cherry', 50};
columnNames = {'Fruthe it', 'Calories'};
% Create the figure
f = figure('Position', [100, 100, 400, 200]);
% Create the table
t = uitable('Parent', f, 'Data', data, 'ColumnName', columnNames, 'Position', [20, 20, 360, 160]);
% Set the figure properties for better output
set(f, 'PaperPositionMode', 'auto');
set(f, 'InvertHardcopy', 'off');
set(f, 'Color', 'w');
% Save the figure as a PDF
print(f, 'table_output', '-dpdf');
Please refer to the following documentation link to learn more about print function.
Hope this helps!

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!