how to save an image in pdf format without blank space. i,e; size of pdf should be same as the size of the image

조회 수: 47 (최근 30일)
  댓글 수: 2
Parveiz Lone
Parveiz Lone 2020년 3월 11일
above comment ....saveas(gca, 'file.pdf');
could not help me
a=imread('lena.jpg');
imshow(a),title('lena');
then i need to save image 'a' as pdf, but size of pdf should be same as size of image.

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

채택된 답변

Parveiz Lone
Parveiz Lone 2021년 11월 25일
%% This can work good
h=figure;
subplot(111),imshow(image_name),title('image');
set(h,'papersize',[5.1 3.2]);
print(h,'image_name','-dpdf')

추가 답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 3월 10일
Although Friedrich's answer here: https://www.mathworks.com/matlabcentral/answers/12987-how-to-save-a-matlab-graphic-in-a-right-size-pdf#answer_17755 provides a clean solution, It still leave some extra white spaces.
I personally prefer to print the file to eps format. It leaves absolutely no extra space
print(gcf, 'filename', '-depsc')
And then export the eps file to pdf using epstopdf (command-line tool available with the installation of latex). If you don't have epstopdf installed, you can use this link: https://www.zamzar.com/convert/eps-to-pdf/ to convert the files to pdf.
The following image shows the difference between both methods. First is according to Friedrich's answer, second, when it is created using the above method.

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by