How to "print" on the command line or from a gui like is done from the figure "file" menu option

Hello,
To simplify life, I would like to have a button in my gui call up the same MATLAB gui window to choose the printer that is done when you choose "File Print" in Windows. I don't want a new figure window (if possible) to pop up, but just to print the chosen axes (chosen through copyobj()).
The print procedure is NOT very intuitive.
Thanks.
Doug

댓글 수: 12

I do not understand the question. While the print command is powerful and does exactly what is useful for printing, I do not understand, how copyobj "chooses" an axes or where you choose "File Print".
What do you want to print and which problem occurs?
To ad to Jan Simon's point are you looking how to get a file drop down menu which has print as an option?
Jan:
I wanted to only print one of the axes in a gui. I found an "Answer" -->
but it didn't give me the way to easily do the printing. Joseph's answer (which I guess was obvious from the end of the "print help") should be my solution.
However! I get the appropriate figure popping up (Figure 1), and when I print (using printdlg()), only a blank sheet of paper comes out of the printer.
Any thoughts? Thanks for the help.
So using printpreview() you can see the figure? I haven't tried to actually print beyond seeing it in the printpreview screen.
Actually, no! The figure comes up, there's a brief "flash", and the figure then disappears.
Here is the code:
% --- Executes on button press in print_button.
function print_button_Callback(hObject, eventdata, handles)
% hObject handle to print_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axis_handle = handles.printer_compo;
new_fig = figure; %('Visible','off');
%copyobj(handles.tran_wt_axis,new_fig);
new_axes = copyobj(axis_handle,new_fig);
set(new_axes, 'units', 'normalized', 'position', [0.13 0.11 0.775 0.815]);
printpreview(new_fig);
close(new_fig);
I tried it first with 'Visible','off' for the figure, thinking it would go straight to the printer. The figure is just right, but somehow is lost to the print.
Figured it out!
n = printpreview(TESTS);
uiwait(n)
close(TESTS)
which will wait for the printpreview to close before closing the fig.
Well, yes you did -- The print preview dialog came up and waited for me to do the print. But, again, only a blank sheet of paper was spit out.
I did get a "Warning", as follows:
Warning: Failed in memory BitBlt (gle00000008)
> In C:\Program Files (x86)\MATLAB\R2012b\toolbox\matlab\graphics\hardcopy.p>hardcopy at 28
In graphics\private\render at 142
In print>LocalPrint at 280
In print at 237
In graphics\private\printdlg_deprecated at 66
In printdlg at 62
In printpreview>onPrint at 1000
In uiwait at 82
In sc_gui2>print_button_Callback at 433
In gui_mainfcn at 96
In sc_gui2 at 42
In @(hObject,eventdata)sc_gui2('print_button_Callback',hObject,eventdata,guidata(hObject))
In uiwait at 82
In sc_gui2>sc_gui2_OpeningFcn at 129
In gui_mainfcn at 221
In sc_gui2 at 42
Do you know what this is about? Thanks again!
Doug
By the way, I am able to print a figure created from the command line(just a dummy with a simple plot) using either the "File->Print" on the figure, or using printpreview().
Joseph,
Thank you for your assistance on "Part I" of this problem. Your solution worked well (the "uiwait" was critical!). However, this BitBlt problem won't get any attention on a Question that already has an accepted answer (yours). I will reopen in a new question.
Thank you!
oh was there a part II? Oh did not see it as I don't get emails about updates to questions. I'll think about it and will answer it in your new Part II question
Quick search of the Matlab Answers for that gave a possible solution.
set(gcf,'Renderer','OpenGL')
Amazing! Yes, setting, the new figure to the 'Renderer','OpenGL' worked.
Thank you!
Doug
For reference, the code that WORKS is:
% --- Executes on button press in print_button.
function print_button_Callback(hObject, eventdata, handles)
% hObject handle to print_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axis_handle = handles.printer_compo;
new_fig = figure('Visible','off');
new_axes = copyobj(axis_handle,new_fig);
set(new_axes, 'units', 'normalized', 'position', [0.13 0.11 0.775 0.815]);
set(new_fig,'Renderer','OpenGL');
pp_handle = printpreview(new_fig);
uiwait(pp_handle);
close(new_fig);

댓글을 달려면 로그인하십시오.

 채택된 답변

Thinking about it more... here is what i came up with.
in GUIDE use the menu editor add in file and print as a new menu and menu item.
after that in the call back for print
TESTS=figure;
copyobj(handles.axes2,TESTS);
printpreview(TESTS);
close(TESTS);
printpreview() may not be what you are looking for but as a temporary thing to see if you are actually getting the axes you are looking for. after you know this is what you're looking for then you can swap out printpreview() with printdlg().

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

태그

Community Treasure Hunt

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

Start Hunting!

Translated by