How do I export my app to a pdf without clipping?
10 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
T.Nikhil kumar
on 15 May 2024
Edited: T.Nikhil kumar
on 15 May 2024
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 Comments
More Answers (1)
Masood Salik
on 27 Jun 2024
Use this command
print(gcf, '-dpdf', outputPDFPath,'-bestfit');
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!