how to export images to pdf

조회 수: 10 (최근 30일)
Lukas
Lukas 2014년 4월 19일
답변: Yash 2024년 8월 26일
heloo
i need to export a lot of images to pdf file. i tried this solutions but it is bad.
for a=1:2
h=subplot(2,1,a), imshow(absKoniec{a})
%in absKoniec are more then 2 images(pages of book), this is only example
kurnik = figure(1)
end
saveas(h,'hokus.pdf')
hgexport(kurnik, 'figure1.pdf', hgexport('factorystyle'), 'Format', 'pdf')
output is here:
images in pdf and in figure are too small(background is too big).so it is necessary to zoom in pdf. And how to do it, if i want to have one image on every single page of pdf (it is possible)? help me pls...
  댓글 수: 2
Walter Roberson
Walter Roberson 2014년 4월 20일
What did you set() the figure PageSize to be?
Lukas
Lukas 2014년 4월 20일
do you thing this:
for a=1:30
h=subplot(30,1,a), imshow(absKoniec{a})
kurnik = figure(1)
end
%saveas(h,'hokus.pdf')
%hgexport(kurnik, 'figure1.pdf', hgexport('factorystyle'), 'Format', 'pdf')
%A = hgload('myFigure.fig');
% set desired output size
set(kurnik, 'Units','centimeters')
height = 15;
width = 4;
% the last two parameters of 'Position' define the figure size
set(kurnik, 'Position',[0 0 width height],...
'PaperSize',[width height],...
'PaperPositionMode','auto',...
'InvertHardcopy', 'off',...
'Renderer','painters'... %recommended if there are no alphamaps
);
%saveas(kurnik,'printout','pdf')
hgexport(kurnik, 'figure1.pdf', hgexport('factorystyle'), 'Format', 'pdf')
but if there(in figure) are many images, i need strong zoom to see images...

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

답변 (1개)

Yash
Yash 2024년 8월 26일
Hi Lukas,
As I can understand, you want a pdf with each page as a given image in the folder. Instead of using the "hgexport" function, you can use the "exportgraphics" function to get the pdf. Given below is an example for the same:
% Specify the number of images
numImages = 10;
% Initialize a cell array to store the image file names
imageFiles = cell(numImages, 1);
for i = 1:numImages
imageFiles{i} = sprintf('image_%d.jpg', i); % Adjust the file extension if needed
end
% Create a new PDF
outputPDF = 'output.pdf';
% Create a figure for displaying images
hFig = figure('Visible', 'off');
% Loop over each image and add it to the PDF
for i = 1:numImages
% Read the image
img = imread(imageFiles{i});
% Display the image
imshow(img, 'Border', 'tight');
% Adjust the figure size to fit the image
truesize(hFig);
% Save the current figure as a PDF page
if i == 1
% Use 'append' option to create a new PDF
exportgraphics(hFig, outputPDF, 'Append', false, 'ContentType', 'vector');
else
% Append to the existing PDF
exportgraphics(hFig, outputPDF, 'Append', true, 'ContentType', 'vector');
end
end
% Close the figure
close(hFig);
Kindly refer to the following documentation for the "exportgraphics" function: https://www.mathworks.com/help/matlab/ref/exportgraphics.html
I hope this helps!

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by