Error while trying to convert a TIF file to a PDF file
6 ビュー (過去 30 日間)
古いコメントを表示
Everytime I try to run 1 of the following options:
imageObject = PDImageXObject.createFromByteArray(document, image, 'TIF');
or
imageObject = LosslessFactory(document, image);
it gives me the error: No method 'org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.createFromByteArray'
with matching signature found.
And if I try
PDImageXObject.createFromFile(inputImage,document);
it gives me the error: java.io.IOException: First image in tiff is not CCITT T4 or T6.
The problem with this alternative is that I want the pdf colored, so inputImage has to be colored.
function ConvertToPDF(inputImage)%Image '.tif' or '.tiff'
import org.apache.pdfbox.pdmodel.*;
import org.apache.pdfbox.pdmodel.graphics.image.*;
import java.io.*
import javax.imageio.ImageIO.*
image = imread(inputImage);
numPages=length(imfinfo(inputImage));
document = PDDocument();
for page = 1:numPages
image = image(:, :, :, page);
imageObject = PDImageXObject.createFromByteArray(document, image, 'TIF');%Error here
pdfPage = PDPage();
imageSize = size(image);
pdfPage.setMediaBox(PDRectangle(imageSize(2), imageSize(1)));
contentStream = PDPageContentStream(document, pdfPage);
contentStream.drawImage(imageObject, 0, 0, imageSize(2), imageSize(1));
contentStream.close();
document.addPage(pdfPage);
end
%Save
outputFile = 'output.pdf';
document.save(outputFile);
document.close();
end
0 件のコメント
回答 (1 件)
Mann Baidi
2023 年 8 月 21 日
編集済み: Mann Baidi
2023 年 11 月 3 日
Hi Pablo,
I understand that you are facing issue in converting the TIF files into PDF files.
You can consider using the "print" function. For reference, please follow the sample code attached below:
ConvertToPDF('myfile.tif')
function ConvertToPDF(inputImage)%Image '.tif' or '.tiff'
image = imread(inputImage);
fig = figure;
imshow(image)
print(fig,'MySavedPlot','-dpdf');
%Save
end
Using the above attached sample code, you should be able to convert the TIF file into PDF.
For more details, you can refer to the "print" documentation using the following link.
I hope this helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Convert Image Type についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!