How can I print images to pdf with page size larger than screen size (r2016b, r2017a)? (Warning: An error occurred while drawing the scene)

10 Ansichten (letzte 30 Tage)
I am having trouble printing figures filled with images to pdf when the paper size is >= screen size. The pdf gets generated but the figure size, placement and content are incorrect. During the print, I get this warning:
Warning: An error occurred while drawing the scene
> In defaulterrorcallback (line 12)
In alternatePrintPath>LocalSetPaintDisabled
In alternatePrintPath>printCleanup
In alternatePrintPath>@()printCleanup(pj,pt)
In onCleanup/delete (line 60)
In alternatePrintPath
In print (line 82)
I am seeing this issue with r2016b and r2017a. I was previously using r2015b and never had this problem. Below is a script that I have used to regenerate the issue:(Note that the goal is to have the image fill the pdf page hence the need for explicitly setting the 'paperposition' property)
% Store original units
originalUnits = get(0,'units');
% Set units to inches
set(0,'units','inches');
% Obtain screen size information
screenSizeInches = get(0,'screensize');
% Scale to desired paper size
largePaperSize = screenSizeInches*1.2;
smallPaperSize = screenSizeInches*0.8;
% Get data
data = rand(9);
% Figure with image only
imageHandle = figure;
imagesc(data);
% Figure with lines only
plotHandle = figure;
plot(data);
% Figure with both image and lines
combinedHandle = figure;
subplot(2,1,1)
imagesc(data);
subplot(2,1,2)
plot(data);
% Print to paper larger than screen
% Print image - *Issue here*
set(imageHandle,'paperunits','inches')
set(imageHandle,'papersize',largePaperSize (3:4))
set(imageHandle,'paperposition',largePaperSize );
print(imageHandle, 'testImagePrintLarge.pdf', '-dpdf', '-r0');
% Print lines - No issue
set(plotHandle,'paperunits','inches')
set(plotHandle,'papersize',largePaperSize (3:4))
set(plotHandle,'paperposition',largePaperSize);
print(plotHandle, 'testLinePrintLarge.pdf', '-dpdf', '-r0');
% Print both - No issue
set(combinedHandle,'paperunits','inches')
set(combinedHandle,'papersize',largePaperSize (3:4))
set(combinedHandle,'paperposition',largePaperSize);
print(combinedHandle, 'testCombinedPrintLarge.pdf', '-dpdf', '-r0');
% Print to paper smaller than screen
% Print image - No issue
set(imageHandle,'paperunits','inches')
set(imageHandle,'papersize',smallPaperSize(3:4))
set(imageHandle,'paperposition',smallPaperSize);
print(imageHandle, 'testImagePrintSmall.pdf', '-dpdf', '-r0');
% Restore original units property
set(0, 'units', originalUnits);

Akzeptierte Antwort

Anand Patel
Anand Patel am 24 Apr. 2017
You can use 'opengl' renderer option to generate output. For example,
print(imageHandle, 'testImagePrintLarge.pdf', '-dpdf', '-opengl', '-r0');
To get higher resolution output, use '-r150', '-r300' or larger number.

Weitere Antworten (1)

Ankitha Kollegal Arjun
Ankitha Kollegal Arjun am 17 Apr. 2017
The issue is likely caused by the 'paperposition' property. Try removing this option.
Replace this:
set(imageHandle,'paperposition',largePaperSize );
By this:
set(imageHandle);
  1 Kommentar
Sirmwami
Sirmwami am 17 Apr. 2017
I should have mentioned that the intention is to have the image fill the pdf page hence the need to specify the 'paperposition' property. Thanks for the input but unfortunately, it does not meet my needs.
My apologies for the lack of clarity, I'll edit the question to be more specific.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by