Error while trying to convert a TIF file to a PDF file
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Mann Baidi
am 21 Aug. 2023
Bearbeitet: Mann Baidi
am 3 Nov. 2023
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 Kommentare
Siehe auch
Kategorien
Mehr zu Convert Image Type 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!