When using exportapp on a uifigure who contains uilabels with Tex interpreter, the pdf file contains white pages at the end and I want to delete them.
Here an example code:
File='example.pdf';
Path='D:\Downloads\';
f = uifigure;
lb=uilabel(f,"Text",'x^{2}','Interpreter','tex','Position',[50 50 100 100]);
pause(2)
exportapp(f,fullfile(Path,File))
delete(f)

 Respuesta aceptada

Isaac Marín
Isaac Marín el 12 de Sept. de 2024
Editada: Isaac Marín el 12 de Sept. de 2024
We can remove pages from a pdf using pdfbox
To delete all pages but the first one, example:
Pd=org.apache.pdfbox.pdmodel.PDDocument;
PDFile=java.io.File(fullfile(Path,File));
document=Pd.load(PDFile);
npages=document.getNumberOfPages
if npages>1
for i=npages:-1:2
document.removePage(i-1);
end
document.save(fullfile(Path,File));
end
document.close;

Más respuestas (1)

Edward
Edward el 1 de Oct. de 2026 a las 10:13

0 votos

In this kind of solution, I use PDFChamp Remove PDF Pages to select the unwanted pages and create a new PDF without them. This is handy when you have a long document and only need to keep certain pages.
You can first open the PDF, identify the pages you don't need, select them, and remove them before saving the updated file. It can be useful for removing blank pages, duplicate pages, or unnecessary sections without recreating the entire document.
For important documents, I’d recommend keeping the original PDF unchanged and saving the edited version as a separate file.

Categorías

Más información sobre Printing and Saving en Centro de ayuda y File Exchange.

Productos

Versión

R2024b

Etiquetas

Preguntada:

el 12 de Sept. de 2024

Respondida:

el 1 de Oct. de 2026 a las 10:13

Community Treasure Hunt

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

Start Hunting!

Translated by