Azzera filtri
Azzera filtri

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

50 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

T.Nikhil kumar
T.Nikhil kumar il 15 Mag 2024
Modificato: T.Nikhil kumar il 15 Mag 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 Commenti
David Holmburg
David Holmburg il 15 Mag 2024
I guess this is a known bug for 2024a. Thanks for your help on the workaround!
mala
mala il 4 Lug 2024 alle 12:08
Modificato: mala il 4 Lug 2024 alle 12:09
but its not working for me can you give a whole code ?

Accedi per commentare.

Più risposte (1)

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

Categorie

Scopri di più su Printing and Saving in Help Center e File Exchange

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by