Main Content

exportapp

Capture app as image or PDF

    Description

    example

    exportapp(fig,filename) exports the contents of the figure specified by fig and stores it in the file specified by filename. The figure must be created with either the uifigure function or App Designer. All graphical content is captured, including UI components. The supported file types are JPEG, PNG, TIFF, and PDF.

    Examples

    collapse all

    Create a program file called myapp.m that displays a plot and a button for exporting the user interface as a file. In the callback function for the button, call the uiputfile function to prompt the user for a file name and location. Then call the exportapp function with the full path to the specified file.

    function myapp
    f = uifigure;
    ax = uiaxes(f,'Position',[25 25 400 375]);
    plot(ax,[0 0.3 0.1 0.6 0.4 1])
    uidropdown(f,'Position',[435 250 90 30],'Items',{'Blue Line','Red Line'});
    uicheckbox(f,'Position',[435 290 90 30],'Text','Grid');
    b = uibutton(f,'Position',[435 200 90 30],'Text','Export');
    b.ButtonPushedFcn = @buttoncallback;
    
        function buttoncallback(~,~)
            filter = {'*.jpg';'*.png';'*.tif';'*.pdf'};
            [filename,filepath] = uiputfile(filter);
            if ischar(filename)
                exportapp(f,[filepath filename]);
            end
        end
    end

    Run the app by calling the myapp function. When you click the Export button in the app, a dialog box prompts you for a file name and location. Then, it saves the figure content in the file you specify.

    myapp

    Input Arguments

    collapse all

    Figure object created with the uifigure function, or the figure in an App Designer app.

    If you are developing an App Designer app, the figure is stored in the UIFigure property by default. For example, in an app called myapp, the figure is stored as myapp.UIFigure.

    If you are running an App Designer app that does not have exporting functionality built into it, execute the mlapp file in the command window and specify an output argument. Then, use the output argument to access the figure. For example, this code exports an app called myapp.mlapp as a JPEG file:

    app = myapp;
    exportapp(app.UIFigure,'appcontent.jpg')

    File name, specified as a character vector or a string scalar that includes the file extension. If filename does not include a full path, MATLAB® saves the file in the current folder. You must have permission to write to the file.

    The following table lists the supported file formats and the file extensions (which are not case sensitive).

    File FormatFile Extension

    Joint Photographic Experts Group (JPEG)

    'jpg' or 'jpeg'

    Portable Network Graphics (PNG)

    'png'

    Tagged Image File Format (TIFF)

    'tif' or 'tiff'

    Portable Document Format (PDF)

    The PDF includes embeddable fonts and vector graphics content when possible.

    'pdf'

    Limitations

    • exportapp is not supported in MATLAB Online™ or in Web Apps (MATLAB Compiler).

    • exportapp does not capture UI components created with the uihtml function.

    • Exporting an app as a PDF file is not supported in the Live Editor.

    Introduced in R2020b