How do I export my app to a pdf without clipping?

50 次查看(过去 30 天)
I want to export my app to a pdf report. I am using the code below (straight from the example for "exportapp":
% Button pushed function: ExportDataButton
function ExportDataButtonPushed(app, event)
filter = {'*.jpg';'*.png';'*.tif';'*.pdf'};
[filename,filepath] = uiputfile(filter);
if ischar(filename)
exportapp(app.VisionMetricsUIFigure,[filepath filename]);
end
end
When I choose a file name as an image, everything displays as expected. When I create a pdf, it clips off the right/bottom of the app.
I initially thought it might be related to the app size, so I tried to shrink it to the area that was displayed, but it still clipped in the same area.
Original Size: 952x761
New Size: 876x638
How can I get everything to display when saved as a pdf?

采纳的回答

T.Nikhil kumar
T.Nikhil kumar 2024-5-15
编辑:T.Nikhil kumar 2024-5-15
Hello David,
As per your question, I get that you’re trying to export your app to a pdf file using the ‘exportApp’ function, but some part of the app is clipped off in the generated PDF file.
I too am facing the same issue of clipping while exporting to PDF format with MATLAB R2024a. Though this doesn’t seem to be the case with previous releases of MATLAB since the generated PDF looks fine in MATLAB R2023b.
I would suggest you to try using MATLAB R2023b for this purpose. If not, you can also try the below method as a workaround where you can export the app to an image and convert it to a PDF using MATLAB:
1. Export app to an image format (say PNG)
exportapp(f, 'test.png');
2. Read the image and display it in a figure:
% Create a figure
fig = figure;
% Use imshow to display the image
imshow(imread('test.png'));
% Turn off the axis
axis off;
3. Adjust properties for PDF and specify output path
% Adjust figure properties for PDF output
set(fig, 'Units', 'Inches', 'Position', [0, 0, 8.5, 11], 'PaperPositionMode', 'auto');
% Specify the output PDF file path
outputPDFPath = 'output_path_and_filename.pdf'; % Update this path
4. Use the ‘print’ function to print the figure
% Print the figure to a PDF
print(fig, '-dpdf', outputPDFPath);
% Close the figure
close(fig);
Hope this helps you proceed with your work!
  2 个评论
David Holmburg
David Holmburg 2024-5-15
I guess this is a known bug for 2024a. Thanks for your help on the workaround!
mala
mala 2024-7-4,12:08
编辑:mala 2024-7-4,12:09
but its not working for me can you give a whole code ?

请先登录,再进行评论。

更多回答(1 个)

Masood Salik
Masood Salik 2024-6-27,19:45
Use this command
print(gcf, '-dpdf', outputPDFPath,'-bestfit');

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by